Exemplo n.º 1
0
        // UpdateThing
        public bool UpdateThing(ThingEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx
                             .Things
                             .Single(e => e.ThingId == model.ThingId && e.OwnerId == _userId);
                entity.Heading      = model.Heading;
                entity.TimeAllotted = model.TimeAllotted;
                entity.IsCompleted  = model.IsCompleted;
                entity.CatagoryId   = model.CatagoryId;
                entity.ModifiedUtc  = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            var service = CreateThingService();
            var detail  = service.GetThingById(id);

            ViewBag.Catagories = service.CatagoriesToList();
            var model =
                new ThingEdit
            {
                ThingId      = detail.ThingId,
                Heading      = detail.Heading,
                CatagoryId   = detail.CatagoryId,
                TimeAllotted = detail.TimeAllotted
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, ThingEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.ThingId != id)
            {
                ModelState.AddModelError("", "Thing ID Missmatch");
                return(View(model));
            }
            var service = CreateThingService();

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

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