// GET: Country public ActionResult Index(int?id) { WFM_Country country = new WFM_Country(); if (id != null) { country = countryService.GetCountryById(id); } return(View(country)); }
public void SaveOrUpdate(WFM_Country designation) { using (LinkManagementEntities entities = new LinkManagementEntities()) { if (designation.Id == 0) { entities.WFM_Country.Add(designation); entities.SaveChanges(); } else { entities.Entry(designation).State = System.Data.Entity.EntityState.Modified; entities.SaveChanges(); } } }
public ActionResult SaveOrUpdate(WFM_Country model) { string newData = string.Empty, oldData = string.Empty; try { int id = model.Id; WFM_Country country = null; WFM_Country oldCountry = null; if (model.Id == 0) { country = new WFM_Country { Name = model.Name, IsActive = true }; oldCountry = new WFM_Country(); oldData = new JavaScriptSerializer().Serialize(oldCountry); newData = new JavaScriptSerializer().Serialize(country); } else { country = countryService.GetCountryById(model.Id); oldCountry = countryService.GetCountryById(model.Id); oldData = new JavaScriptSerializer().Serialize(new WFM_Country() { Id = oldCountry.Id, Name = oldCountry.Name, IsActive = oldCountry.IsActive }); country.Name = model.Name; bool Example = Convert.ToBoolean(Request.Form["IsActive.Value"]); country.IsActive = model.IsActive; newData = new JavaScriptSerializer().Serialize(new WFM_Country() { Id = country.Id, Name = country.Name, IsActive = country.IsActive }); } countryService.SaveOrUpdate(country); CommonService.SaveDataAudit(new DataAudit() { Entity = "Country", 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", "Country")); }