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 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 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 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 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 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 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 bool addToDB(string EmployeeID, string Picture) { using (var context = new Company_dbEntities()) { var image = (from a in context.Employee_table where a.EmployeeID == EmployeeID select a).FirstOrDefault <Employee_table>(); if (image != null) { image.Picture = Picture; context.SaveChanges(); return(true); } else { context.SaveChanges(); return(false); } } }
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 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 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 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 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); }
//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 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 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 csvUploadResponse ParseCSV(csvUploadRequest request) { csvUploadResponse response = new csvUploadResponse(); List <dto> list = new List <dto>(); dto dt = new dto(); List <dynamic> data = new List <dynamic>(); data.Add(parse(request)); using (var context = new Company_dbEntities()) { var comp = (from a in context.Company_table where a.CompanyName == request.CompanyName select a).FirstOrDefault <Company_table>(); if (comp != null) { if (request.Employee == true) { foreach (var entry in data[0]) { dynamic fields = JsonConvert.SerializeObject(entry.Data); dynamic item = JsonConvert.DeserializeObject(fields); dt.UserName = item.UserName; dt.Email = item.Email; var emp = (from a in context.Employee_table where a.UserName == dt.UserName && a.Email == dt.Email select a).FirstOrDefault(); if (emp == null) { emp = new Employee_table(); emp.CompanyID = comp.CompanyID; emp.EmployeeName = item.EmployeeName; emp.Email = item.Email; emp.ManagerID = item.ManagerID; emp.Designation = item.Designation; emp.UserName = item.UserName; emp.ModifiedOn = DateTime.Now; emp.IsActive = true; var company = (from a in context.Company_table where a.CompanyID == comp.CompanyID select a).FirstOrDefault(); company.EmployeeCount++; context.Employee_table.Add(emp); context.SaveChanges(); response.csvUploaded = true; } else { dto d = new dto(); d.UserName = item.UserName; d.Email = item.Email; d.EmployeeName = item.EmployeeName; d.CompanyName = item.CompanyName; d.Designation = item.Designation; d.ManagerID = item.ManagerID; list.Add(d); } } response.Duplicate = JsonConvert.SerializeObject(list); response.csvUploaded = false; } else { foreach (var entry in data[0]) { dynamic fields = JsonConvert.SerializeObject(entry.Data); dynamic item = JsonConvert.DeserializeObject(fields); dt.Serial = item.Serial; var res = (from a in context.Resources_table where a.Serial == dt.Serial select a).FirstOrDefault <Resources_table>(); if (res == null) { res = new Resources_table(); res.CompanyID = comp.CompanyID; res.NameOfDevice = item.NameOfDevice; //res.EmployeeID = item.UserName; res.Type = item.Type; res.Serial = item.Serial; res.IssuedFrom = item.IssuedFrom; res.ModifiedOn = DateTime.Now; res.Deleted = false; //res.IsActive = true; var company = (from a in context.Company_table where a.CompanyID == comp.CompanyID select a).FirstOrDefault(); company.ResourceCount++; context.Resources_table.Add(res); context.SaveChanges(); response.csvUploaded = true; } else { dto d = new dto(); d.UserName = item.UserName; d.NameOfDevice = item.NameOfDevice; d.Type = item.Type; d.Serial = item.Serial; d.IssuedFrom = item.IssuedFrom; d.CompanyName = request.CompanyName; list.Add(d); } } response.Duplicate = JsonConvert.SerializeObject(list); response.csvUploaded = false; } } else { throw new Exception("Company Name does not Exists. Try again."); } } 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 HttpResponseMessage uploadImage() { HttpResponseMessage response = null; try { if (HttpContext.Current.Request.Files.AllKeys.Any()) { var uploadedImage = HttpContext.Current.Request.Files["UploadImage"]; var path = HttpContext.Current.Request.Params["FolderPath"]; var employeeID = HttpContext.Current.Request.Params["EmployeeID"]; if (uploadedImage != null) { var source = Path.Combine(HttpContext.Current.Server.MapPath("~/Images/"), path); bool exist = Directory.Exists(source); if (!exist) { Directory.CreateDirectory(source); } var employeeFolder = Path.Combine(source, employeeID + "/"); bool present = Directory.Exists(employeeFolder); if (!present) { Directory.CreateDirectory(employeeFolder); } if (string.Equals(Path.GetExtension(uploadedImage.FileName), ".zip", StringComparison.InvariantCultureIgnoreCase)) { List <Image> pic = new List <Image>(); var zipFilePath = Path.Combine(employeeFolder, uploadedImage.FileName); uploadedImage.SaveAs(zipFilePath); using (ZipArchive archive = System.IO.Compression.ZipFile.OpenRead(zipFilePath)) { foreach (ZipArchiveEntry entry in archive.Entries) { entry.ExtractToFile(Path.Combine(employeeFolder, entry.FullName)); Image i = new Image(); i.name = entry.FullName; pic.Add(i); } using (var context = new Company_dbEntities()) { var result = JsonConvert.SerializeObject(pic); var image = (from a in context.Resources_table where a.Serial == employeeID select a).FirstOrDefault(); image.Picture = result; context.SaveChanges(); } } } else { var picture = Path.Combine(employeeFolder, uploadedImage.FileName); using (var context = new Company_dbEntities()) { var image = (from a in context.Resources_table where a.Serial == employeeID select a).FirstOrDefault(); if (image != null) { Image i = new Image(); i.name = uploadedImage.FileName; var result = JsonConvert.SerializeObject(i); image.Picture = result; context.SaveChanges(); } } // else // { // var profile = (from a in context.Employee_table where a.EmployeeID.ToString() == employeeID select a).FirstOrDefault(); // profile.EmployeeInfo = info; // context.SaveChanges(); // } //} uploadedImage.SaveAs(picture); } } response = Request.CreateResponse(HttpStatusCode.OK, true); } else { response = Request.CreateResponse(HttpStatusCode.OK, true); } } catch (Exception ex) { throw ex; } return(response); }