Beispiel #1
0
        public IHttpActionResult Put(ThemeParkRatingEdit rating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = GetRatingService();

            if (!service.EditThemeParkRating(rating))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool EditThemeParkRating(ThemeParkRatingEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Ratings.Single(r => r.ThemeParkRatingID == model.ThemeParkRatingID);
                entity.GoodnessLevel = model.GoodnessLevel;
                entity.ThemeParkID   = model.ThemeParkID;

                ctx.Ratings.Add(entity);
                if (ctx.SaveChanges() == 1)
                {
                    CalculateGoodness(model.ThemeParkID);
                    return(true);
                }
                return(false);
            }
        }
Beispiel #3
0
        // GET: ThemeParkRating/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = GetRatingService();
            var detail  = service.GetRatingByID(id);
            var model   = new ThemeParkRatingEdit
            {
                ThemeParkRatingID = detail.ThemeParkRatingID,
                ThemeParkID       = detail.ThemeParkID,
                GoodnessLevel     = detail.GoodnessLevel,
            };

            var parkService = new ThemeParkService();
            var parkList    = parkService.GetThemeParks();

            ViewBag.ThemeParkID = new SelectList(parkList, "ThemeParkID", "ThemeParkName", model.ThemeParkID);

            return(View(model));
        }
Beispiel #4
0
        public ActionResult Edit(ThemeParkRatingEdit model)
        {
            var parkService = new ThemeParkService();
            var parkList    = parkService.GetThemeParks();

            ViewBag.ThemeParkID = new SelectList(parkList, "ThemeParkID", "ThemeParkName", model.ThemeParkID);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = GetRatingService();

            if (service.EditThemeParkRating(model))
            {
                return(RedirectToAction("Index", "ThemePark"));
            }

            ModelState.AddModelError("", "Could not update rating");
            return(View(model));
        }