public ActionResult DeleteConfirmed(int id, int locId)
        {
            DbChangeLog log             = new DbChangeLog();
            LocHours    deletedLocHours = context.DeleteLocHour(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.LocHoursToString(deletedLocHours);
            if (deletedLocHours != null)
            {
                log.Success = true;

                TempData["message"] = string.Format("{0} : {1} was deleted", deletedLocHours.Days, deletedLocHours.Hours);
            }
            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 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 }));
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public LocHours DeleteLocHour(int id)
        {
            LocHours dbEntry = context.LocHours.Find(id);

            if (dbEntry != null)
            {
                context.LocHours.Remove(dbEntry);

                context.SaveChanges();
                SaveLocHoursXMLFile();
            }
            return(dbEntry);
        }
        // GET: LocHours/Edit/5
        public ActionResult Edit(int?id)
        {
            LocHours hours = context.LocHours
                             .FirstOrDefault(h => h.Id == id);

            LocHourCats cats = context.LocHourCats.FirstOrDefault(h => h.Id == hours.LocHourCatsId);

            LocationHoursViewModel model = new LocationHoursViewModel
            {
                Location = context.Locations
                           .FirstOrDefault(h => h.Id == cats.LocationId),
                Cats = cats,

                LocHours = hours
            };

            return(View(model));
        }
Beispiel #6
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();
 }