示例#1
0
        public async Task <IEnumerable <ProjectionDomainModel> > GetAllAsyncForSpecificMovie(Guid id)
        {
            var data = await _projectionsRepository.GetAllFromOneMovie(id);

            List <ProjectionDomainModel> result = new List <ProjectionDomainModel>();

            if (data == null)
            {
                return(null);
            }

            ProjectionDomainModel model;

            foreach (var item in data)
            {
                model = new ProjectionDomainModel
                {
                    Id                   = item.Id,
                    MovieId              = item.MovieId,
                    AuditoriumId         = item.AuditoriumId,
                    ProjectionTimeString = item.DateTime.ToString("hh:mm tt"),
                    MovieTitle           = item.Movie.Title,
                    AuditoriumName       = item.Auditorium.Name
                };
                List <Seat> listaSeat = new List <Seat>();
                var         seatsForThisAuditorium = await _seatsRepository.GetAllOfSpecificAuditoriumForProjection(model.AuditoriumId);

                var row        = 0;
                var seatPerRow = 0;
                foreach (var seatInAuditorium in seatsForThisAuditorium)
                {
                    listaSeat.Add(seatInAuditorium);
                }
                foreach (var seat in listaSeat)
                {
                    row        = seat.Row;
                    seatPerRow = seat.Number;
                }
                model.NumOFRows        = row;
                model.NumOFSeatsPerRow = seatPerRow;
                result.Add(model);
            }

            return(result);
        }
示例#2
0
        public async Task <CreateMovieResultModel> UpdateMovie(MovieDomainModel updateMovie)
        {
            var item = await _moviesRepository.GetByIdAsync(updateMovie.Id);

            var projections = await _projectionsRepository.GetAllFromOneMovie(updateMovie.Id);

            if (projections != null)
            {
                if (item.Current.Equals(true) && updateMovie.Current.Equals(false))
                {
                    List <Projection> checkProjection = projections.ToList();

                    var dateTimeNow = DateTime.Now;
                    foreach (var projection in checkProjection)
                    {
                        if (projection.DateTime > dateTimeNow)
                        {
                            return(new CreateMovieResultModel
                            {
                                IsSuccessful = false,
                                ErrorMessage = Messages.MOVIE_CURRENT_TO_NOT_CURRENT_UPDATE_ERROR
                            });
                        }
                    }
                }
            }
            Movie movie = new Movie()
            {
                Id      = updateMovie.Id,
                Title   = updateMovie.Title,
                Current = updateMovie.Current,
                Year    = updateMovie.Year,
                Rating  = updateMovie.Rating
            };

            var data = _moviesRepository.Update(movie);

            if (data == null)
            {
                return(new CreateMovieResultModel
                {
                    IsSuccessful = false,
                    ErrorMessage = Messages.MOVIE_CURRENT_UPDATE_ERROR
                });
            }
            _moviesRepository.Save();

            CreateMovieResultModel createMovieResultModel = new CreateMovieResultModel
            {
                ErrorMessage = null,
                IsSuccessful = true,
                Movie        = new MovieDomainModel()
                {
                    Id      = data.Id,
                    Title   = data.Title,
                    Current = data.Current,
                    Year    = data.Year,
                    Rating  = data.Rating ?? 0
                },
            };

            return(createMovieResultModel);
        }