Exemple #1
0
        // GET: ShowEpisodes/Delete/5
        public ActionResult Delete(int?id, string name)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var dbShowEpisode = db.GetShowEpisode(id.Value);

            if (dbShowEpisode == null)
            {
                return(HttpNotFound());
            }

            var showEpisode = new ShowEpisodeViewModel
            {
                Id      = dbShowEpisode.Id,
                ShowId  = dbShowEpisode.ShowId,
                UserId  = dbShowEpisode.UserId,
                Season  = dbShowEpisode.Season,
                Episode = dbShowEpisode.Episode
            };

            ViewBag.Name = name;

            return(View(showEpisode));
        }
Exemple #2
0
        public ActionResult Create([Bind(Include = "Id,UserId,ShowId,Season,Episode")] ShowEpisodeViewModel showEpisode)
        {
            if (ModelState.IsValid && isQuantityValid(showEpisode))
            {
                Mapper.Initialize(cfg => cfg.CreateMap <ShowEpisodeViewModel, ShowEpisodeDTO>());
                db.Create(Mapper.Map <ShowEpisodeDTO>(showEpisode));
                return(RedirectToAction("Index"));
            }

            ViewBag.ErrorMessage = "Введены неверные значения";
            return(View(showEpisode));
        }
Exemple #3
0
        private bool isQuantityValid(ShowEpisodeViewModel showEpisode)
        {
            var dbShow = db.GetShow(showEpisode.ShowId);

            if (showEpisode.Season < 1 || showEpisode.Season > dbShow.Seasons)
            {
                return(false);
            }

            if (showEpisode.Episode < 1 || showEpisode.Episode > dbShow.Episodes)
            {
                return(false);
            }

            return(true);
        }