public async Task <IEnumerable <SeatDomainModel> > GetSeatsByAuditoriumId(int id) { var data = _seatsRepository.GetByAuditoriumId(id); if (data == null) { return(null); } List <SeatDomainModel> domainModelList = new List <SeatDomainModel>(); foreach (Seat seat in data) { SeatDomainModel domainModel = new SeatDomainModel { Id = seat.Id, AuditoriumId = seat.AuditoriumId, Number = seat.Number, Row = seat.Row }; domainModelList.Add(domainModel); } return(domainModelList); }
public async Task <IEnumerable <SeatDomainModel> > DeleteByAuditoriumId(int auditoriumId) { var seatModelsByAuditoriumId = _seatsRepository.GetByAuditoriumId(auditoriumId); if (seatModelsByAuditoriumId == null) { return(null); } seatModelsByAuditoriumId.ToList(); var data = await _seatsRepository.DeleteByAuditoriumId(auditoriumId); if (data == null) { return(null); } List <SeatDomainModel> domainModelList = new List <SeatDomainModel>(); foreach (Seat seat in data) { SeatDomainModel domainModel = new SeatDomainModel { Id = seat.Id, AuditoriumId = seat.AuditoriumId, Number = seat.Number, Row = seat.Row }; domainModelList.Add(domainModel); } return(domainModelList); }
public async Task <IEnumerable <SeatDomainModel> > GetAllAsync() { var data = await _seatsRepository.GetAll(); if (data == null) { return(null); } List <SeatDomainModel> result = new List <SeatDomainModel>(); SeatDomainModel model; foreach (var item in data) { model = new SeatDomainModel { Id = item.Id, AuditoriumId = item.AuditoriumId, Number = item.Number, Row = item.Row }; result.Add(model); } return(result); }
public async Task <SeatDomainModel> AddSeat(SeatDomainModel newSeat) { Seat seatToCreate = new Seat() { AuditoriumId = newSeat.AuditoriumId, Number = newSeat.Number, Row = newSeat.Row }; var data = _seatsRepository.Insert(seatToCreate); if (data == null) { return(null); } _seatsRepository.Save(); SeatDomainModel domainModel = new SeatDomainModel() { Id = data.Id, AuditoriumId = data.AuditoriumId, Number = data.Number, Row = data.Row }; return(domainModel); }
public async Task <SeatDomainModel> DeleteSeat(Guid seatId) { var reservationData = await _reservationService.DeleteBySeatId(seatId); if (reservationData == null) { return(null); } var data = _seatsRepository.Delete(seatId); if (data == null) { return(null); } _seatsRepository.Save(); SeatDomainModel domainModel = new SeatDomainModel { Id = data.Id, AuditoriumId = data.AuditoriumId, Number = data.Number, Row = data.Row }; return(domainModel); }
public async Task <SeatDomainModel> DeleteSeat(Guid id) { var existingSeats = await _seatsRepository.GetByIdAsync(id); if (existingSeats == null) { return(null); } _seatsRepository.Delete(id); _seatsRepository.Save(); if (existingSeats.Tickets != null) { return(null); } SeatDomainModel domainModel = new SeatDomainModel { AuditoriumId = existingSeats.AuditoriumId, Id = existingSeats.Id, Number = existingSeats.Number, Row = existingSeats.Row }; return(domainModel); }
public SeatDomainModel ReadById(object id) { if (id == null) { throw new ArgumentNullException("id"); } Seat seat = Uow.GetRepository <Seat>().ReadById(id); SeatDomainModel seatDomain = Mapper.Map <Seat, SeatDomainModel>(seat); return(seatDomain); }
public void Delete(SeatDomainModel entity) { if (entity == null) { throw new ArgumentNullException("entity"); } Seat seat = Mapper.Map <SeatDomainModel, Seat>(entity); Uow.GetRepository <Seat>().Delete(seat); Uow.Save(); }
public void TestInitialize() { _seat = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Row = 2, Number = 2 }; _seatDomainModel = new SeatDomainModel { Id = _seat.Id, AuditoriumId = 1, Row = 2, Number = 2 }; _reservationDomainModel = new ReservationDomainModel { ProjectionId = Guid.NewGuid(), SeatId = _seat.Id, UserId = Guid.NewGuid() }; _numberOfSeatsModel = new NumberOfSeatsModel { MaxNumber = 2, MaxRow = 2 }; List <Seat> seatsModelsList = new List <Seat>(); seatsModelsList.Add(_seat); IEnumerable <Seat> seats = seatsModelsList; Task <IEnumerable <Seat> > responseTask = Task.FromResult(seats); _mockSeatsRepository = new Mock <ISeatsRepository>(); List <ReservationDomainModel> reservationDomainModelsList = new List <ReservationDomainModel>(); reservationDomainModelsList.Add(_reservationDomainModel); IEnumerable <ReservationDomainModel> reservations = reservationDomainModelsList; Task <IEnumerable <ReservationDomainModel> > reservationResponseTask = Task.FromResult(reservations); _mockReservationService = new Mock <IReservationService>(); }
public async Task <SeatDomainModel> GetSeatByAuditoriumIdRowSeatnum(int auditoriumId, int rowNum, int seatNum) { var data = await _seatsRepository.GetByAuditoriumIdRowColumn(auditoriumId, rowNum, seatNum); if (data == null) { return(null); } SeatDomainModel domainModel = new SeatDomainModel() { AuditoriumId = data.AuditoriumId, Id = data.Id, Number = data.Number, Row = data.Row }; return(domainModel); }
public void SeatService_GetAllSeats_ReturnsListOfSeats() { //Arrange var expectedCount = 2; Seat seat2 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1 }; SeatDomainModel seatDomainModel2 = new SeatDomainModel { Id = seat2.Id, AuditoriumId = seat2.AuditoriumId, Number = seat2.Number, Row = seat2.Row }; List <Seat> seats = new List <Seat>(); seats.Add(_seat); seats.Add(seat2); List <SeatDomainModel> seatDomainModels = new List <SeatDomainModel>(); seatDomainModels.Add(_seatDomainModel); seatDomainModels.Add(seatDomainModel2); _mockSeatRepository.Setup(x => x.GetAll()).ReturnsAsync(seats); //Act var resultAction = _seatService.GetAllAsync().ConfigureAwait(false).GetAwaiter().GetResult(); var result = resultAction.ToList(); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(expectedCount, result.Count); Assert.AreEqual(_seat.Id, result[0].Id); Assert.AreEqual(seatDomainModel2.Id, result[1].Id); Assert.IsInstanceOfType(result[0], typeof(SeatDomainModel)); }
public ActionResult <IEnumerable <SeatDomainModel> > GetTakenSeats(Guid projectionId) { var takenSeats = _reservationService.GetTakenSeats(projectionId); List <SeatDomainModel> seatDomainList = new List <SeatDomainModel>(); foreach (var seat in takenSeats) { SeatDomainModel s = new SeatDomainModel { AuditoriumId = seat.SeatDomainModel.AuditoriumId, Id = seat.SeatDomainModel.Id, Number = seat.SeatDomainModel.Number, Row = seat.SeatDomainModel.Row }; seatDomainList.Add(s); } return(Ok(seatDomainList)); }
public void GetAll_Seats_By_Auditorium_Id() { //Arrange int expectedStatusCode = 200; int expectedRow = 3; int expectedNumber = 2; SeatDomainModel seatDomainModel = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 23, Number = 2, Row = 3 }; List <SeatDomainModel> seatDomainModels = new List <SeatDomainModel>(); seatDomainModels.Add(seatDomainModel); IEnumerable <SeatDomainModel> listOfSeatsIEn = seatDomainModels; Task <IEnumerable <SeatDomainModel> > responseTask = Task.FromResult(listOfSeatsIEn); _seatService = new Mock <ISeatService>(); _reservationService = new Mock <IReservationService>(); _seatService.Setup(x => x.GetAllSeatsByAuditoriumId(It.IsAny <int>())).Returns(responseTask); SeatsController seatsController = new SeatsController(_seatService.Object, _reservationService.Object); //Act var result = seatsController.GetAllSeatsByAuditoriumId(1).ConfigureAwait(false).GetAwaiter().GetResult().Result; var objectResult = ((OkObjectResult)result).Value; List <SeatDomainModel> seatsResult = (List <SeatDomainModel>)objectResult; //Assert Assert.IsNotNull(objectResult); Assert.AreEqual(expectedRow, seatsResult[0].Row); Assert.AreEqual(expectedNumber, seatsResult[0].Number); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void TestInitialize() { _seat = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 1 }; _seatDomainModel = new SeatDomainModel { Id = _seat.Id, AuditoriumId = _seat.AuditoriumId, Number = _seat.Number, Row = _seat.Row }; _mockSeatRepository = new Mock <ISeatsRepository>(); _seatService = new SeatService(_mockSeatRepository.Object); }
public async Task <IEnumerable <SeatDomainModel> > GetAllSeatsForProjection(Guid id) { var allSeatsForProjection = await _seatsRepository.GetAllOfSpecificProjection(id); var reservedSeatsForThisProjection = _ticketRepository.GetAllForSpecificProjection(id); if (allSeatsForProjection == null) { return(null); } List <SeatDomainModel> result = new List <SeatDomainModel>(); SeatDomainModel model; foreach (var seat in allSeatsForProjection) { model = new SeatDomainModel { AuditoriumId = seat.AuditoriumId, Id = seat.Id, Number = seat.Number, Row = seat.Row }; foreach (var reservedSeat in reservedSeatsForThisProjection) { if (seat.Id == reservedSeat.SeatId) { model.Reserved = true; } } result.Add(model); } return(result); }
public void GetAsync_Return_All_Seats() { //Arrange SeatDomainModel seatDomainModel = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 23, Number = 2, Row = 3 }; int expectedStatusCode = 200; int expectedResultCount = 1; List <SeatDomainModel> seatDomainModels = new List <SeatDomainModel>(); seatDomainModels.Add(seatDomainModel); IEnumerable <SeatDomainModel> seatsIEn = seatDomainModels; Task <IEnumerable <SeatDomainModel> > responseTask = Task.FromResult(seatsIEn); _seatService = new Mock <ISeatService>(); _reservationService = new Mock <IReservationService>(); _seatService.Setup(x => x.GetAllAsync()).Returns(responseTask); SeatsController seatsController = new SeatsController(_seatService.Object, _reservationService.Object); //Act var result = seatsController.GetAsync().ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; List <SeatDomainModel> seatDomainModelsResult = (List <SeatDomainModel>)resultList; //Assert Assert.IsNotNull(seatDomainModelsResult); Assert.AreEqual(expectedResultCount, seatDomainModelsResult.Count); Assert.AreEqual(seatDomainModel.Id, seatDomainModelsResult[0].Id); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public async Task <AuditoriumDomainModel> GetByIdAsync(int id) { var data = await _auditoriumsRepository.GetByIdAsync(id); if (data == null) { return(null); } List <SeatDomainModel> domainModelList = new List <SeatDomainModel>(); if (data.Seats != null) { foreach (Seat seat in data.Seats) { SeatDomainModel domainModel = new SeatDomainModel() { Id = seat.Id, AuditoriumId = seat.AuditoriumId, Number = seat.Number, Row = seat.Row }; domainModelList.Add(domainModel); } } AuditoriumDomainModel result = new AuditoriumDomainModel() { Id = data.Id, CinemaId = data.CinemaId, Name = data.Name, SeatsList = domainModelList }; return(result); }
public void TestIni() { _seatDomainModel = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 1 }; _numberOfSeats = new NumberOfSeatsModel { MaxNumber = 1, MaxRow = 1 }; List <SeatDomainModel> seatList = new List <SeatDomainModel>(); seatList.Add(_seatDomainModel); IEnumerable <SeatDomainModel> seats = seatList; Task <IEnumerable <SeatDomainModel> > responseTask = Task.FromResult(seats); _mockSeatService = new Mock <ISeatService>(); }
public void AuditoriumService_CreateAuditorium_ReturnsCreatedAuditoriumWithSeats() { //Arrange var expectedSeatCount = 3; int numOfRows = 2; int numOfSeats = 4; Seat s1 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 1 }; Seat s2 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1 }; Seat s3 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; SeatDomainModel s4 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; SeatDomainModel s5 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; SeatDomainModel s6 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 2 }; List <Auditorium> audits = new List <Auditorium>(); List <Seat> seats = new List <Seat>(); List <SeatDomainModel> seatsList = new List <SeatDomainModel>(); seats.Add(s1); seats.Add(s2); seats.Add(s3); seatsList.Add(s4); seatsList.Add(s5); seatsList.Add(s6); _auditorium.Seats = seats; _auditoriumDomainModel.SeatsList = seatsList; AuditoriumDomainModel ad2 = new AuditoriumDomainModel { Id = 22, CinemaId = 2, Name = "bla bla audit", SeatsList = seatsList }; CreateAuditoriumResultModel cr = new CreateAuditoriumResultModel { IsSuccessful = true, ErrorMessage = null, Auditorium = _auditoriumDomainModel }; _mockCinemaRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_cinema); _mockAuditoriumRepository.Setup(x => x.Insert(It.IsAny <Auditorium>())).Returns(_auditorium); _mockAuditoriumRepository.Setup(x => x.GetByAuditName(It.IsAny <string>(), It.IsAny <int>())).ReturnsAsync(audits); _mockAuditoriumRepository.Setup(x => x.Insert(It.IsAny <Auditorium>())).Returns(_auditorium); //Act var resultAction = _auditoriumService.CreateAuditorium(ad2, numOfRows, numOfSeats).ConfigureAwait(false).GetAwaiter().GetResult(); //Arrange Assert.IsNotNull(resultAction); Assert.AreEqual(resultAction.Auditorium.Id, cr.Auditorium.Id); Assert.IsInstanceOfType(resultAction, typeof(CreateAuditoriumResultModel)); Assert.AreEqual(expectedSeatCount, resultAction.Auditorium.SeatsList.Count); Assert.IsTrue(resultAction.IsSuccessful); Assert.IsNull(resultAction.ErrorMessage); }
public void ReservationService_CreateReservation_ReturnsErrorMessage_SeatNotExist() { //Arrange List <SeatDomainModel> seatDomainModels = new List <SeatDomainModel>(); SeatDomainModel seat1 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1 }; SeatDomainModel seat2 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 3, Row = 1 }; seatDomainModels.Add(seat1); seatDomainModels.Add(seat2); List <SeatResultModel> seatsTaken = new List <SeatResultModel>(); Seat s1 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 4, Row = 1 }; Seat s2 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 5, Row = 1 }; List <Seat> seats = new List <Seat>(); seats.Add(s1); seats.Add(s2); CreateReservationModel createReservationModel = new CreateReservationModel() { ProjectionId = Guid.NewGuid(), UserId = Guid.NewGuid(), SeatIds = new List <SeatDomainModel>() }; Projection projection = new Projection { Id = createReservationModel.ProjectionId, AuditoriumId = 1, MovieId = Guid.NewGuid(), DateTime = DateTime.Now.AddDays(1) }; createReservationModel.SeatIds = seatDomainModels; _mockReservationService.Setup(x => x.GetTakenSeats(createReservationModel.ProjectionId)).Returns(seatsTaken); _mockSeatRepository.Setup(x => x.GetAll()).ReturnsAsync(seats); _mockProjectionRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(projection); //Act var resultAction = _reservationService.CreateReservation(createReservationModel); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(Messages.SEAT_SEATS_NOT_EXIST_FOR_AUDITORIUM, resultAction.ErrorMessage); Assert.IsNull(resultAction.Reservation); Assert.IsFalse(resultAction.IsSuccessful); Assert.IsInstanceOfType(resultAction, typeof(ReservationResultModel)); }
public void ReservationService_CreateReservation_ReturnsErrorMessage_SeatNotInTheSameRow() { //Arrange List <SeatDomainModel> seatsRequested = new List <SeatDomainModel>(); SeatDomainModel seat1 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1 }; SeatDomainModel seat2 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 3, Row = 1 }; SeatDomainModel seat3 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 2 }; seatsRequested.Add(seat1); seatsRequested.Add(seat2); seatsRequested.Add(seat3); List <SeatResultModel> seatsTaken = new List <SeatResultModel>(); Seat s1 = new Seat { Id = seat1.Id, AuditoriumId = seat1.AuditoriumId, Number = seat1.Number, Row = seat1.Row }; Seat s2 = new Seat { Id = seat2.Id, AuditoriumId = seat2.AuditoriumId, Number = seat2.Number, Row = seat2.Row }; Seat s3 = new Seat { Id = seat3.Id, AuditoriumId = seat3.AuditoriumId, Number = seat3.Number, Row = seat3.Row }; List <Seat> seatsInAuditorium = new List <Seat>(); seatsInAuditorium.Add(s1); seatsInAuditorium.Add(s2); seatsInAuditorium.Add(s3); CreateReservationModel createReservationModel = new CreateReservationModel() { ProjectionId = Guid.NewGuid(), UserId = Guid.NewGuid(), SeatIds = new List <SeatDomainModel>() }; Projection projection = new Projection { Id = createReservationModel.ProjectionId, AuditoriumId = 1, MovieId = Guid.NewGuid(), DateTime = DateTime.Now.AddDays(1) }; createReservationModel.SeatIds = seatsRequested; _mockReservationService.Setup(x => x.GetTakenSeats(createReservationModel.ProjectionId)).Returns(seatsTaken); _mockSeatRepository.Setup(x => x.GetAll()).ReturnsAsync(seatsInAuditorium); _mockProjectionRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(projection); _mockSeatRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(s1); //Act var resultAction = _reservationService.CreateReservation(createReservationModel); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(Messages.SEAT_SEATS_CANNOT_BE_DUPLICATES, resultAction.ErrorMessage); Assert.IsFalse(resultAction.IsSuccessful); Assert.IsNull(resultAction.Reservation); Assert.IsInstanceOfType(resultAction, typeof(ReservationResultModel)); }
public async Task <AuditoriumDomainModel> UpdateAuditorium(AuditoriumDomainModel updatedAuditorium, int numberOfRows, int numberOfColumns) { var originalAuditoriumSeats = await _seatService.GetSeatsByAuditoriumId(updatedAuditorium.Id); if (originalAuditoriumSeats == null) { return(null); } // Proveravanje trenutnog stanja auditorijuma int maxRow = 1; int maxColumn = 1; void setMax(IEnumerable <SeatDomainModel> audit) { foreach (SeatDomainModel seat in audit) { if (seat.Row > maxRow) { maxRow = seat.Row; } if (seat.Number > maxColumn) { maxColumn = seat.Number; } } } void setMaxRow(IEnumerable <SeatDomainModel> audit) { foreach (SeatDomainModel seat in audit) { maxRow = 1; if (seat.Row > maxRow) { maxRow = seat.Row; } } } setMax(originalAuditoriumSeats); // Uspostavljanje parametara za izmenu stanja sedista updatedAuditorium.SeatsList = originalAuditoriumSeats.ToList(); int rowDelta = numberOfRows - maxRow; // parametar koji definise kako se menja broj kolona moze biti pozitivan i negativan int columnDelta = numberOfColumns - maxColumn; // parametar koji definise kako se menja broj redova moze biti pozitivan i negativan if (rowDelta != 0 || columnDelta != 0) { int i = 0, j = 0; // brojaci // ako treba da se dodaju redovi if (rowDelta > 0) { for (i = maxRow + 1; i <= maxRow + rowDelta; i++) { for (j = 1; j <= maxColumn; j++) { SeatDomainModel newSeat = new SeatDomainModel() { AuditoriumId = updatedAuditorium.Id, Row = i, Number = j }; // sedista se dodaju u objekat koji ce se updejtovati updatedAuditorium.SeatsList.Add(newSeat); } } setMaxRow(updatedAuditorium.SeatsList); } // ako treba da se izbrisu redovi else if (rowDelta < 0) { for (i = maxRow; i > maxRow + rowDelta; i--) { for (j = 1; j <= maxColumn; j++) { // sedista se brisu iz baze var seatToDelete = await _seatService.GetSeatByAuditoriumIdRowSeatnum(updatedAuditorium.Id, i, j); if (seatToDelete == null) { continue; } // ovo je neophodno jer navodno ne moze da se radi .remove preko kopije objekta nego mora da bude 'isti tip objekta' var seatListObjectToRemove = updatedAuditorium.SeatsList.Where(x => x.Id == seatToDelete.Id).FirstOrDefault(); updatedAuditorium.SeatsList.Remove(seatListObjectToRemove); var result = await _seatService.DeleteSeat(seatToDelete.Id); if (result == null) { return(null); } } } setMaxRow(updatedAuditorium.SeatsList); } if (columnDelta > 0) { for (i = 1; i <= maxRow; i++) { for (j = maxColumn + 1; j <= maxColumn + columnDelta; j++) { SeatDomainModel newSeat = new SeatDomainModel() { AuditoriumId = updatedAuditorium.Id, Row = i, Number = j }; // sedista se dodaju u objekat koji ce se updejtovati updatedAuditorium.SeatsList.Add(newSeat); } } } else if (columnDelta < 0) { for (i = 1; i <= maxRow; i++) { for (j = maxColumn; j > maxColumn + columnDelta; j--) { // ovde skidanje sa liste ide prvo jer sedista koja su samo dodata na listu a nisu u bazu takodje treba da se obrisu var seatListObjectToRemove = updatedAuditorium.SeatsList.Where(x => x.AuditoriumId == updatedAuditorium.Id && x.Row == i && x.Number == j).FirstOrDefault(); updatedAuditorium.SeatsList.Remove(seatListObjectToRemove); // sedista se brisu iz baze var seatToDelete = await _seatService.GetSeatByAuditoriumIdRowSeatnum(updatedAuditorium.Id, i, j); if (seatToDelete == null) { continue; } var result = _seatService.DeleteSeat(seatToDelete.Id); if (result == null) { return(null); } } } foreach (SeatDomainModel seat in updatedAuditorium.SeatsList) { if (seat.Row > maxRow) { maxRow = seat.Row; } } ; } } // SeatDomainModel se prevode u SeatList da bi se Auditorium objekat uneo u bazu List <Seat> auditoriumSeatList = new List <Seat>(); foreach (SeatDomainModel domainModel in updatedAuditorium.SeatsList) { Seat seat = new Seat() { Id = domainModel.Id, AuditoriumId = domainModel.AuditoriumId, Row = domainModel.Row, Number = domainModel.Number }; auditoriumSeatList.Add(seat); } // Kreira se updejtovani objekat za unos u bazu Auditorium auditorium = new Auditorium() { CinemaId = updatedAuditorium.CinemaId, Id = updatedAuditorium.Id, Name = updatedAuditorium.Name, Seats = auditoriumSeatList }; // Updejtovani auditorijum se vraca u bazu var data = _auditoriumsRepository.Update(auditorium); if (data == null) { return(null); } _auditoriumsRepository.Save(); // Prevodjenje vracenog Auditorijuma u AuditoriumDomainModel i return List <SeatDomainModel> resultSeatList = new List <SeatDomainModel>(); foreach (Seat seat in data.Seats) { SeatDomainModel seatDomainModel = new SeatDomainModel() { Id = seat.Id, AuditoriumId = seat.AuditoriumId, Row = seat.Row, Number = seat.Number }; resultSeatList.Add(seatDomainModel); } AuditoriumDomainModel returnResult = new AuditoriumDomainModel() { Id = data.Id, CinemaId = data.CinemaId, Name = data.Name, SeatsList = resultSeatList }; return(returnResult); }
public async Task <ReservationResultModel> CreateReservation(ReservationDomainModel requestedReservation) { // get taken seats for show var takenSeats = await GetTakenSeats(requestedReservation.ShowId); var seats = await _seatRepository.GetAllAsync(); // check if show id is valid var show = await _showRepository.GetByIdAsync(requestedReservation.ShowId); if (show == null) { return(new ReservationResultModel { isSuccessful = false, ErrorMessage = Messages.SHOW_DOES_NOT_EXIST_FOR_RESERVATION }); } // check if user id is valid var user = await _userRepository.GetByIdAsync(requestedReservation.UserId); if (user == null) { return(new ReservationResultModel { isSuccessful = false, ErrorMessage = Messages.USER_FOR_RESERVATION_DOES_NOT_EXIST }); } // get all seats for auditorium seats = seats.Where(seat => seat.AuditoriumId == show.AuditoriumId); //check if requested seats exist in the auditorium var duplicateSeats = seats .Select(x => x.Id) .Intersect(requestedReservation.SeatsList .Select(x => x.Id)); if (duplicateSeats.Count() != requestedReservation.SeatsList.Count()) { return(new ReservationResultModel { isSuccessful = false, ErrorMessage = Messages.SEAT_DOES_NOT_EXIST_FOR_AUDITORIUM }); } // check if requested seats are more than 1 and in the same row List <SeatDomainModel> seatModels = new List <SeatDomainModel>(); foreach (var seat in requestedReservation.SeatsList) { var reqSeat = await _seatRepository.GetByIdAsync(seat.Id); SeatDomainModel seatDomain = new SeatDomainModel { Id = reqSeat.Id, Number = reqSeat.Number, Row = reqSeat.Row, AuditoriumId = reqSeat.AuditoriumId }; seatModels.Add(seatDomain); } // check if seats are duplicates var row = seatModels[0].Number; var differentRows = seatModels.Select(x => x.Number).Distinct(); if (differentRows.Count() < seatModels.Count) { return(new ReservationResultModel { isSuccessful = false, ErrorMessage = Messages.SEATS_CANNOT_BE_DUPLICATES }); } // check if seats are in the same row if (requestedReservation.SeatsList.Count() > 1) { var singleSeat = seatModels[0]; foreach (var x in seatModels) { if (singleSeat.Row != x.Row) { return(new ReservationResultModel { isSuccessful = false, ErrorMessage = Messages.SEATS_NOT_IN_THE_SAME_ROW }); } } } // check if seats are next to each other if (requestedReservation.SeatsList.Count() > 1) { seatModels = seatModels.OrderByDescending(x => x.Number).ToList(); var singleSeat2 = seatModels[0]; var counter = 1; foreach (var x in seatModels.Skip(1)) { if (x.Number + counter != singleSeat2.Number) { return(new ReservationResultModel { isSuccessful = false, ErrorMessage = Messages.SEATS_MUST_BE_NEXT_TO_EACH_OTHER }); } else { counter++; } } } // check if requested seats are already taken if (takenSeats != null) { foreach (var takenSeat in takenSeats) { foreach (var requestedSeat in requestedReservation.SeatsList) { if (takenSeat.Id == requestedSeat.Id) { return(new ReservationResultModel { isSuccessful = false, ErrorMessage = Messages.SEATS_ALREADY_TAKEN_ERROR }); } } } } // insert in database Reservation reservationToInsert = new Reservation { ShowId = requestedReservation.ShowId, UserId = requestedReservation.UserId, ReservationSeats = new List <ReservationSeat>() }; var insertedReservation = _reservationsRepository.Insert(reservationToInsert); foreach (var rs in requestedReservation.SeatsList) { reservationToInsert.ReservationSeats.Add(new ReservationSeat { SeatId = rs.Id, ReservationId = insertedReservation.Id }); } _reservationsRepository.Save(); return(new ReservationResultModel { isSuccessful = true, ReservationDomainModel = new ReservationDomainModel { Id = insertedReservation.Id, ShowId = insertedReservation.ShowId, UserId = insertedReservation.UserId } }); }
public void TestInitialize() { _auditorium = new Auditorium { Id = 1, CinemaId = 1, Name = "AuditoriumIme", Cinema = new Data.Cinema { Name = "Bioskop" } }; _auditoriumDomainModel = new AuditoriumDomainModel { Id = _auditorium.Id, CinemaId = _auditorium.CinemaId, Name = _auditorium.Name }; _projectionDomainModel = new ProjectionDomainModel { AuditoriumId = _auditoriumDomainModel.Id, Id = Guid.NewGuid(), AuditoriumName = _auditoriumDomainModel.Name, MovieId = Guid.NewGuid(), MovieRating = 1, MovieTitle = "imefilmea", MovieYear = 1992, ProjectionTime = DateTime.Now.AddDays(1) }; _seatDomainModel = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = _auditoriumDomainModel.Id, Row = 1, Number = 1 }; List <Auditorium> auditoriumsModelsList = new List <Auditorium>(); auditoriumsModelsList.Add(_auditorium); IEnumerable <Auditorium> auditoriums = auditoriumsModelsList; Task <IEnumerable <Auditorium> > responseTask = Task.FromResult(auditoriums); List <ProjectionDomainModel> projectionsModelsList = new List <ProjectionDomainModel>(); projectionsModelsList.Add(_projectionDomainModel); IEnumerable <ProjectionDomainModel> projections = projectionsModelsList; Task <IEnumerable <ProjectionDomainModel> > projectionsResponseTask = Task.FromResult(projections); List <SeatDomainModel> seatsModelsList = new List <SeatDomainModel>(); seatsModelsList.Add(_seatDomainModel); IEnumerable <SeatDomainModel> seats = seatsModelsList; Task <IEnumerable <SeatDomainModel> > seatsResponseTask = Task.FromResult(seats); _mockAuditoriumsRepository = new Mock <IAuditoriumsRepository>(); _mockProjectionService = new Mock <IProjectionService>(); _mockSeatService = new Mock <ISeatService>(); }
public ReservationResultModel CreateReservation(CreateReservationModel reservation) { //get all taken seats for projection var takenSeats = GetTakenSeats(reservation.ProjectionId); var seats = _seatRepository.GetAll().Result; var projection = _projectionRepository.GetByIdAsync(reservation.ProjectionId).Result; if(projection == null) { return new ReservationResultModel { IsSuccessful = false, ErrorMessage = Messages.PROJECTION_DOES_NOT_EXIST }; } //get all seats for auditorium seats = seats.Where(auditorium => auditorium.AuditoriumId == projection.AuditoriumId); //check if the requested seats exist in the auditorium var commonSeats = seats.Select(x => x.Id).Intersect(reservation.SeatIds.Select(s => s.Id)); if(commonSeats.Count() != reservation.SeatIds.Count()) { return new ReservationResultModel { IsSuccessful = false, ErrorMessage = Messages.SEAT_SEATS_NOT_EXIST_FOR_AUDITORIUM }; } //check if requested seats are more than 1 and in the same row List<SeatDomainModel> seatModels = new List<SeatDomainModel>(); foreach (var seat in reservation.SeatIds) { var reqSeat = _seatRepository.GetByIdAsync(seat.Id).Result; SeatDomainModel seatDomain = new SeatDomainModel() { Id = reqSeat.Id, Number = reqSeat.Number, Row = reqSeat.Row, AuditoriumId = reqSeat.AuditoriumId }; seatModels.Add(seatDomain); } //check if seats are duplicates var row = seatModels[0].Number; var differentRow = seatModels.Select(x => x.Number).Distinct(); if(differentRow.Count() < seatModels.Count) { return new ReservationResultModel { IsSuccessful = false, ErrorMessage = Messages.SEAT_SEATS_CANNOT_BE_DUPLICATES }; } if (reservation.SeatIds.ToList().Count() > 1) { var singleSeat = seatModels[0]; foreach (var x in seatModels) { if(singleSeat.Row != x.Row) { return new ReservationResultModel { IsSuccessful = false, ErrorMessage = Messages.SEAT_SEATS_NOT_IN_SAME_ROW }; } } } //check if seats are not next to each other if(reservation.SeatIds.Count() > 1) { seatModels = seatModels.OrderByDescending(x => x.Number).ToList(); var singleSeat2 = seatModels[0]; var counter = 1; foreach (var y in seatModels.Skip(1)) { if (y.Number + counter != singleSeat2.Number) { return new ReservationResultModel { IsSuccessful = false, ErrorMessage = Messages.SEAT_SEATS_MUST_BE_NEXT_TO_EACH_OTHER }; } else { counter++; } } } //check if requested seats are already taken if(takenSeats != null) { foreach (var takenSeat in takenSeats) { foreach (var requestedSeat in reservation.SeatIds) { if (takenSeat.SeatDomainModel.Id == requestedSeat.Id) { return new ReservationResultModel { IsSuccessful = false, ErrorMessage = Messages.SEAT_SEATS_ALREADY_TAKEN_ERROR }; } } } } #region Komentar /* var auditorium = _auditoriumRepository.GetByIdAsync(projection.AuditoriumId).Result; List<(int, int)> requestedSeatsRowsAndNumbers = reservation.SeatsRequested .Select(s => { var seat = _seatRepository.GetByIdAsync(s.Id).Result; return (seat.Row, seat.Number); }).ToList(); int rowMax = auditorium.Seats.Max(s => s.Row); int numberMax = auditorium.Seats.Max(s => s.Number); List<(int row, int number)> listOfAllSeats = new List<(int, int)>(); for (int i = 1; i <= rowMax; i++) { for (int j = 1; j <= numberMax; j++) { listOfAllSeats.Add((i, j)); } } List<(int row, int number)> listTakenSeats = takenSeats .Select(s => (s.SeatDomainModel.Row, s.SeatDomainModel.Number)) .ToList(); List<(int row, int number)> listFreeSeats = listOfAllSeats .Except(listTakenSeats) .ToList(); */ //CHECK IF listFreeSeats CONTAINS AT LEAST 1 REQUESTED //ROW WHICH HAS EQUAL OR MORE FREE CONTINIOUS SEATS //COMPARED TO NUMBER OF REQUESTED SEATS. IF SO, THROW ERROR //BECAUSE CLIENT COULD RESERVE ALL SEATS IN THE SAME ROW. // IF NOT, ALLOW CLIENT SEPARATE RESERVATIONS. //LASTLY, CHECK IF SEATS ARE NEXT TO EACH OTHER. //IF THEY ARE, PROCEED. IF NOT, CHECK IF ROW // CONTAINS ENOUGH CONTINIOUS SEATS. IF IT DOES, // THROW ERROR BECAUSE CLIENT COULD RESERVE PROPERLY. // IF NOT, ALLOW SEPARATE RESERVATIONS IN SAME ROW. #endregion //improvised fake payment system #region Payment /* Levi9PaymentService payment = new Levi9PaymentService(); var paymentResult = payment.MakePayment().Result; if(paymentResult.IsSuccess == false) { return new ReservationResultModel { IsSuccessful = false, ErrorMessage = Messages.PAYMENT_CREATION_ERROR }; }*/ //end of payment system #endregion //create reservation for inserting Reservation reservationToAdd = new Reservation { Id = Guid.NewGuid(), ProjectionId = reservation.ProjectionId, UserId = reservation.UserId }; int countOfSeats = reservation.SeatIds.Count(); var numOfPoints = countOfSeats * 1; _userRepository.AddPointsForUser(reservation.UserId, numOfPoints); var insertedReservation = _reservationsRepository.Insert(reservationToAdd); foreach(var rs in reservation.SeatIds) { reservationToAdd.ReservationSeats.Add(new ReservationSeat { SeatId = rs.Id, ReservationId = insertedReservation.Id }); } _reservationsRepository.Save(); return new ReservationResultModel { IsSuccessful = true, Reservation = new ReservationDomainModel { Id = insertedReservation.Id, ProjectionId = insertedReservation.ProjectionId, UserId = insertedReservation.UserId } }; }
public void CinemaService_CreateCinemaAsync_ReturnsListOfCinemasWithAuditoriumsSeats() { //Arrange List <Data.Cinema> cinemas = new List <Data.Cinema>(); _city = new City { Id = 1, Name = "Miami" }; _cityDomainModel = new CityDomainModel() { Id = _city.Id, Name = _city.Name }; SeatDomainModel seat1 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1 }; SeatDomainModel seat2 = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 3, Row = 1 }; Seat s1 = new Seat { Id = seat1.Id, AuditoriumId = seat1.AuditoriumId, Number = seat1.Number, Row = seat1.Row }; Seat s2 = new Seat { Id = seat2.Id, AuditoriumId = seat2.AuditoriumId, Number = seat2.Number, Row = seat2.Row }; List <SeatDomainModel> seats = new List <SeatDomainModel>(); seats.Add(seat1); seats.Add(seat2); List <Seat> ss = new List <Seat>(); ss.Add(s1); ss.Add(s2); AuditoriumDomainModel auditoriumDomainModel = new AuditoriumDomainModel { Id = 1, CinemaId = 11, Name = "Test Audit", SeatsList = seats }; Auditorium auditorium = new Auditorium { Id = auditoriumDomainModel.Id, CinemaId = auditoriumDomainModel.CinemaId, AuditName = auditoriumDomainModel.Name, Seats = ss }; List <AuditoriumDomainModel> auditoriumDomainModelList = new List <AuditoriumDomainModel>(); auditoriumDomainModelList.Add(auditoriumDomainModel); List <Auditorium> auditoriumList = new List <Auditorium>(); auditoriumList.Add(auditorium); _cinemaDomainModel.AuditoriumsList = auditoriumDomainModelList; _cinema.Auditoriums = auditoriumList; int numOfRows = 3; int numOfSeats = 2; int expectedAuditoriumCount = 1; _mockCityRepository.Setup(x => x.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(_city); _mockCinemaRepository.Setup(x => x.GetAll()).ReturnsAsync(cinemas); _mockCinemaRepository.Setup(x => x.Insert(It.IsAny <Data.Cinema>())).Returns(_cinema); _mockCinemaRepository.Setup(x => x.Save()); //Act var resultAction = cinemaService.CreateCinemaAsync(_cinemaDomainModel, numOfSeats, numOfRows, "auditorium123").ConfigureAwait(false).GetAwaiter().GetResult(); //Assert Assert.IsNotNull(resultAction); Assert.AreEqual(expectedAuditoriumCount, resultAction.AuditoriumsList.Count); Assert.AreEqual(_cinemaDomainModel.Name, resultAction.Name); Assert.IsInstanceOfType(resultAction, typeof(CinemaDomainModel)); }