Пример #1
0
        public bool UpdateChore(ChoreEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Chores
                    .Single(e => e.ChoreId == model.ChoreId);

                entity.ChoreName        = model.ChoreName;
                entity.ChoreDescription = model.ChoreDescription;
                entity.Location         = model.Location;
                entity.Animal           = model.Animal;
                entity.TimeOfDay        = model.TimeOfDay;
                entity.IsDaily          = model.IsDaily;
                entity.ModifiedUtc      = DateTime.Now;

                return(ctx.SaveChanges() == 1);
            }
        }
Пример #2
0
        // PUT -- Chore by id
        public ActionResult Edit(int id)
        {
            var service = CreateChoreService();
            var detail  = service.GetChoreById(id);

            //var noteService = CreateNoteService();
            //var notes = noteService.GetNotesByChoreId();
            //ViewBag.Note = "Detail";

            var model =
                new ChoreEdit
            {
                ChoreId          = detail.ChoreId,
                ChoreName        = detail.ChoreName,
                ChoreDescription = detail.ChoreDescription,
                Location         = detail.Location,
                Animal           = detail.Animal,
                TimeOfDay        = detail.TimeOfDay,
                IsDaily          = detail.IsDaily
            };

            return(View(model));
        }
Пример #3
0
        public ActionResult Edit(int id, ChoreEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.ChoreId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateChoreService();

            if (service.UpdateChore(model))
            {
                TempData["SaveResult"] = "Chore was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Chore could not be updated.");
            return(View(model));
        }