public bool PostEmployee(WorkModel model) { panconDatabaseEntities entities = new panconDatabaseEntities(); try { if (model.EmpOperation == "Save") { Contractors contractor = (from c in entities.Contractors where (c.CompanyName == model.ContractorName) select c).FirstOrDefault(); Employees newEntry = new Employees() { ContractorId = contractor.ContractorId, Username = model.Username, Password = model.Password, Firstname = model.Firstname, Lastname = model.Lastname, Phone = model.Phone.ToString(), Email = model.Email, CreatedAt = DateTime.Now, Active = true, }; entities.Employees.Add(newEntry); } else if (model.EmpOperation == "Modify") { Employees existing = (from e in entities.Employees where (e.EmployeeId == model.EmployeeId) && (e.Active == true) select e).FirstOrDefault(); if (existing != null) { existing.Firstname = model.Firstname; existing.Lastname = model.Lastname; existing.Phone = model.Phone.ToString(); existing.Email = model.Email; existing.LastModified = DateTime.Now; existing.EmployeePicture = model.Picture; } else { return(false); } } else if (model.EmpOperation == "Delete") { Employees existing = (from e in entities.Employees where (e.EmployeeId == model.EmployeeId) select e).FirstOrDefault(); if (existing != null) { entities.Employees.Remove(existing); } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public List <string> GetChosenEntity(string Entity) { panconDatabaseEntities entities = new panconDatabaseEntities(); string[] sheet = null; string[] workAssignments = (from wa in entities.WorkAssignments where (wa.Active == true) select wa.Title).ToArray(); string[] employees = (from e in entities.Employees where (e.Active == true) select e.Firstname + " " + e.Lastname).ToArray(); string[] contractors = (from cont in entities.Contractors where (cont.Active == true) select cont.CompanyName).ToArray(); List <string[]> empData = new List <string[]>(); List <string[]> contData = new List <string[]>(); List <string[]> WorkData = new List <string[]>(); WorkData.Add(workAssignments); empData.Add(employees); contData.Add(contractors); foreach (var item in empData) { foreach (var i in item) { if (i.ToString() == Entity) { string emplo = (from e in entities.Employees where (e.Firstname + " " + e.Lastname == Entity) select e.EmployeeId.ToString()).Single(); sheet = (from ts in entities.Timesheets where (ts.EmployeeId.ToString() == emplo) select ts.ContractorId.ToString() + " " + ts.EmployeeId.ToString() + " " + ts.WorkAssignmentId.ToString()).ToArray(); } } } foreach (var itemm in WorkData) { foreach (var it in itemm) { if (it.ToString() == Entity) { string worka = (from w in entities.WorkAssignments where (w.Title == Entity) select w.WorkAssignmentId.ToString()).Single(); sheet = (from ts in entities.Timesheets where (ts.WorkAssignmentId.ToString() == worka) select ts.ContractorId.ToString() + " " + ts.EmployeeId.ToString() + " " + ts.WorkAssignmentId.ToString()).ToArray(); } } } foreach (var iten in contData) { foreach (var ite in iten) { if (ite.ToString() == Entity) { string contra = (from c in entities.Contractors where (c.CompanyName == Entity) select c.ContractorId.ToString()).Single(); sheet = (from ts in entities.Timesheets where (ts.ContractorId.ToString() == contra) select ts.ContractorId.ToString() + " " + ts.EmployeeId.ToString() + " " + ts.WorkAssignmentId.ToString()).ToArray(); } } } List <string> entityList = new List <string>(); try { foreach (var item in sheet) { string[] datas = item.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string contractor = datas[0]; string contr = (from c in entities.Contractors where (c.ContractorId.ToString() == contractor) select c.CompanyName).Single(); string employee = datas[1]; string emp = (from e in entities.Employees where (e.EmployeeId.ToString() == employee) select e.Firstname + " " + e.Lastname).Single(); string workid = datas[2]; string work = (from w in entities.WorkAssignments where (w.WorkAssignmentId.ToString() == workid) select w.Title).Single(); entityList.Add(contr + " | " + emp + " | " + work + " " + "( " + workid + " )"); } } finally { entities.Dispose(); } return(entityList); }
public bool PostStatus(WorkAssignmentOperationModel input) { panconDatabaseEntities entities = new panconDatabaseEntities(); try { WorkAssignments assignment = (from wa in entities.WorkAssignments where (wa.Active == true) && (wa.Title == input.AssignmentTitle) select wa).FirstOrDefault(); if (assignment == null) { return(false); } if (input.Operation == "Start") { int assignmentId = assignment.WorkAssignmentId; Timesheets NewEntry = new Timesheets() { WorkAssignmentId = assignmentId, StartTime = DateTime.Now, WorkComplete = false, Active = true, CreatedAt = DateTime.Now }; entities.Timesheets.Add(NewEntry); assignment.InProgress = true; assignment.InProgressAt = DateTime.Now; assignment.LastModified = DateTime.Now; } else if (input.Operation == "Stop") { int assignmentId = assignment.WorkAssignmentId; Timesheets existing = (from ts in entities.Timesheets where (ts.WorkAssignmentId == assignmentId) && (ts.Active == true) && (ts.WorkComplete == false) orderby ts.StartTime descending select ts).FirstOrDefault(); if (existing != null) { existing.StopTime = DateTime.Now; existing.WorkComplete = true; existing.LastModified = DateTime.Now; assignment.InProgress = false; assignment.Completed = true; assignment.CompletedAt = DateTime.Now; assignment.LastModified = DateTime.Now; } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public bool PostContractor(WorkModel model) { panconDatabaseEntities entities = new panconDatabaseEntities(); try { if (model.ContOperation == "Save") { Contractors newEntry = new Contractors() { CompanyName = model.ContractorName, ContactPerson = model.ContractorContactPerson, Phone = model.ContractorPhone, Email = model.ContractorEmail, VatId = model.VatId, HourlyRate = int.Parse(model.HourlyRate), Active = true, CreatedAt = DateTime.Now }; entities.Contractors.Add(newEntry); } else if (model.ContOperation == "Modify") { Contractors existing = (from co in entities.Contractors where (co.ContractorId == model.ContractorId) && (co.Active == true) select co).FirstOrDefault(); if (existing != null) { existing.CompanyName = model.ContractorName; existing.ContactPerson = model.ContractorContactPerson; existing.Phone = model.ContractorPhone; existing.Email = model.ContractorEmail; existing.VatId = model.VatId; existing.HourlyRate = int.Parse(model.HourlyRate); existing.LastModified = DateTime.Now; } else { return(false); } } else if (model.ContOperation == "Delete") { Contractors existing = (from e in entities.Contractors where (e.ContractorId == model.ContractorId) select e).FirstOrDefault(); if (existing != null) { entities.Contractors.Remove(existing); } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }