public async Task AddAsync(AddHallInputModel inputModel) { var projectionType = Enum.Parse(typeof(ProjectionType), inputModel.ProjectionType); var seats = new List <Seat>(); var hall = new Hall { ProjectionType = (ProjectionType)projectionType, Seats = seats, }; for (int i = 0; i < inputModel.Seats; i++) { var seat = new Seat { HallId = hall.Id, }; seats.Add(seat); } await this.hallsRepository.AddAsync(hall); await this.hallsRepository.SaveChangesAsync(); }
public async Task <IActionResult> AddAsync(AddHallInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.hallsService.AddAsync(inputModel); return(this.Redirect("/")); }
public HallsServiceTests() { this.hall = new AddHallInputModel { ProjectionType = "TwoD", Seats = 50, }; AutoMapperConfig.RegisterMappings(typeof(TestHallViewModel).Assembly); this.options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); }
public async Task GetByIdShouldReturnCorrectData() { var repository = new EfDeletableEntityRepository <Hall>(new ApplicationDbContext(this.options.Options)); var service = new HallsService(repository); var diffHall = new AddHallInputModel { ProjectionType = "FourDx", Seats = 100, }; await service.AddAsync(this.hall); await service.AddAsync(diffHall); var result = service.GetById <TestHallViewModel>(2); Assert.Equal(ProjectionType.FourDx, result.ProjectionType); }