public HttpResponseMessage Xamarin_reg(WorkModel input) { try { var same = entities.Employees.Any(u => u.Username == input.Username); if (same == true) { return(Request.CreateResponse(HttpStatusCode.Unauthorized, "Username is in use, try a." + same.ToString())); } else { Employees employee = new Employees(); employee.Firstname = input.Firstname; employee.Lastname = input.Lastname; employee.Phone = input.Phone; employee.Email = input.Email; employee.Username = input.Username; employee.Password = input.Password; entities.Employees.Add(employee); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Accepted, "Successfully Created")); } } finally { entities.Dispose(); } }
public bool PostChanges(WorkModel model) { panconDatabaseEntities entities = new panconDatabaseEntities(); try { Employees MyProfile = (from ce in entities.Employees where (ce.Active == true) && (ce.Firstname + " " + ce.Lastname == model.Firstname + " " + model.Lastname) select ce).FirstOrDefault(); if (MyProfile == null) { return(false); } int employeeId = MyProfile.EmployeeId; Employees existing = (from e in entities.Employees where (e.EmployeeId == employeeId) && (e.Active == true) select e).FirstOrDefault(); if (existing != null && model.Picture != null && model.Operation == "Save") { 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 if (existing != null && model.Picture == null && model.Operation == "Save") { existing.Firstname = model.Firstname; existing.Lastname = model.Lastname; existing.Phone = model.Phone.ToString(); existing.Email = model.Email; existing.LastModified = DateTime.Now; } else if (existing != null && model.Operation == "SavePw") { existing.Password = model.Password; } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public ActionResult Update(Employees empl) { panconDatabaseEntities entities = new panconDatabaseEntities(); bool OK = false; if (empl.EmployeeId == 0) { Employees dbItem = new Employees() { Firstname = empl.Firstname, Lastname = empl.Lastname, }; entities.Employees.Add(dbItem); entities.SaveChanges(); OK = true; entities.Dispose(); return(Json(OK)); } else { Employees dbItem = (from e in entities.Employees where e.EmployeeId == empl.EmployeeId select e).FirstOrDefault(); if (dbItem != null) { dbItem.Firstname = empl.Firstname; dbItem.Lastname = empl.Lastname; entities.SaveChanges(); } ; OK = true; entities.Dispose(); return(Json(OK, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(int id) { panconDatabaseEntities entities = new panconDatabaseEntities(); bool OK = false; Employees dbItem = (from e in entities.Employees where e.EmployeeId == id select e).FirstOrDefault(); if (dbItem != null) { entities.Employees.Remove(dbItem); entities.SaveChanges(); OK = true; } entities.Dispose(); return(Json(OK, JsonRequestBehavior.AllowGet)); }
public string PutEmployeeImage() { panconDatabaseEntities entities = new panconDatabaseEntities(); try { Employees newEmployee = new Employees() { Firstname = "X", Lastname = "MAN", EmployeePicture = File.ReadAllBytes(@"C:\Users\Admin\Pictures\car.png") }; entities.Employees.Add(newEmployee); entities.SaveChanges(); return("OK!"); } finally { entities.Dispose(); } return("Error!"); }
public bool PostCustomer(WorkModel model) { panconDatabaseEntities entities = new panconDatabaseEntities(); try { if (model.CustOperation == "Save") { Customers newEntry = new Customers() { CustomerName = model.CustomerName, ContactPerson = model.ContactPerson, Phone = model.CustomerPhone, Email = model.CustomerEmail, CreatedAt = DateTime.Now, Active = true }; entities.Customers.Add(newEntry); } else if (model.CustOperation == "Modify") { Customers existing = (from c in entities.Customers where (c.CustomerId == model.CustomerId) && (c.Active == true) select c).FirstOrDefault(); if (existing != null) { existing.CustomerName = model.CustomerName; existing.ContactPerson = model.ContactPerson; existing.Phone = model.CustomerPhone; existing.Email = model.CustomerEmail; existing.LastModified = DateTime.Now; } else { return(false); } } else if (model.CustOperation == "Delete") { Customers chosenCustomer = (from cc in entities.Customers where (cc.CustomerName == model.CustomerName) select cc).FirstOrDefault(); if (chosenCustomer == null) { return(false); } int customerId = chosenCustomer.CustomerId; Customers existing = (from e in entities.Customers where (e.CustomerId == customerId) select e).FirstOrDefault(); if (existing != null) { entities.Customers.Remove(existing); } else { return(false); } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
public bool PostWork(WorkModel model) { panconDatabaseEntities entities = new panconDatabaseEntities(); Customers customer = (from cu in entities.Customers where (cu.Active == true) && (cu.CustomerName == model.CustomerName) select cu).FirstOrDefault(); try { if (model.Operation == "Save") { WorkAssignments newEntry = new WorkAssignments() { CustomerId = customer.CustomerId, Title = model.WorkTitle, Description = model.Description, Deadline = model.Deadline, InProgress = true, CreatedAt = DateTime.Now, Active = true }; entities.WorkAssignments.Add(newEntry); } else if (model.Operation == "Modify") { WorkAssignments existing = (from wa in entities.WorkAssignments where (wa.WorkAssignmentId == model.WorkId) && (wa.Active == true) select wa).FirstOrDefault(); if (existing != null) { existing.Title = model.WorkTitle; existing.Description = model.Description; existing.Deadline = model.Deadline; existing.LastModified = DateTime.Now; } else { return(false); } } else if (model.Operation == "Delete") { WorkAssignments existing = (from wa in entities.WorkAssignments where (wa.WorkAssignmentId == model.WorkId) select wa).FirstOrDefault(); if (existing != null) { entities.WorkAssignments.Remove(existing); } else { return(false); } } else if (model.Operation == "Assign") { WorkAssignments assignment = (from wa in entities.WorkAssignments where (wa.WorkAssignmentId == model.WorkId) && (wa.Active == true) && (wa.InProgress == true) select wa).FirstOrDefault(); if (assignment == null) { return(false); } Employees emp = (from e in entities.Employees where (e.EmployeeId == model.EmployeeId) select e).FirstOrDefault(); if (emp == null) { return(false); } int workId = assignment.WorkAssignmentId; int customerId = assignment.CustomerId.Value; assignment.InProgressAt = DateTime.Now; Timesheets newEntry = new Timesheets() { CustomerId = customerId, ContractorId = emp.ContractorId, EmployeeId = emp.EmployeeId, WorkAssignmentId = workId, StartTime = DateTime.Now, CreatedAt = DateTime.Now, Active = true, WorkComplete = false }; entities.Timesheets.Add(newEntry); } else if (model.Operation == "MarkComplete") { WorkAssignments assignment = (from wa in entities.WorkAssignments where (wa.WorkAssignmentId == model.WorkId) && (wa.Active == true) && (wa.InProgress == true) && (wa.InProgressAt != null) select wa).FirstOrDefault(); if (assignment == null) { return(false); } int workId = assignment.WorkAssignmentId; int customerId = assignment.CustomerId.Value; assignment.CompletedAt = DateTime.Now; assignment.Completed = true; assignment.InProgress = false; Timesheets existing = (from ts in entities.Timesheets where (ts.WorkAssignmentId == workId) && (ts.CustomerId == customerId) select ts).FirstOrDefault(); if (existing != null) { existing.WorkComplete = true; existing.StopTime = DateTime.Now; existing.LastModified = DateTime.Now; existing.Comments = "Work set to completed by Admin"; } } entities.SaveChanges(); } catch { return(false); } finally { entities.Dispose(); } return(true); }
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 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); }