public ManageResourcesResponse Allocate(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); using (var context = new Company_dbEntities()) { var alloc = (from a in context.Resources_table where a.Serial == request.Serial select a).FirstOrDefault(); if (alloc != null) { if(request.Allocate == true) { alloc.EmployeeID = request.UserName; alloc.IssuedTo = DateTime.Now.ToString(); context.SaveChanges(); response.allocated = true; } else { alloc.EmployeeID = null; alloc.IssuedTo = DateTime.Now.ToString(); context.SaveChanges(); response.allocated = false; } } } return response; }
public static int? GetEmployeeId(string employeeName, string email) { int? empId = null; using (var context = new Company_dbEntities()) { var employee = (from a in context.Employee_table where a.EmployeeName.ToLower() == employeeName.ToLower() && a.Email.ToLower() == email.ToLower() select a).FirstOrDefault(); if (employee != null) empId = employee.EmployeeID; } return empId; }
public static int? GetCompanyId(string companyName) { int? compId = null; using (var context = new Company_dbEntities()) { var company = (from a in context.Company_table where a.CompanyName.ToLower() == companyName.ToLower() select a).FirstOrDefault(); if (company != null) compId = company.CompanyID; } return compId; }
public ManageCompanyResponse allCompany() { ManageCompanyResponse response = new ManageCompanyResponse(); List<Company_table> company = new List<Company_table>(); using (var context = new Company_dbEntities()) { company = (from a in context.Company_table select a).ToList<Company_table>(); if (company.Count() > 0) response.CompanyList = JsonConvert.SerializeObject(company); else response.CompanyList = null; } return response; }
public ManageResourcesResponse AddResources(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } using (var context = new Company_dbEntities()) { var resp = (from a in context.Resources_table where a.CompanyID == compId.Value && request.Serial == a.Serial select a).FirstOrDefault<Resources_table>(); if (resp == null) { resp = new Resources_table(); resp.NameOfDevice = request.NameOfDevice; resp.Type = request.Type; resp.IssuedFrom = request.IssuedFrom.ToShortDateString(); resp.Serial = request.Serial; resp.CompanyID = compId.Value; resp.EmployeeID = null; resp.Deleted = false; context.Resources_table.Add(resp); var comp = (from a in context.Company_table where a.CompanyID == compId.Value select a).FirstOrDefault<Company_table>(); if (comp != null) comp.ResourceCount++; context.SaveChanges(); response.IsResourcesCreated = true; } else { response.IsResourcesCreated = false; } } return response; }
public ManageTaskResponse Approval(ManageTaskRequest request) { ManageTaskResponse response = new ManageTaskResponse(); using (var context = new Company_dbEntities()) { var approve = (from a in context.Task_table where a.EmployeeID == request.UserName && a.Description == request.Description && a.EmployeeConfirm == "Completed" select a).FirstOrDefault<Task_table>(); if (request.Accept == true) { if (approve != null) { approve.ManagerConfirm = request.ManagerConfirm; context.SaveChanges(); response.ConfirmManager = true; } else { response.ConfirmManager = false; } } else { if (approve != null) { approve.ManagerConfirm = request.ManagerConfirm; approve.EmployeeConfirm = "Pending"; context.SaveChanges(); response.ConfirmManager = true; } else { response.ConfirmManager = false; } } } return response; }
public ManageCompanyResponse AddCompany(ManageCompanyRequest request) { ManageCompanyResponse response = new ManageCompanyResponse(); using (var context = new Company_dbEntities()) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId != null) { throw new Exception("Company Name already Exists. Try another name."); } var comp = (from a in context.Company_table where a.Prefix == request.Prefix select a).FirstOrDefault(); if(comp == null) { comp = new Company_table(); comp.CompanyName = request.CompanyName; comp.OwnerName = request.OwnerName; comp.Address = request.Address; comp.Contact = request.Contact; comp.EmployeeCount = 0; comp.ResourceCount = 0; comp.Email = request.Email; comp.Prefix = request.Prefix; comp.ModifiedOn = DateTime.Now; comp.IsActive = true; context.Company_table.Add(comp); context.SaveChanges(); response.IsCompanyCreated = true; response.CompanyId = comp.CompanyID; } else { response.IsCompanyCreated = false; } } return response; }
public ManageTaskResponse AddTask(ManageTaskRequest request) { ManageTaskResponse response = new ManageTaskResponse(); //int? empId = AdapterHelper.GetEmployeeId(request.AssignedBy, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); using (var context = new Company_dbEntities()) { Task_table task = new Task_table(); task.EmployeeID = request.UserName; task.EmployeeName = request.EmployeeName; task.Description = request.Description; task.AssignedBy = request.AssignedBy; task.EmployeeConfirm = request.EmployeeConfirm; context.Task_table.Add(task); context.SaveChanges(); response.TaskAdded = true; } return response; }
public ManageCompanyResponse SearchCompany(ManageCompanyRequest request) { ManageCompanyResponse response = new ManageCompanyResponse(); using (var context = new Company_dbEntities()) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } var company = (from a in context.Company_table where a.CompanyID == compId select a).FirstOrDefault(); //Whenever selecting the first or default, always check for null if (company != null) { response.IsCompanyExist = true; dynamic comp = new ExpandoObject(); comp.CompanyName = company.CompanyName; comp.CompanyId = company.CompanyID; comp.Address = company.Address; comp.Contact = company.Contact; comp.Email = company.Email; comp.EmployeeCount = company.EmployeeCount; comp.ResourceCount = company.ResourceCount; comp.OwnerName = company.OwnerName; comp.Prefix = company.Prefix; response.CompanyInfo = JsonConvert.SerializeObject(comp); } } return response; }
public ManageCompanyResponse deleteCompany(ManageCompanyRequest request) { ManageCompanyResponse response = new ManageCompanyResponse(); //creating a new instance is not required //Company_table company = new Company_table(); //calling the constructor would suffice Company_table company = default(Company_table); using (var context = new Company_dbEntities()) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } company = (from a in context.Company_table where a.CompanyID == compId select a).FirstOrDefault(); if (company != null) { context.Company_table.Remove(company); response.IsCompanyUpdated = true; } context.SaveChanges(); } return response; }
public ManageCompanyResponse allManagers(ManageCompanyRequest request) { ManageCompanyResponse response = new ManageCompanyResponse(); using (var context = new Company_dbEntities()) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) throw new Exception("No company found. Try again!"); // List<Employee_table> managers = new List<Employee_table>(); //Add FK bw employee and comapny table using company Id, redo LINQ for this- DONE! var managers = (from a in context.Employee_table where a.CompanyID == compId && a.Designation == "Manager" select new { EmployeeName = a.EmployeeName, EmployeeID = a.UserName, CompanyID = a.CompanyID, ManagerID = a.ManagerID, Designation = a.Designation, //Department = a.Department, //DOB = a.DOB, //Address = a.Address, // Contact = a.Contact, Email = a.Email }).ToList(); //dynamic manList = new ExpandoObject(); //manList.Managers = managers; response.ManagerList = JsonConvert.SerializeObject(managers); } return response; }
//All employeees under the requested EmployeeId public ManageEmployeeResponse ManagerEmployees(ManageEmployeeRequest request) { ManageEmployeeResponse response = new ManageEmployeeResponse(); List<Employee_table> employee = new List<Employee_table>(); //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); List<dto> dto = new List<dto>(); using (var context = new Company_dbEntities()) { employee = (from a in context.Employee_table where a.ManagerID == request.UserName select a).ToList(); if (employee.Count() > 0) { foreach (var entry in employee) { dto d = new dto(); d.EmployeeID = entry.UserName; d.EmployeeName = entry.EmployeeName; dto.Add(d); } response.ManagerEmployees = JsonConvert.SerializeObject(dto); } else response.ManagerEmployees = null; } return response; }
//public ManageEmployeeResponse checkEmployee(ManageEmployeeRequest request) //{ // ManageEmployeeResponse response = new ManageEmployeeResponse(); // using (var context = new Company_dbEntities()) // { // int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); // if (!empId.HasValue) // throw new Exception("Employee does not exist!"); // var employee = (from a in context.Employee_table // where a.EmployeeID == empId.Value // select a).FirstOrDefault(); // if (employee != null) // { // response.IsEmployeeExist = true; // response.EmployeeDetail = // } // var employee = (from a in context.Employee_table where a.EmployeeName == request.EmployeeName select a).FirstOrDefault<Employee_table>(); // if (employee != null) // { // response.IsEmployeeExist = true; // } // else // { // response.IsEmployeeExist = false; // } // } // return response; //} //public ManageEmployeeResponse countEmployee(ManageEmployeeRequest request) //{ // ManageEmployeeResponse response = new ManageEmployeeResponse(); // using (var context = new Company_dbEntities()) // { // int? compId = AdapterHelper.GetCompanyId(request.CompanyName); // if (!compId.HasValue) // throw new Exception("No company found. Try again!"); // var employeeCount = (from a in context.Employee_table where a.CompanyID == compId.Value select a).Count(); // var company = (from a in context.Company_table where request.CompanyName == a.CompanyName select a).FirstOrDefault<Company_table>(); // company.EmployeeCount = employee; // context.SaveChanges(); // response.EmployeeCount = employee; // } // return response; //} public ManageEmployeeResponse ReplaceEmployee(ManageEmployeeRequest request) { ManageEmployeeResponse response = new ManageEmployeeResponse(); int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } using (var context = new Company_dbEntities()) { var emp = (from a in context.Employee_table where a.UserName == request.UserName && a.Email == request.Email select a).FirstOrDefault(); emp.UserName = request.UserName; emp.Email = request.Email; emp.EmployeeName = request.EmployeeName; emp.Designation = request.Designation; emp.ManagerID = request.ManagerID; //var comp = (from a in context.Company_table // where a.CompanyName == request.CompanyName // select a).FirstOrDefault(); //if (comp != null) // comp.EmployeeCount++; emp.CompanyID = compId.Value; context.SaveChanges(); response.IsEmployeeReplaced = true; } return response; }
public ManageEmployeeResponse UpdateEmployee(ManageEmployeeRequest request) { ManageEmployeeResponse response = new ManageEmployeeResponse(); using (var context = new Company_dbEntities()) { //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); var employee = (from a in context.Employee_table where a.UserName == request.UserName select a).FirstOrDefault(); if (employee != null) { //employee.Designation = request.Designation; //employee.ManagerID = request.ManagerID; //employee.Department = request.Department; //employee.DOB = request.DOB; //employee.Address = request.Address; // employee.Contact = request.Contact; employee.EmployeeInfo = request.EmployeeInfo; employee.Email = request.Email; employee.ModifiedOn = DateTime.Now; employee.IsActive = true; } context.SaveChanges(); response.IsEmployeeUpdated = true; } return response; }
public ManageEmployeeResponse AddEmployee(ManageEmployeeRequest request) { ManageEmployeeResponse response = new ManageEmployeeResponse(); using (var context = new Company_dbEntities()) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (!compId.HasValue) throw new Exception("No company found. Try again!"); //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (empId.HasValue) // throw new Exception("Employee already exists."); var employee = (from a in context.Employee_table where a.Email == request.Email select a).FirstOrDefault(); if (employee == null) { employee = new Employee_table(); employee.EmployeeName = request.EmployeeName.ToLower(); employee.CompanyID = compId.Value; employee.Email = request.Email.ToLower(); employee.Designation = request.Designation; employee.ManagerID = request.ManagerID; //employee.Contact = request.Contact; employee.ModifiedOn = DateTime.Now; employee.IsActive = true; employee.EmployeeInfo = request.EmployeeInfo; //employeeInfo info = new employeeInfo(); //info.Address = request.Address; //info.Contact = request.Contact; //info.Department = request.Department; //info.DOB = request.DOB; //employee.EmployeeInfo = JsonConvert.SerializeObject(info); context.Employee_table.Add(employee); //Updating the count of employees on successfulkl addition of employee. var comp = (from a in context.Company_table where a.CompanyID == compId.Value select a).FirstOrDefault(); if (comp != null) comp.EmployeeCount++; context.SaveChanges(); //var prefix = "BL_"; var emp = (from a in context.Employee_table where a.EmployeeName == request.EmployeeName.ToLower() && a.Email == request.Email select a).FirstOrDefault(); var ID = comp.Prefix + emp.EmployeeID; emp.UserName = ID; context.SaveChanges(); //SendSms sms = new SendSms(); //string body = "Your Employee ID is" + ID; //string status = sms.send("9899699418", "3561", "Your Employee ID is" + ID, request.Contact); //if (status == "1") //{ // response.EmployeeID = "Message Send"; //} //else if (status == "2") //{ // response.EmployeeID = "No Internet Connection"; // // MessageBox.Show("No Internet Connection"); //} //else //{ // response.EmployeeID = "Invalid Login Or No Internet Connection"; // //MessageBox.Show("Invalid Login Or No Internet Connection"); //} response.EmployeeID = emp.UserName; } else { response.EmployeeID = null; } } return response; }
public ManageCompanyResponse UpdateCompany(ManageCompanyRequest request) { ManageCompanyResponse response = new ManageCompanyResponse(); using (var context = new Company_dbEntities()) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } var comp = (from a in context.Company_table where a.CompanyID == compId select a).FirstOrDefault(); if (comp != null) { //comp = new Company_table(); // comp.ResourceCount = request.Resources.ToString(); comp.Address = request.Address; comp.Contact = request.Contact; comp.Email = request.Email; //comp.EmployeeCount = 0; //comp.ResourceCount = 0; } // this method does not update any information about the employee or the resources of the company! context.SaveChanges(); response.IsCompanyUpdated = true; } return response; }
public ManageResourcesResponse ResourceAllocated(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); List<resourceDTO> res = new List<resourceDTO>(); List<Resources_table> resource = new List<Resources_table>(); using (var context = new Company_dbEntities()) { resource = (from a in context.Resources_table where a.EmployeeID == request.UserName && a.Deleted == false select a).ToList(); if (resource != null) { foreach (var entry in resource) { resourceDTO r = new resourceDTO(); r.NameOfDevice = entry.NameOfDevice; r.Type = entry.Type; r.IssuedTo = entry.IssuedTo; // r.IssuedFrom = entry.IssuedFrom.ToString(); res.Add(r); } } response.ResourcesAllocated = JsonConvert.SerializeObject(res); } return response; }
//public ManageResourcesResponse ResourceCount(ManageResourcesRequest request) //{ // ManageResourcesResponse response = new ManageResourcesResponse(); // using (var context = new Company_dbEntities()) // { // var resource = (from a in context.Resources_table select a).Count(); // var company = (from a in context.Company_table where request.CompanyName == a.CompanyName select a).FirstOrDefault<Company_table>(); // company.ResourceCount = resource; // context.SaveChanges(); // response.Resourcecount = resource; // } // return response; //} public ManageResourcesResponse ReplaceResource(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } using (var context = new Company_dbEntities()) { var res = (from a in context.Resources_table where a.Serial == request.Serial select a).FirstOrDefault(); res.Serial = request.Serial; res.NameOfDevice = request.NameOfDevice; res.Type = request.Type; res.EmployeeID = request.UserName; res.CompanyID = compId.Value; res.IssuedFrom = request.IssuedFrom.ToString(); res.Deleted = false; res.ModifiedOn = DateTime.Now; //var comp = (from a in context.Company_table // where a.CompanyName == request.CompanyName // select a).FirstOrDefault(); //if (comp != null) // comp.EmployeeCount++; //emp.CompanyID = compId.Value; context.SaveChanges(); response.IsResourceReplaced = true; } return response; }
public ManageResourcesResponse DeleteResources(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); //Resources_table resource = new Resources_table(); using (var context = new Company_dbEntities()) { var resource = (from a in context.Resources_table where request.CompanyID == a.CompanyID && request.Serial == a.Serial select a).FirstOrDefault(); if(resource != null) { if(request.Deleted == true) { resource.Deleted = false; var comp = (from a in context.Company_table where a.CompanyID == request.CompanyID select a).FirstOrDefault<Company_table>(); if (comp != null) comp.ResourceCount++; } else { resource.Deleted = true; resource.EmployeeID = null; var comp = (from a in context.Company_table where a.CompanyID == request.CompanyID select a).FirstOrDefault<Company_table>(); if (comp != null) comp.ResourceCount--; //context.Resources_table.Remove(resource); } } context.SaveChanges(); response.ResourceDeleted = true; } return response; }
public ManageResourcesResponse CompanyDeleted(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); Resources_table resource = new Resources_table(); using (var context = new Company_dbEntities()) { resource = (from a in context.Resources_table select a).FirstOrDefault<Resources_table>(); if (resource != null) { context.Resources_table.Remove(resource); context.SaveChanges(); CompanyDeleted(request); } response.DeletedCompany = true; } return response; }
public ManageResourcesResponse ShowImage(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); using (var context = new Company_dbEntities()) { var image = (from a in context.Resources_table where a.Serial == request.Serial select a).FirstOrDefault(); if(image != null) { resourceDTO r = new resourceDTO(); r.Picture = image.Picture; response.resourceImage = r.Picture; } } return response; }
public ManageResourcesResponse ShowResources(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } List<resourceDTO> res = new List<resourceDTO>(); List<Resources_table> resource = new List<Resources_table>(); using (var context = new Company_dbEntities()) { resource = (from a in context.Resources_table where a.CompanyID == compId.Value select a).ToList(); if (resource != null) { foreach(var entry in resource) { resourceDTO r = new resourceDTO(); r.NameOfDevice = entry.NameOfDevice; r.Type = entry.Type; r.IssuedFrom = entry.IssuedFrom.ToString(); r.EmployeeID = entry.EmployeeID; r.Serial = entry.Serial; r.CompanyID = entry.CompanyID; r.Deleted = entry.Deleted; r.Picture = entry.Picture; r.IsActive = entry.IsActive; res.Add(r); } } response.ResourcesList = JsonConvert.SerializeObject(res); } return response; }
public ManageTaskResponse EmployeeConfirm(ManageTaskRequest request) { ManageTaskResponse response = new ManageTaskResponse(); using(var context = new Company_dbEntities()) { var confirm = (from a in context.Task_table where a.EmployeeID == request.UserName && a.Description == request.Description && a.AssignedBy == request.AssignedBy select a).FirstOrDefault<Task_table>(); if(confirm != null) { if(confirm.EmployeeConfirm == "Completed" && confirm.ManagerConfirm == "Approved") { context.SaveChanges(); response.ConfirmEmployee = true; } else { confirm.EmployeeConfirm = request.EmployeeConfirm; confirm.ManagerConfirm = null; context.SaveChanges(); response.ConfirmEmployee = true; } } else { response.ConfirmEmployee = false; } } return response; }
public ManageResourcesResponse UpdateResources(ManageResourcesRequest request) { ManageResourcesResponse response = new ManageResourcesResponse(); using (var context = new Company_dbEntities()) { var comp = (from a in context.Resources_table where a.NameOfDevice == request.NameOfDevice && a.Serial == request.Serial select a).FirstOrDefault<Resources_table>(); if (comp != null) { //comp = new Resources_table(); comp.Type = request.Type; //comp.IssuedTo = request.IssuedTo.ToShortDateString(); comp.IssuedFrom = request.IssuedFrom.ToShortDateString(); //comp.Picture = request.Picture; comp.IsActive = request.IsActive; } context.SaveChanges(); response.IsResourcesUpdated = true; } return response; }
public ManageTaskResponse TaskAssign(ManageTaskRequest request) { ManageTaskResponse response = new ManageTaskResponse(); //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); List<Task_table> task = new List<Task_table>(); List<task> list = new List<task>(); using (var context = new Company_dbEntities()) { task = (from a in context.Task_table where a.AssignedBy == request.UserName select a).ToList(); if(task != null) { foreach(var entry in task) { task t = new task(); t.EmployeeID = entry.EmployeeID; t.EmployeeName = entry.EmployeeName; t.Description = entry.Description; t.EmployeeConfirm = entry.EmployeeConfirm; t.ManagerConfirm = entry.ManagerConfirm; list.Add(t); } response.TaskAssign = JsonConvert.SerializeObject(list); } else { response.TaskAssign = null; } } return response; }
public ManageEmployeeResponse EmployeeDetail(ManageEmployeeRequest request) { ManageEmployeeResponse response = new ManageEmployeeResponse(); //List<Employee_table> employee = new List<Employee_table>(); using (var context = new Company_dbEntities()) { if(request.CompanyName != null) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) { throw new Exception("No company found. Try again!"); } var employee = (from a in context.Employee_table where a.CompanyID == compId.Value select a).ToList(); List<dto> dt = new List<dto>(); if (employee != null) { //response.IsEmployeeExist = true; foreach(var entry in employee) { dto d = new dto(); d.EmployeeName = entry.EmployeeName; d.EmployeeID = entry.UserName; d.Email = entry.Email; d.Designation = entry.Designation; //emp.DOB = employee.DOB; //emp.Department = employee.Department; d.ManagerID = entry.ManagerID; d.CompanyID = entry.CompanyID; // emp.CompanyId = employee.CompanyID; //emp.Address = employee.Address; //emp.Contact = employee.Contact; var emp = (from a in context.Employee_table where a.UserName == entry.UserName select a).Count(); if(emp > 1) { d.count = 1; } else { d.count = 0; } //var comp = (from a in context.Company_table where a.CompanyID == compId select a.Prefix).FirstOrDefault(); //d.EmployeeID = comp + entry.EmployeeID; dt.Add(d); } response.EmployeeInfo = JsonConvert.SerializeObject(dt); } } else { //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); var employee = (from a in context.Employee_table where a.UserName == request.UserName && a.Email == request.Email select a).FirstOrDefault(); if (employee != null) { response.IsEmployeeExist = true; dynamic emp = new ExpandoObject(); emp.EmployeeName = employee.EmployeeName; emp.UserName = employee.UserName; emp.Email = employee.Email; emp.Designation = employee.Designation; //emp.DOB = employee.DOB; //emp.Department = employee.Department; emp.ManagerId = employee.ManagerID; emp.CompanyId = employee.CompanyID; //emp.Address = employee.Address; //emp.Contact = employee.Contact; emp.EmployeeInfo = employee.EmployeeInfo; response.EmployeeInfo = JsonConvert.SerializeObject(emp); } } } return response; }
public ManageTaskResponse DeleteTask(ManageTaskRequest request) { ManageTaskResponse response = new ManageTaskResponse(); using (var context = new Company_dbEntities()) { var delete = (from a in context.Task_table where a.EmployeeID == request.UserName && a.Description == request.Description select a).FirstOrDefault<Task_table>(); if (delete != null) { context.Task_table.Remove(delete); context.SaveChanges(); response.TaskDeleted = true; } else { response.TaskDeleted = false; } } return response; }
// this works the same as search company... //public ManageCompanyResponse CheckCompany(ManageCompanyRequest request) //{ // ManageCompanyResponse response = new ManageCompanyResponse(); // //Company_table company = new Company_table(); // using (var context = new Company_dbEntities()) // { // var company = (from a in context.Company_table where request.CompanyName == a.CompanyName && request.OwnerName == a.OwnerName select a).FirstOrDefault<Company_table>(); // if (company != null) // { // response.IsCompanyExist = true; // } // else // { // response.IsCompanyExist = false; // } // } // return response; //} public ManageCompanyResponse allEmployee(ManageCompanyRequest request) { ManageCompanyResponse response = new ManageCompanyResponse(); using (var context = new Company_dbEntities()) { int? compId = AdapterHelper.GetCompanyId(request.CompanyName); if (compId == null) throw new Exception("No company found. Try again!"); // List<Employee_table> managers = new List<Employee_table>(); List<employee> emp = new List<employee>(); //Add FK bw employee and comapny table using company Id, redo LINQ for this- DONE! var emplo = (from a in context.Employee_table where a.CompanyID == compId select a).ToList(); foreach(var entry in emplo) { employee e = new employee(); e.UserName = entry.UserName; emp.Add(e); } //dynamic manList = new ExpandoObject(); //manList.Managers = managers; response.EmployeeList = JsonConvert.SerializeObject(emp); } return response; }
public ManageEmployeeResponse CheckManager(ManageEmployeeRequest request) { ManageEmployeeResponse response = new ManageEmployeeResponse(); using (var context = new Company_dbEntities()) { //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); var employee = (from a in context.Employee_table where a.UserName == request.UserName select a).FirstOrDefault(); if (employee != null && (employee.Designation == "Manager" || employee.Designation == "manager")) response.IsManager = true; else response.IsManager = false; } return response; }
public ManageEmployeeResponse employees(ManageEmployeeRequest request) { ManageEmployeeResponse response = new ManageEmployeeResponse(); //int? empId = AdapterHelper.GetEmployeeId(request.EmployeeName, request.Email); //if (!empId.HasValue) // throw new Exception("Employee does not exist!"); // List<dynamic> list = new List<dynamic>(); //List<Employee_table> employee = new List<Employee_table>(); using (var context = new Company_dbEntities()) { dto dt = new dto(); var employee = (from a in context.Employee_table where a.UserName == request.UserName select a).FirstOrDefault(); if (employee != null) { dt.EmployeeName = employee.EmployeeName; dt.EmployeeID = employee.UserName; // dt.EmployeeID = employee.EmployeeID; dt.ManagerID = employee.ManagerID; //dt.ManagerID = employee.ManagerID; //dt.Department = employee.Department; dt.Designation = employee.Designation; //dt.DOB = employee.DOB; //dt.Address = employee.Address; //dt.Contact = employee.Contact; dt.Email = employee.Email; dt.EmployeeInfo = employee.EmployeeInfo; //var comp = (from a in context.Company_table where a.CompanyID == employee.CompanyID select a.Prefix).FirstOrDefault(); //dt.EmployeeID = comp + employee.EmployeeID; } response.EmployeeList = JsonConvert.SerializeObject(dt); } return response; }