public async Task <CreateProjectionResultModel> CreateProjection(ProjectionDomainModel domainModel) { int projectionTime = 3; var projectionsAtSameTime = _projectionsRepository.GetByAuditoriumId(domainModel.AuditoriumId) .Where(x => x.DateTime <domainModel.ProjectionTime.AddHours(projectionTime) && x.DateTime> domainModel.ProjectionTime.AddHours(-projectionTime)) .ToList(); if (projectionsAtSameTime != null && projectionsAtSameTime.Count > 0) { return(new CreateProjectionResultModel { IsSuccessful = false, ErrorMessage = Messages.PROJECTIONS_AT_SAME_TIME }); } var newProjection = new Data.Projection { MovieId = domainModel.MovieId, AuditoriumId = domainModel.AuditoriumId, DateTime = domainModel.ProjectionTime }; var insertedProjection = _projectionsRepository.Insert(newProjection); if (insertedProjection == null) { return(new CreateProjectionResultModel { IsSuccessful = false, ErrorMessage = Messages.PROJECTION_CREATION_ERROR }); } _projectionsRepository.Save(); var projekcija = await _projectionsRepository.GetByIdAsync(insertedProjection.Id); CreateProjectionResultModel result = new CreateProjectionResultModel { IsSuccessful = true, ErrorMessage = null, Projection = new ProjectionDomainModel { Id = insertedProjection.Id, AuditoriumId = insertedProjection.AuditoriumId, MovieId = insertedProjection.MovieId, ProjectionTime = insertedProjection.DateTime, AuditoriumName = projekcija.Auditorium.AuditName, MovieTitle = projekcija.Movie.Title } }; return(result); }