示例#1
0
        public async Task <ActionResult <ShowingDto> > Edit(int showingId, [FromBody] EditShowingDto showing)
        {
            if (await _showingsService.GetById(showingId) == null)
            {
                return(NotFound("Showing not found"));
            }
            var result = await _showingsService.EditShowing(showingId, showing);

            if (result == null)
            {
                return(NotFound(new ErrorMessage("Hall or Movie not found")));
            }
            return(Ok(result));
        }
        public async Task <ShowingDto> EditShowing(int showingId, EditShowingDto showing)
        {
            var editedShowing = await _showingsRepository.GetById(showingId);

            if (editedShowing == null)
            {
                return(null);
            }
            if (showing.HallId != null)
            {
                var hall = await _halesRepository.GetById((int)showing.HallId);

                if (hall == null)
                {
                    return(null);
                }
                else
                {
                    editedShowing.ShowingHall = hall;
                }
            }

            if (showing.MovieId != null)
            {
                var movie = await _moviesRepository.GetById((int)showing.MovieId);

                if (movie == null)
                {
                    return(null);
                }
                else
                {
                    editedShowing.ShowingMovie = movie;
                }
            }

            if (showing.Date != null)
            {
                editedShowing.ShowingDate = showing.Date;
            }

            return(new ShowingDto(await _showingsRepository.Edit(editedShowing)));
        }