Ejemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            var service = CreateStatService();
            var detail  = service.GetStatById(id);
            var model   =
                new StatEdit
            {
                StatId      = detail.StatId,
                Weight      = detail.Weight,
                WeightDate  = detail.WeightDate,
                GoalMessage = detail.GoalMessage
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public bool UpdateStat(StatEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Stats
                    .Single(e => e.StatId == model.StatId);

                entity.Weight      = (int)model.Weight;
                entity.WeightDate  = DateTimeOffset.Now;
                entity.GoalMessage = model.GoalMessage;


                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, StatEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.StatId != id)
            {
                ModelState.AddModelError("", "Id Doesn't Match");
                return(View(model));
            }

            var service = CreateStatService();

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

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