// GET: Theaters/Create
        public ActionResult Create()
        {
            var model = new TheaterViewModel();

            model.Action = "Create";
            return(View(model));
        }
Exemple #2
0
        public ActionResult UpdateTheater([FromBody] TheaterViewModel model)
        {
            Theater theater = dbHandler.Theaters.Include(x => x.Seats).FirstOrDefault(x => x.Id.ToString() == model.Id);

            if (theater is null)
            {
                return(BadRequest());
            }

            theater.Number      = (theater.Number != model.Number && model.Number != 0) ? model.Number : theater.Number;
            theater.RowNumbers  = (theater.RowNumbers != model.RowNumbers && model.RowNumbers != 0) ? model.RowNumbers : theater.RowNumbers;
            theater.SeatNumbers = (theater.SeatNumbers != model.SeatNumbers && model.SeatNumbers != 0) ? model.SeatNumbers : theater.SeatNumbers;
            theater.Capacity    = (theater.Capacity != model.Capacity && model.Capacity != 0) ? model.Capacity : theater.Capacity;

            try
            {
                dbHandler.Theaters.Update(theater);
                if ((model.RowNumbers != 0 && model.RowNumbers != theater.RowNumbers) || (model.SeatNumbers != 0 && model.SeatNumbers != theater.SeatNumbers))
                {
                    List <Seat> seats = dbHandler.Seats.Include(x => x.Theater).Where(x => x.Theater.Id == theater.Id).ToList();
                    dbHandler.Seats.RemoveRange(seats);
                    theater.Seats.Clear();
                    theater.Seats = model.Seats;
                }
                dbHandler.SaveChanges();
            } catch (Exception)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Exemple #3
0
        public async Task <ActionResult> Index(
            [FromServices] IGetAllTheatersService service)
        {
            IEnumerable <TheaterDto> theaters = await service.GetAllTheaters();

            return(View(TheaterViewModel.TranslateRange(theaters)));
        }
        public async Task <IActionResult> Update([FromBody] TheaterViewModel updatedTheater)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var theater = await TheaterAppService.GetAsync(updatedTheater.Id);

                    theater.Name       = updatedTheater.Name;
                    theater.CNPJ       = updatedTheater.CNPJ;
                    theater.Street     = updatedTheater.Street;
                    theater.Number     = updatedTheater.Number;
                    theater.Complement = updatedTheater.Complement;
                    theater.PostalCode = updatedTheater.PostalCode;
                    theater.Priority   = updatedTheater.Priority;
                    theater.Enabled    = updatedTheater.Enabled;
                    theater.CityId     = updatedTheater.CityId;
                    await TheaterAppService.UpdateAsync(theater);

                    return(Ok());
                }
                catch (Exception ex)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
                }
            }

            return(BadRequest(ModelState));
        }
Exemple #5
0
        public ActionResult GetPreferredTheaters(String username)
        {
            TheaterViewModel theaterViewModel = new TheaterViewModel();

            theaterViewModel.customer = new Customer(username);
            theaterViewModel.GetPreferredTheaters();
            return(null);// View("")
        }
Exemple #6
0
        public IActionResult PreferredTheater(String username)
        {
            TheaterViewModel theaters = new TheaterViewModel();

            theaters.userName = username;
            theaters.GetPreferredTheaters();
            return(View("~/Views/MyAccount/PreferredTheater.cshtml", theaters));
        }
Exemple #7
0
        public ActionResult SearchForTheaters(String userName, String movieName, String errorText)//The asterisk in String* allows errorText to be null
        {
            TheaterViewModel theaterViewModel = new TheaterViewModel();

            theaterViewModel.customer = new Customer();
            theaterViewModel.userName = userName;
            theaterViewModel.GetPreferredTheaters();
            theaterViewModel.movieName = movieName;
            return(View("~/Views/Theater/SearchForTheaters.cshtml", theaterViewModel));
        }
Exemple #8
0
        public ActionResult DisplaySearchedTheaters(String searchName, String userName, String movieName)
        {
            TheaterViewModel theaterViewModel = new TheaterViewModel();

            theaterViewModel.customer  = new Customer();
            theaterViewModel.userName  = userName;
            theaterViewModel.movieName = movieName;

            theaterViewModel.foundTheaters = Theater.SearchTheaters(searchName);
            if (theaterViewModel.foundTheaters.Count == 0)//no theaters found
            {
                return(RedirectToAction("SearchForTheaters", "Theater", new { userName = userName, movieName = movieName, errorText = "No results found." }));
            }
            return(View("~/Views/Theater/DisplaySearchedTheaters.cshtml", theaterViewModel));
        }
        public async Task <ActionResult> Create([Bind(Include = "TheaterID,Name,Address,Latitude,Longitude")] TheaterViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var theater = new Theater();
                theater.Name      = viewModel.Name;
                theater.Address   = viewModel.Address;
                theater.Latitude  = viewModel.Latitude;
                theater.Longitude = viewModel.Longitude;

                db.Theaters.Add(theater);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
        public async Task <ActionResult> Edit([Bind(Include = "TheaterID,Name,Address,Latitude,Longitude")] TheaterViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var theater = new Theater();
                theater.TheaterID = viewModel.TheaterID;
                theater.Name      = viewModel.Name;
                theater.Address   = viewModel.Address;
                theater.Latitude  = viewModel.Latitude;
                theater.Longitude = viewModel.Longitude;

                db.Entry(theater).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View("Create", viewModel));
        }
Exemple #11
0
        public ActionResult CreateTheater([FromBody] TheaterViewModel model)
        {
            Theater theater = new Theater
            {
                Number      = model.Number,
                Capacity    = model.Capacity,
                Seats       = model.Seats,
                RowNumbers  = model.RowNumbers,
                SeatNumbers = model.SeatNumbers
            };

            try
            {
                dbHandler.Theaters.Add(theater);
                dbHandler.SaveChanges();
            } catch (Exception)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Exemple #12
0
        public static void Add(TheaterViewModel model)
        {
            using (ApplicationDbContext _context = new ApplicationDbContext())
            {
                var theater = new Theater()
                {
                    TheaterName = model.Name,
                    ZipCode     = model.Location
                };

                _context.Theaters.Add(theater);

                try
                {
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
        // GET: Theaters/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Theater theater = await db.Theaters.FindAsync(id);

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

            TheaterViewModel viewModel = new TheaterViewModel();

            viewModel.Action    = "Update";
            viewModel.TheaterID = theater.TheaterID;
            viewModel.Name      = theater.Name;
            viewModel.Address   = theater.Address;
            viewModel.Latitude  = theater.Latitude;
            viewModel.Longitude = theater.Longitude;

            return(View("Create", viewModel));
        }
        public ActionResult Create(TheaterViewModel model)
        {
            TheaterManager.Add(model);

            return(RedirectToAction("Index"));
        }
Exemple #15
0
        public IEnumerable <MovieTheaterViewModel> GetMoviesByLocation(double latitude, double longitude, string genres)
        {
            //todo: receber tolerancia como parametro, mas default 1

            //get theaters
            var theaters = db.Theaters.Where(t =>
                                             (t.Latitude >= latitude - 1 && t.Latitude <= latitude + 1) &&
                                             (t.Longitude >= longitude - 1 && t.Longitude <= longitude + 1)
                                             );

            //haversine

            //get genres
            List <Genre> selectedGenres = new List <Genre>();
            var          listGenres     = genres.Split(new char[] { ',' });

            foreach (var s in listGenres)
            {
                Genre genre   = new Genre();
                int   genreId = 0;
                if (Int32.TryParse(s, out genreId))
                {
                    genre = db.Genres.Find(genreId);
                }
                else
                {
                    genre = db.Genres.FirstOrDefault(g => g.Name == s);
                }

                if (genre != null)
                {
                    selectedGenres.Add(genre);
                }
            }

            //match
            List <MovieTheaterViewModel> movies = new List <MovieTheaterViewModel>();

            foreach (var theater in theaters)
            {
                foreach (var s in theater.ShowTimes)
                {
                    if (s.Movie.Genres.Count(g => selectedGenres.Count(gg => gg.GenreId == g.GenreId) > 0) > 0)
                    {
                        MovieTheaterViewModel movie = new MovieTheaterViewModel();

                        TheaterViewModel theaterModel = new TheaterViewModel();
                        theaterModel.TheaterId = theater.TheaterId;
                        theaterModel.Name      = theater.Name;

                        if (movies.Count(m => m.MovieId == s.Movie.MovieId) == 0)
                        {
                            movie.MovieId    = s.Movie.MovieId;
                            movie.MovieTitle = s.Movie.Title;
                            movie.MovieGenre = s.Movie.Genres.First().Name;
                            movie.Theaters   = new List <TheaterViewModel>();
                            movie.Theaters.Add(theaterModel);
                            movies.Add(movie);
                        }
                        else
                        {
                            movie = movies.FirstOrDefault(m => m.MovieId == s.Movie.MovieId);
                            movie.Theaters.Add(theaterModel);
                        }
                    }
                }
            }

            return(movies.AsEnumerable());
        }