Exemplo n.º 1
0
        public ActionResult Edit(LocHours locHours)
        {
            /***** Logging initial settings *****/
            DbChangeLog log = new DbChangeLog();
            log.UserName = User.Identity.Name;
            log.Controller = "LocHours";
            log.Action = (locHours.Id != 0) ? "Edit" : "Create";

            if (log.Action == "Edit")
            {
                LocHours oldHours = context.LocHours.FirstOrDefault(m => m.Id == locHours.Id);
                log.BeforeChange = Domain.Extensions.DbLogExtensions.LocHoursToString(oldHours);
            }
            log.AfterChange = Domain.Extensions.DbLogExtensions.LocHoursToString(locHours);
            /***** end Logging initial settings *****/

            if (ModelState.IsValid)
            {
                try
                {
                    context.SaveLocHours(locHours);
                    log.ItemId = locHours.Id;

                    log.Success = true;
                    TempData["message"] = string.Format("{0} : {1} has been saved", locHours.Days, locHours.Hours);
                }
                catch (Exception e)
                {
                    log.Error = e.ToString();
                    log.Success = false;
                    TempData["alert"] = string.Format("There has been an error. {0} : {1} has not been saved", locHours.Days, locHours.Hours);
                }

            }
            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.LocHoursToString(locHours);
            context.SaveLog(log);
            return RedirectToAction("Edit",new { id = locHours.Id });
        }
Exemplo n.º 2
0
 public static string LocHoursToString(LocHours hours)
 {
     string locString = "<table class='table table-striped'>";
     locString += "<tr><th>ID:</th><td>" + hours.Id.ToString() + "</td></tr>";
     locString += "<tr><th>Days:</th><td>" + hours.Days + "</td></tr>";
     locString += "<tr><th>Hours:</th><td>" + hours.Hours + "</td></tr>";
     locString += "<tr><th>Priority:</th><td>" + hours.Priority.ToString() + "</td></tr>";
     locString += "<tr><th>Parent Category ID:</th><td>" + hours.LocHourCatsId.ToString() + "</td></tr>";
     locString += "</table>";
     return locString;
 }
Exemplo n.º 3
0
 public void SaveLocHours(LocHours hours)
 {
     if (hours.Id == 0)
     {
         context.LocHours.Add(hours);
     }
     else
     {
         LocHours dbEntry = context.LocHours.Find(hours.Id);
         if (dbEntry != null)
         {
             dbEntry.Days = hours.Days;
             dbEntry.Hours = hours.Hours;
             dbEntry.Priority = hours.Priority;
         }
     }
     context.SaveChanges();
     SaveLocHoursXMLFile();
 }