public ActionResult DeleteConfirmed(int id, int locId) { DbChangeLog log = new DbChangeLog(); LocPhoneExts deletedLocPhoneExts = context.DeleteLocPhoneExt(id); log.UserName = User.Identity.Name; log.Controller = ControllerContext.RouteData.Values["controller"].ToString(); log.Action = ControllerContext.RouteData.Values["action"].ToString(); log.ItemId = id; log.BeforeChange = Domain.Extensions.DbLogExtensions.LocPhoneExtToString(deletedLocPhoneExts); if (deletedLocPhoneExts != null) { log.Success = true; TempData["message"] = string.Format("{0} was deleted", deletedLocPhoneExts.Name); } else { log.Success = false; log.Error = "Unable to delete location"; TempData["alert"] = "Sorry, there was an error, that location has not been deleted"; } context.SaveLog(log); return(RedirectToAction("Edit", "Locations", new { id = locId })); }
public static string LocPhoneExtToString(LocPhoneExts ext) { string locString = "<table class='table table-striped'>"; locString += "<tr><th>ID:</th><td>" + ext.Id.ToString() + "</td></tr>"; locString += "<tr><th>Name:</th><td>" + ext.Name + "</td></tr>"; locString += "<tr><th>Extension:</th><td>" + ext.Number + "</td></tr>"; locString += "<tr><th>Parent Phone ID:</th><td>" + ext.LocPhoneNumsId.ToString() + "</td></tr>"; locString += "</table>"; return(locString); }
public ActionResult Edit(LocPhoneExts locPhoneExts) { /***** Logging initial settings *****/ DbChangeLog log = new DbChangeLog(); log.UserName = User.Identity.Name; log.Controller = "LocPhoneExts"; log.Action = (locPhoneExts.Id != 0) ? "Edit" : "Create"; if (log.Action == "Edit") { LocPhoneExts oldExt = context.LocPhoneExts.FirstOrDefault(m => m.Id == locPhoneExts.Id); log.BeforeChange = Domain.Extensions.DbLogExtensions.LocPhoneExtToString(oldExt); } log.AfterChange = Domain.Extensions.DbLogExtensions.LocPhoneExtToString(locPhoneExts); /***** end Logging initial settings *****/ if (ModelState.IsValid) { try { context.SaveLocPhoneExt(locPhoneExts); log.ItemId = locPhoneExts.Id; log.Success = true; TempData["message"] = string.Format("{0} has been saved", locPhoneExts.Name); } catch (Exception e) { log.Error = e.ToString(); log.Success = false; TempData["alert"] = string.Format("There has been an error. {0} has not been saved", locPhoneExts.Name); } } else { log.Error = "Errors: "; NLogLogger logger = new NLogLogger(); logger.Info("There has been a validation error, this record has not been saved"); foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { log.Error += error + "<br />"; } } TempData["alert"] = "There has been a validation error, this record has not been saved"; } log.AfterChange = Domain.Extensions.DbLogExtensions.LocPhoneExtToString(locPhoneExts); context.SaveLog(log); return(RedirectToAction("Edit", new { id = locPhoneExts.Id })); }
public LocPhoneExts DeleteLocPhoneExt(int id) { LocPhoneExts dbEntry = context.LocPhoneExts.Find(id); if (dbEntry != null) { context.LocPhoneExts.Remove(dbEntry); context.SaveChanges(); SaveLocPhonesXMLFile(); } return(dbEntry); }
public void SaveLocPhoneExt(LocPhoneExts ext) { if (ext.Id == 0) { context.LocPhoneExts.Add(ext); } else { LocPhoneExts dbEntry = context.LocPhoneExts.Find(ext.Id); if (dbEntry != null) { dbEntry.Name = ext.Name; dbEntry.Number = ext.Number; } } context.SaveChanges(); SaveLocPhonesXMLFile(); }
// GET: LocPhoneExts/Edit/5 public ActionResult Edit(int?id) { if (id == null) { TempData["alert"] = "Sorry, I could not find the item you were looking for. Please try again."; return(View("~/Locations")); } LocPhoneExts phoneExts = context.LocPhoneExts.FirstOrDefault(e => e.Id == id); LocPhoneNums phones = context.LocPhoneNums.FirstOrDefault(p => p.Id == phoneExts.LocPhoneNumsId); LocationPhoneExtensionsViewModel model = new LocationPhoneExtensionsViewModel { Location = context.Locations.FirstOrDefault(p => p.Id == phones.LocationId), LocPhoneExts = phoneExts, PhoneNums = phones }; if (phoneExts == null) { return(HttpNotFound()); } return(View(model)); }