Exemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(Models.Show model)
        {
            if (ModelState.IsValid)
            {
                if (!(showService.ExistsShow(model.CinemaCity) && showService.ExistsShow(model.FilmName) && showService.ExistsShow(model.ShowTimeFilm)))
                {
                    var dbModel = new Domain.Show();
                    dbModel.InjectFrom(model);
                    showService.AddShow(dbModel);
                    TempData["message"] = string.Format("{0} has been saved", model.FilmName);
                }
                else
                {
                    ModelState.AddModelError("Show", "Cannot have two identical shows!");

                    //Cinema
                    var cinemas    = cinemaRepository.GetAll();
                    var cinemaList = cinemas.Select(c => new SelectListItem()
                    {
                        Value = c.Id.ToString(),
                        Text  = c.CinemaCity
                    }).ToList();
                    //Film
                    var films    = filmRepository.GetAll();
                    var filmList = films.Select(f => new SelectListItem()
                    {
                        Value = f.Id.ToString(),
                        Text  = f.Name
                    }).ToList();
                    //ShowTimeFilm
                    var showtimefilms    = showtimefilmRepository.GetAll();
                    var showtimefilmList = showtimefilms.Select(s => new SelectListItem()
                    {
                        Value = s.Id.ToString(),
                        Text  = s.ShowTime.ToString("dd/MM/yyyy hh:mm")
                    }).ToList();

                    ViewBag.Cinemas       = cinemaList;
                    ViewBag.Films         = filmList;
                    ViewBag.ShowTimeFilms = showtimefilmList;

                    return(View(model));
                }

                //showRepository.Add(dbModel);

                //transform the object
                //unitOfWork.Commit();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult Edit(Models.Show show)
        {
            if (ModelState.IsValid)
            {
                var showEdit = new Domain.Show();
                showEdit.InjectFrom(show);
                showRepository.Update(showEdit);
                TempData["message"] = string.Format("{0} has been saved", show.FilmName);
                unitOfWork.Commit();
            }

            else
            {
                return(View(show));
            }

            return(RedirectToAction("Index"));
        }