Пример #1
0
        public ActionResult Edit(LocHourCats locHourCats)
        {
            /***** Logging initial settings *****/

            DbChangeLog log = new DbChangeLog();

            log.UserName   = User.Identity.Name;
            log.Controller = "LocHourCats";
            log.Action     = (locHourCats.Id != 0) ? "Edit" : "Create";
            log.ItemId     = locHourCats.Id;
            // if this is an edit to an exhisting item, record the old item to the log
            if (log.Action == "Edit")
            {
                LocHourCats oldCat = context.LocHourCats.FirstOrDefault(c => c.Id == locHourCats.Id);
                log.BeforeChange = Domain.Extensions.DbLogExtensions.LocCatToString(oldCat);
            }

            // record the newly attempted change
            log.AfterChange = Domain.Extensions.DbLogExtensions.LocCatToString(locHourCats);

            /***** end Logging initial settings *****/

            if (ModelState.IsValid)
            {
                try
                {
                    context.SaveLocHourCat(locHourCats);

                    // need to record the id here, if this item has just been created it will not have an ID until it has been recorded to the DB
                    log.ItemId          = locHourCats.Id;
                    log.Success         = true;
                    TempData["message"] = string.Format("{0} has been saved", locHourCats.Name);
                }

                catch (Exception e)
                {
                    log.Error         = e.ToString();
                    log.Success       = false;
                    TempData["alert"] = "There has been an error. That item has not been saved";
                }
            }
            else
            {
                TempData["alert"] = string.Format("{0} has not been saved", locHourCats.Name);

                // record the errors and error status to the log
                log.Success = false;
                log.Error   = "Errors: ";
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        log.Error += error + "<br />";
                    }
                }
            }

            context.SaveLog(log);
            return(RedirectToAction("Edit", new { Id = locHourCats.Id }));
        }
Пример #2
0
        public ActionResult Delete(int id)
        {
            DbChangeLog log        = new DbChangeLog();
            LocHourCats deletedCat = context.DeleteLocHourCat(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.LocCatToString(deletedCat);
            if (deletedCat != null)
            {
                log.Success = true;

                TempData["message"] = string.Format("{0} was deleted", deletedCat.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 = deletedCat.LocationId }));
        }
Пример #3
0
        public static string LocCatToString(LocHourCats cat)
        {
            string locString = "<table class='table table-striped'>";

            locString += "<tr><th>ID:</th><td>" + cat.Id.ToString() + "</td></tr>";
            locString += "<tr><th>Name:</th><td>" + cat.Name + "</td></tr>";
            locString += "<tr><th>Location ID:</th><td>" + cat.LocationId + "</td></tr>";
            locString += "</table>";
            return(locString);
        }
Пример #4
0
        public LocHourCats DeleteLocHourCat(int id)
        {
            LocHourCats dbEntry = context.LocHourCats.Find(id);

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

                context.SaveChanges();
                SaveLocHoursXMLFile();
                SaveLocHoursXMLFile();
            }
            return(dbEntry);
        }
Пример #5
0
        // GET: LocHours/Create
        public ActionResult Manage(int id)
        {
            LocHourCats cats = context.LocHourCats.FirstOrDefault(h => h.Id == id);

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

                LocHours = new LocHours()
            };

            return(View(model));
        }
Пример #6
0
        // 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));
        }
Пример #7
0
 public void SaveLocHourCat(LocHourCats hourCat)
 {
     if (hourCat.Id == 0)
     {
         context.LocHourCats.Add(hourCat);
     }
     else
     {
         LocHourCats dbEntry = context.LocHourCats.Find(hourCat.Id);
         if (dbEntry != null)
         {
             dbEntry.Name       = hourCat.Name;
             dbEntry.LocationId = hourCat.LocationId;
         }
     }
     context.SaveChanges();
     SaveLocHoursXMLFile();
 }
Пример #8
0
        // GET: LocHourCats/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"));
            }
            LocHourCats locHours = context.LocHourCats.FirstOrDefault(p => p.Id == id);

            LocationCatsViewModel model = new LocationCatsViewModel
            {
                Location    = context.Locations.FirstOrDefault(l => l.Id == locHours.LocationId),
                LocHourCats = locHours
            };

            if (locHours == null)
            {
                return(HttpNotFound());
            }
            return(View(model));
        }