public async Task CreateProjectionAndTestIfProjectionExists()
        {
            var projectionsService    = this.ProjectionServiceTest();
            var projectionsRepository = this.RepositoryForTest();

            var projectionInput = new ProjectionInputModel
            {
                CinemaId  = 1,
                StartTime = new DateTime(2020, 05, 12, 15, 30, 00),
                MovieId   = 5,
                HallId    = 10,
                Type      = ProjectionType._2D,
            };

            var firstIdToCkeck = await projectionsService.
                                 CreateAsync(1, new DateTime(2020, 05, 12, 15, 30, 00), 5, 10, ProjectionType._2D);

            var secondIdToCkeck = await projectionsService.
                                  CreateAsync(1, new DateTime(2020, 05, 13, 15, 30, 00), 3, 11, ProjectionType._4DX);

            var thirdIdToCkeck = await projectionsService.
                                 CreateAsync(1, new DateTime(2020, 05, 16, 15, 30, 00), 8, 12, ProjectionType._4DX);

            Assert.True(projectionsService.ProjectionExists(firstIdToCkeck));
            Assert.True(projectionsService.ProjectionExists(secondIdToCkeck));
            Assert.True(projectionsService.ProjectionExists(thirdIdToCkeck));
        }
Exemplo n.º 2
0
        public async Task UpdateProjection(ProjectionInputModel projection)
        {
            var projectionToUpdate = AutoMapperConfig.MapperInstance.Map <Projection>(projection);

            this.projectionRepository.Update(projectionToUpdate);
            await this.movieRepository.SaveChangesAsync();
        }
        public async Task <IActionResult> Add(ProjectionInputModel input)
        {
            var user = await userManager.GetUserAsync(User);

            var cinema = user?.Cinema;

            if (cinema == null)
            {
                return(this.RedirectToAction("Index", "Projections"));
            }

            var film = filmDataBusiness.GetByName(input.FilmTitle);

            if (film?.FilmId == null)
            {
                ModelState.AddModelError("Found", "Film not found!");
            }

            if (input.Date < DateTime.UtcNow)
            {
                ModelState.AddModelError("Date", "Projection can start at least one hour from now!");
            }

            if (!ModelState.IsValid)
            {
                var allFilmsTitles = filmDataBusiness.GetAllFilmsTitles();
                input.AvailableFilms = new SelectList(allFilmsTitles, "Key", "Value");
                return(this.View(input));
            }

            var projection = mapper.MapToFilmProjection(input, film, cinema);
            await filmProjectionBusiness.AddAsync(projection);

            return(this.RedirectToAction("Detail", "Projections", new { projection.Id }));
        }
        public async Task <IActionResult> Add()
        {
            var user = await userManager.GetUserAsync(User);

            var cinema = user?.Cinema;

            if (cinema != null)
            {
                var model          = new ProjectionInputModel();
                var allFilmsTitles = filmDataBusiness.GetAllFilmsTitles();
                model.AvailableFilms = new SelectList(allFilmsTitles, "Key", "Value");
                model.Date           = DateTime.UtcNow.Date;
                return(this.View(model));
            }
            return(this.RedirectToAction("Index", "Projections"));
        }
Exemplo n.º 5
0
 ///<summary>
 /// Creates FilmProjection object
 ///</summary>
 ///<param name="input">Projection data to map from</param>
 ///<param name="film"> Film object to map from</param>
 ///<param name="cinema"> Cinema object to map from</param>
 ///<returns>Mapped instance of type <see cref="FilmProjection"/></returns>
 public FilmProjection MapToFilmProjection(ProjectionInputModel input, FilmData film, Cinema cinema)
 {
     return(new FilmProjection
     {
         CinemaId = cinema.Id,
         Date = input.Date,
         FilmId = film.FilmId,
         ProjectionType = input.ProjectionType,
         TotalTickets = input.TotalTickets,
         TicketPrices = new TicketPrices
         {
             AdultPrice = input.AdultsTicketPrice,
             StudentPrice = input.StudentsTicketPrice,
             ChildrenPrice = input.ChildrenTicketPrice
         }
     });
 }
        public async Task <IActionResult> Update(string id, ProjectionInputModel input)
        {
            var user = await userManager.GetUserAsync(User);

            var cinema     = user?.Cinema;
            var projection = await filmProjectionBusiness.GetAsync(id);

            if (cinema == null ||
                projection == null ||
                projection?.CinemaId != cinema.Id ||
                projection?.Date < DateTime.UtcNow)
            {
                return(this.RedirectToAction("Index", "Projections"));
            }

            var film = filmDataBusiness.GetByName(input.FilmTitle);

            if (film?.FilmId == null)
            {
                ModelState.AddModelError("Found", "Film not found!");
            }

            if (input.Date < DateTime.UtcNow)
            {
                ModelState.AddModelError("Date", "Projection can start at least one hour from now!");
            }

            if (!ModelState.IsValid)
            {
                var allFilmsTitles = filmDataBusiness.GetAllFilmsTitles();
                input.AvailableFilms = new SelectList(allFilmsTitles, "Key", "Value");
                return(this.View(input));
            }

            var projectionUrlPattern = Url.ActionLink("Index", "Projections");
            var ticketUrlPattern     = Url.ActionLink("Index", "Tickets");
            var updatedProjection    = mapper.MapToFilmProjection(input, film, cinema);

            updatedProjection.Id = id;
            await filmProjectionBusiness.UpdateAsync(updatedProjection, projectionUrlPattern, ticketUrlPattern);

            return(this.RedirectToAction("Detail", "Projections", new { projection.Id }));
        }