Skip to content
Permalink
Browse files

added get employee

  • Loading branch information
Jeremy Mill
Jeremy Mill committed Dec 10, 2015
1 parent c95eb9d commit adf00cf6dbbe1ebe2a7254b6b564a9da4ebbaaaa
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TeamDBAwesome.Models;
using TeamDBAwesome.SqlService;
using Newtonsoft.Json;

namespace TeamDBAwesome.Controllers
{
public class GetEmployeeController : ApiController
{
public HttpResponseMessage Get(int personId)
{
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK);
MySqlService sql = new MySqlService();
employee emp = sql.GetEmployee(personId);
string json = JsonConvert.SerializeObject(emp);
message.Content = new StringContent(json);
return message;
}
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TeamDBAwesome.Models
{
public class employee
{
public int employeeid { get; set; }
public string title { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public string email { get; set; }
public bool isAdmin { get; set; }
}
}
@@ -1002,6 +1002,42 @@ public int NewCustomPlaylist(CustomPlaylistId playlist)
}
}

public employee GetEmployee(int personId)
{
bool open = this.OpenConnection();
employee Employee = new employee();
if(open == true)
{
string empQuery = "select EmployeeId,Title,LastName,FirstName,Email from employee "
+ "left join person on person.PersonId = employee.PersonId " +
"where person.PersonId = " + personId;
string numResults = "select count(*) from employee left join person on person.PersonId = employee.PersonId where person.PersonId = " + personId;
MySqlCommand cmd = new MySqlCommand(numResults, SqlConn);
int numRes = int.Parse(cmd.ExecuteScalar() + "");
if (numRes > 0)
{
cmd = new MySqlCommand(empQuery, SqlConn);
MySqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
Employee.employeeid = int.Parse(GetDBString("EmployeeId", reader));
Employee.title = GetDBString("Title", reader);
Employee.lastname = GetDBString("LastName", reader);
Employee.firstname = GetDBString("FirstName", reader);
Employee.email = GetDBString("Email", reader);
if(Employee.title == "General Manager")
{
Employee.isAdmin = true;
}
else { Employee.isAdmin = false; }
}
return Employee;
}
else { return Employee; }
}
return Employee;
}

public int NewPlaylist(string playlistname)
{
bool open = this.OpenConnection();
@@ -183,6 +183,7 @@
<Compile Include="Controllers\GetCustomerOrdersController.cs" />
<Compile Include="Controllers\GetCustomPlaylistController.cs" />
<Compile Include="Controllers\GetCustomPlaylistsController.cs" />
<Compile Include="Controllers\GetEmployeeController.cs" />
<Compile Include="Controllers\GetOrderTracksController.cs" />
<Compile Include="Controllers\GetPaymentController.cs" />
<Compile Include="Controllers\GetPlaylistController.cs" />
@@ -202,6 +203,7 @@
<Compile Include="Models\Artist.cs" />
<Compile Include="Models\Customer.cs" />
<Compile Include="Models\CustomPlaylistId.cs" />
<Compile Include="Models\employee.cs" />
<Compile Include="Models\Genre.cs" />
<Compile Include="Models\Invoice.cs" />
<Compile Include="Models\Media.cs" />

0 comments on commit adf00cf

Please sign in to comment.
You can’t perform that action at this time.