public async Task <MovieResultModel> DeactivateMovie(Guid id) { var movie = await _moviesRepository.GetByIdAsync(id); if (movie == null) { return(new MovieResultModel { IsSuccessful = false, ErrorMessage = Messages.MOVIE_DOES_NOT_EXIST }); } var projections = await _projectionRepository.GetAll(); var futureProjections = projections.Where(p => p.MovieId == id && p.DateTime > DateTime.Now); if (futureProjections.Count() > 0) { return(new MovieResultModel { IsSuccessful = false, ErrorMessage = Messages.MOVIE_DEACTIVATION_ERROR, }); } var deactivatedMovie = await _moviesRepository.DeactivateCurrentMovie(movie.Id); _moviesRepository.Save(); MovieResultModel movieResultModel = new MovieResultModel { Movie = new MovieDomainModel { Id = movie.Id, Current = deactivatedMovie.Current, Rating = movie.Rating ?? 0, Title = movie.Title, Year = movie.Year, HasOscar = movie.HasOscar }, IsSuccessful = true, ErrorMessage = null }; return(movieResultModel); }
public async Task <IEnumerable <ProjectionDomainModel> > GetAllAsync() { var data = await _projectionsRepository.GetAll(); if (data == null) { return(null); } List <ProjectionDomainModel> result = new List <ProjectionDomainModel>(); ProjectionDomainModel model; foreach (var item in data) { model = new ProjectionDomainModel { Id = item.Id, MovieId = item.MovieId, AuditoriumId = item.AuditoriumId, ProjectionTime = item.DateTime, MovieTitle = item.Movie.Title, AuditoriumName = item.Auditorium.Name }; result.Add(model); } return(result); }
//Projection filter by: Auditorium, Cinema, Movie, TimeSpan public async Task <IEnumerable <ProjectionDomainModel> > GetAllAsync(ProjectionQuery query) { var data = await _projectionsRepository.GetAll(); if (query.AuditoriumId > 0) { data = data.Where(x => x.AuditoriumId == query.AuditoriumId); } if (query.CinemaId > 0) { data = data.Where(x => x.Auditorium.Cinema.Id == query.CinemaId); } if (query.MovieId != Guid.Empty) { data = data.Where(x => x.MovieId == query.MovieId); } if (query.DateLaterThan.HasValue) { data = data.Where(x => x.DateTime > query.DateLaterThan); } if (query.DateEarlierThan.HasValue) { data = data.Where(x => x.DateTime < query.DateEarlierThan); } List <ProjectionDomainModel> result = new List <ProjectionDomainModel>(); ProjectionDomainModel model; foreach (var item in data) { model = new ProjectionDomainModel { Id = item.Id, MovieId = item.MovieId, AuditoriumId = item.AuditoriumId, ProjectionTime = item.DateTime, MovieTitle = item.Movie.Title, AuditoriumName = item.Auditorium.AuditName }; result.Add(model); } return(result); }