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 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 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();
 }