public async Task AddAsync(AddProjectionInputModel inputModel) { var projectionSeats = new List <ProjectionSeat>(); var projection = new Projection { Id = Guid.NewGuid().ToString(), HallId = inputModel.HallId, MovieId = inputModel.MovieId, ProjectionDateTime = inputModel.ProjectionDateTime.ToUniversalTime(), Seats = projectionSeats, }; var seats = this.seatsRepository .All() .Where(s => s.HallId == inputModel.HallId) .ToList(); foreach (var seat in seats) { var projectionSeat = new ProjectionSeat { Id = Guid.NewGuid().ToString(), SeatId = seat.Id, ProjectionId = projection.Id, }; projectionSeats.Add(projectionSeat); } await this.projectionsRepository.AddAsync(projection); await this.projectionsRepository.SaveChangesAsync(); }
public async Task EditeProjectionShouldWorkCorrectly() { var context = new ApplicationDbContext(this.options.Options); var repository = new EfDeletableEntityRepository <Projection>(context); var service = this.GetProjectionsService(repository, context); await service.AddAsync(this.projection); var id = repository.All().Select(p => p.Id).FirstOrDefault(); var diffProjection = new AddProjectionInputModel { Id = id, HallId = 2, MovieId = 3, ProjectionDateTime = new DateTime(2020, 05, 10), }; await service.EditAsync(diffProjection); var dbProjection = await repository.GetByIdWithDeletedAsync(id); Assert.Equal(2, dbProjection.HallId); Assert.Equal(3, dbProjection.MovieId); }
public async Task <IActionResult> Add(AddProjectionInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.projectionsService.AddAsync(inputModel); return(this.Redirect("/")); }
public ProjectionsServiceTests() { this.projection = new AddProjectionInputModel { HallId = 1, MovieId = 1, ProjectionDateTime = new DateTime(2008, 4, 10), }; AutoMapperConfig.RegisterMappings(typeof(TestProjectionViewModel).Assembly); this.options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); }
public IActionResult Add() { var movies = this.moviesService.GetAll <MovieDropDownViewModel>(null); var halls = this.hallsService.GetAll <HallDropDownViewModel>(); var viewModel = new AddProjectionInputModel { HallId = 1, Movies = movies, Halls = halls, ProjectionDateTime = new DateTime(DateTime.Now.Ticks / 600000000 * 600000000), }; return(this.View(viewModel)); }
public async Task EditAsync(AddProjectionInputModel inputModel) { var projection = await this.projectionsRepository.GetByIdWithDeletedAsync(inputModel.Id); if (projection == null) { throw new ArgumentNullException(InvalidIdExceptionMessage); } if (projection.HallId != inputModel.HallId) { var oldSeats = this.projectionsSeatsRepo.All().Where(s => s.ProjectionId == inputModel.Id).ToList(); foreach (var oldSeat in oldSeats) { this.projectionsSeatsRepo.HardDelete(oldSeat); } await this.projectionsSeatsRepo.SaveChangesAsync(); var projectionSeats = new List <ProjectionSeat>(); var seats = this.seatsRepository .All() .Where(s => s.HallId == inputModel.HallId) .ToList(); foreach (var seat in seats) { var projectionSeat = new ProjectionSeat { Id = Guid.NewGuid().ToString(), SeatId = seat.Id, ProjectionId = projection.Id, }; projectionSeats.Add(projectionSeat); } projection.Seats = projectionSeats; } projection.HallId = inputModel.HallId; projection.MovieId = inputModel.MovieId; projection.ProjectionDateTime = inputModel.ProjectionDateTime.ToUniversalTime(); this.projectionsRepository.Update(projection); await this.projectionsRepository.SaveChangesAsync(); }
public void EditProjectionShouldThrowIfInvalidId() { var context = new ApplicationDbContext(this.options.Options); var repository = new EfDeletableEntityRepository <Projection>(context); var service = this.GetProjectionsService(repository, context); var diffProjection = new AddProjectionInputModel { Id = "Invalid", HallId = 2, MovieId = 3, ProjectionDateTime = new DateTime(2020, 05, 10), }; Assert.Throws <ArgumentNullException>(() => service.EditAsync(diffProjection).GetAwaiter().GetResult()); }
public async Task GetByIdShouldWorkCorrectly() { var context = new ApplicationDbContext(this.options.Options); var repository = new EfDeletableEntityRepository <Projection>(context); var service = this.GetProjectionsService(repository, context); var diffProjection = new AddProjectionInputModel { HallId = 2, MovieId = 3, ProjectionDateTime = new DateTime(2020, 05, 10), }; await service.AddAsync(diffProjection); await service.AddAsync(this.projection); var result = service.GetById <TestProjectionViewModel>(3); var dbProjection = result.FirstOrDefault(); Assert.Equal(2, dbProjection.HallId); }
public async Task <IActionResult> EditProjection(AddProjectionInputModel inputModel) { await this.projectionsService.EditAsync(inputModel); return(this.RedirectToAction("Manage")); }