Example #1
0
        public async Task <ActionResult <ShowingDto> > AddAsync([FromBody] AddShowingDto showing)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ErrorMessage("Provide correct values")));
            }
            var result = await _showingsService.AddShowing(showing);

            if (result == null)
            {
                return(NotFound(new ErrorMessage("Hall or Movie not found")));
            }
            return(Ok(result));
        }
        public async Task <ShowingDto> AddShowing(AddShowingDto showing)
        {
            var movie = await _moviesRepository.GetById(showing.MovieId);

            var hall = await _halesRepository.GetById(showing.HallId);

            if (movie == null || hall == null)
            {
                return(null);
            }
            var newShowing = new Showing {
                ShowingDate  = showing.Date,
                ShowingMovie = movie,
                ShowingHall  = hall
            };
            var result = await _showingsRepository.Add(newShowing);

            return(new ShowingDto(result));
        }