// GET: WFM_ProjectSector public ActionResult Index(int?id) { WFM_ProjectSector projectSector = new WFM_ProjectSector(); if (id != null) { projectSector = projectSectorService.GetProjectSectorById(id); } ViewBag.ProjectSectorList = projectSectorService.GetProjectSectorList().Where(o => o.ParentId == 0).OrderBy(o => o.Name).ToList(); return(View(projectSector)); }
public void SaveOrUpdate(WFM_ProjectSector projectSector) { using (LinkManagementEntities entities = new LinkManagementEntities()) { if (projectSector.Id == 0) { entities.WFM_ProjectSector.Add(projectSector); entities.SaveChanges(); } else { entities.Entry(projectSector).State = System.Data.Entity.EntityState.Modified; entities.SaveChanges(); } } }
public ActionResult SaveOrUpdate(WFM_ProjectSector model) { string newData = string.Empty, oldData = string.Empty; try { int id = model.Id; WFM_ProjectSector projectSector = null; WFM_ProjectSector oldProjectSector = null; if (model.Id == 0) { projectSector = new WFM_ProjectSector { Name = model.Name, IsActive = true, ParentId = (model.ParentId == null) ? 0 : model.ParentId }; oldProjectSector = new WFM_ProjectSector(); oldData = new JavaScriptSerializer().Serialize(oldProjectSector); newData = new JavaScriptSerializer().Serialize(projectSector); } else { projectSector = projectSectorService.GetProjectSectorById(model.Id); oldProjectSector = projectSectorService.GetProjectSectorById(model.Id); oldData = new JavaScriptSerializer().Serialize(new WFM_ProjectSector() { Id = oldProjectSector.Id, Name = oldProjectSector.Name, IsActive = oldProjectSector.IsActive, ParentId = oldProjectSector.ParentId }); projectSector.Name = model.Name; bool Example = Convert.ToBoolean(Request.Form["IsActive.Value"]); projectSector.IsActive = model.IsActive; projectSector.ParentId = (model.ParentId == null) ? 0 : model.ParentId; newData = new JavaScriptSerializer().Serialize(new WFM_ProjectSector() { Id = projectSector.Id, Name = projectSector.Name, IsActive = projectSector.IsActive, ParentId = projectSector.ParentId }); } projectSectorService.SaveOrUpdate(projectSector); CommonService.SaveDataAudit(new DataAudit() { Entity = "WFM_ProjectSector", NewData = newData, OldData = oldData, UpdatedOn = DateTime.Now, UserId = new Guid(User.Identity.GetUserId()) }); TempData["Message"] = "<div id='flash-success'>Record Saved Successfully.</div>"; } catch (Exception ex) { TempData["Message"] = "<span id='flash-error'>Error.</span>" + ex.InnerException; } return(RedirectToAction("Index", "ProjectSector")); }