Наследование: System.Web.UI.Page
Пример #1
0
        public bool UpdateShift(ShiftEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Shifts.SingleOrDefault(e => e.ShiftId == model.ShiftId);

                entity.Shift = model.Shift;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #2
0
        //GET: Shift/Edit/{id}
        public ActionResult Edit(int id)
        {
            ShiftDetail detail = service.GetShiftById(id);
            ShiftEdit   model  = new ShiftEdit
            {
                ShiftId = detail.ShiftId,
                Shift   = detail.Shift
                          //Should I add employee here?
            };

            return(View(model));
        }
Пример #3
0
        // GET: Edit
        // Shift/Edit/{id}

        public ActionResult Edit(int id)
        {
            var service = CreateShiftService();
            var detail  = service.GetShiftById(id);

            var model =
                new ShiftEdit
            {
                ShiftId   = detail.ShiftId,
                ShiftName = detail.ShiftName,
                Date      = detail.Date,
                Notes     = detail.Notes
            };

            return(View(model));
        }
Пример #4
0
        public bool UpdateShift(ShiftEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Shifts
                    .FirstOrDefault(e => e.ShiftId == model.ShiftId && e.OwnerId == _userId);

                entity.ShiftName = model.ShiftName;
                entity.Date      = model.Date;
                entity.Notes     = model.Notes;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #5
0
        public ActionResult Edit(int id, ShiftEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ShiftId != id)
            {
                ModelState.AddModelError("", "ID does not match.");
                return(View(model));
            }
            if (service.UpdateShift(model))
            {
                TempData["SaveShiftResult"] = $"Shift {service.GetShiftById(id).Shift} was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Shift could not be updated.");
            return(View());
        }
Пример #6
0
        public ActionResult Edit(int id, ShiftEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ShiftId != id)
            {
                ModelState.AddModelError("", "The Id's do not match.");
                return(View(model));
            }

            var service = CreateShiftService();

            if (service.UpdateShift(model))
            {
                TempData["SaveResult"] = $"{model.ShiftName} has been updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "This Shift was NOT updated successfully.");
            return(View());
        }