public ActionResult EditOrCreate(IntegrationWebSiteMvc.Models.Employee newInstance) { try { /* // APPROACH 1 => Allow EF to work out what has changed by comparing to copy in DB // Load current account from DB IntegrationWebSiteMvc.Models.Employee storedInstance = _modelContext.Employees.Single(p => p.ADLoginID == newInstance.ADLoginID); // Update the properties _modelContext.Entry(storedInstance).CurrentValues.SetValues(newInstance); // Save the changes _modelContext.SaveChanges(); */ /* // APPROACH 2 => Assumes changes even thougth may not be any _modelContext.Entry(newInstance).State = EntityState.Modified; _modelContext.SaveChanges(); */ // Update Employee Data in Master DB IntegrationWebSiteMvc.Models.Employee storedInstance = _modelContext.Employees.Find(newInstance.ADLoginID); if (storedInstance != null) { // newInstance.AreaDetails = _modelContext.Areas.ToList().Find(p => p.ID == newInstance.AreaDetails.ID); _modelContext.Entry(storedInstance).CurrentValues.SetValues(newInstance); } else { _modelContext.Employees.Add(newInstance); } _modelContext.SaveChanges(); // Update Employee Data in non-Master DBs _modelContext.SynchroniseData(newInstance); return RedirectToAction("Index"); } catch (Exception excE) { throw excE; } }
public ActionResult Areas(IntegrationWebSiteMvc.Models.AreaData model) { return RedirectToAction("Index"); }
public ActionResult EditOrCreateArea(IntegrationWebSiteMvc.Models.AreaData model) { try { _modelContext.SaveEmployeeArea(model.ADLoginID, model.SubAreaID); return RedirectToAction("Areas", new { id = model.ADLoginID }); } catch (Exception excE) { throw excE; } }
public ActionResult EditOrCreatePostCode(IntegrationWebSiteMvc.Models.PostCodeResponsibility newInstance, string adLoginID) { try { /* // APPROACH 1 => Allow EF to work out what has changed by comparing to copy in DB // Load current account from DB IntegrationWebSiteMvc.Models.Employee storedInstance = _modelContext.Employees.Single(p => p.ADLoginID == newInstance.ADLoginID); // Update the properties _modelContext.Entry(storedInstance).CurrentValues.SetValues(newInstance); // Save the changes _modelContext.SaveChanges(); */ /* // APPROACH 2 => Assumes changes even though may not be any _modelContext.Entry(newInstance).State = EntityState.Modified; _modelContext.SaveChanges(); */ IntegrationWebSiteMvc.Models.Employee storedInstance = _modelContext.Employees.Single(p => p.ADLoginID == adLoginID); if (storedInstance != null && storedInstance.PostCodeResponsibilities != null && storedInstance.PostCodeResponsibilities.ToList().Find(p => p.ID == newInstance.ID) != null) { _modelContext.Entry(storedInstance).CurrentValues.SetValues(newInstance); } else { // _modelContext.Employees.Single(p => p.ADLoginID == adLoginID).Skills.Add(newInstance); if (storedInstance.PostCodeResponsibilities == null) { storedInstance.PostCodeResponsibilities = new List<IntegrationWebSiteMvc.Models.PostCodeResponsibility>(); } newInstance.ID = storedInstance.PostCodeResponsibilities.Count + 1; storedInstance.PostCodeResponsibilities.Add(newInstance); } _modelContext.SaveChanges(); return RedirectToAction("Index"); } catch (Exception excE) { throw excE; } }