Example #1
0
        public ActionResult Edit(int id, RatingsEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

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

            var service = CreateRatingsService();

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

            ModelState.AddModelError("", "Your rating could not be updated.");

            return(View(model));
        }
Example #2
0
        public ActionResult Edit(int id)
        {
            var service = CreateRatingsService();
            var detail  = service.GetRatingById(id);
            var model   =
                new RatingsEdit
            {
                Id             = detail.Id,
                ExertionScore  = detail.ExertionScore,
                EnjoymentScore = detail.EnjoymentScore,
                HeartrateScore = detail.HeartrateScore
            };

            return(View(model));
        }
Example #3
0
        public bool UpdateRating(RatingsEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Ratings
                    .Single(e => e.Id == model.Id && e.UserId == _userId);

                entity.Id             = model.Id;
                entity.ExertionScore  = model.ExertionScore;
                entity.EnjoymentScore = model.EnjoymentScore;
                entity.HeartrateScore = model.HeartrateScore;

                return(ctx.SaveChanges() == 1);
            }
        }