public JsonResult Save(ICollection <ReservationSeat> seats) { var errorMessage = validateReservation(seats); if (errorMessage == null) { var rsrv = new Reservation(); rsrv.Name = User.Identity.Name; rsrv.ReserveDateTime = System.DateTime.Now; db.Reservations.Add(rsrv); foreach (var seat in seats) { var rsrvSt = new ReservationSeat(); rsrvSt.Name = seat.Name; rsrvSt.SeatLevel = seat.SeatLevel; db.ReservationSeats.Add(rsrvSt); } db.SaveChanges(); return(Json("登録完了しました。", JsonRequestBehavior.AllowGet)); } else { return(Json(errorMessage, JsonRequestBehavior.AllowGet)); } }
public void CreateNewTickets(ref List <TicketVM> tickets, InformAboutPassengers personsInf) { CarriageType carrType = carrServ.GetCarrTypyById(carrServ.GetCarrTypeIdByCarrType(tickets[0].CarriageType)); Carriage carr = carrServ.GetCarrByTypeOrderAndTrain(carrType.ID, tickets[0].CarriageOrder, tickets[0].TrainNumber); StationOnRoute startStatOnRoute = statOnRouteServ.GetByTrainNumbAndStation(tickets[0].TrainNumber, tickets[0].StartStation); StationOnRoute endStatOnRoute = statOnRouteServ.GetByTrainNumbAndStation(tickets[0].TrainNumber, tickets[0].EndStation); ReservationSeat seat; Person person; bool haveTea = false; bool haveBed = false; for (int i = 0; i < tickets.Count(); i++) { int maxIdInResrvSeat = seatServ.GetMaxId(); seat = new ReservationSeat() { ID = maxIdInResrvSeat + 1, Number = tickets[i].SeatNumber, CarriageID = carr.ID, IsDeleted = false }; seatServ.Create(seat); if (!personServ.PersonExist(tickets[i].FirstName, tickets[i].LastName, tickets[i].BirthDate, tickets[i].PersonType)) { int maxIdInPerson = personServ.GetMaxId(); int personTypeId = personServ.GetPersonTypeIdByType(tickets[i].PersonType); person = new Person() { ID = maxIdInPerson + 1, FirstName = tickets[i].FirstName, LastName = tickets[i].LastName, BirthDate = tickets[i].BirthDate, Email = personsInf.Email[i], Phone = personsInf.Phone[i], PersonTypeID = personTypeId, IsDeleted = false }; personServ.Create(person); } else { person = personServ.GetPersonByFLNameBirthType(tickets[i].FirstName, tickets[i].LastName, tickets[i].BirthDate, tickets[i].PersonType); } int maxIdInTicket = ticketServ.GetMaxId(); Ticket ticket = new Ticket() { ID = maxIdInTicket + 1, PersonID = person.ID, DepartureDateTime = tickets[i].DepartureDateTime, ArrivalDateTime = tickets[i].ArrivalDateTime, ReservationSeatID = seat.ID, StationOnRouteStartID = startStatOnRoute.ID, StationOnRouteEndID = endStatOnRoute.ID, IsDeleted = false }; ticketServ.Create(ticket); if (tickets[i].HaveTea) { haveTea = true; } if (tickets[i].HaveBed) { haveBed = true; } tickets[i].Price = sqlProcService.GetTicketPrice(ticket.ID, haveTea, haveBed); ticketServ.AddPriceForTicket(ticket.ID, tickets[i].Price); haveTea = false; haveBed = false; } }
public void ReservationService_CreateReservation_ReturnsCreatedReservation() { //Arrange Projection projection = new Projection { Id = Guid.NewGuid(), AuditoriumId = 1, DateTime = DateTime.Now.AddHours(5), MovieId = Guid.NewGuid() }; SeatResultModel srm1 = new SeatResultModel { ErrorMessage = null, IsSuccessful = true, SeatDomainModel = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 1 } }; SeatResultModel srm2 = new SeatResultModel { ErrorMessage = null, IsSuccessful = true, SeatDomainModel = new SeatDomainModel { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1 } }; List <SeatResultModel> seatResults = new List <SeatResultModel>(); Seat s1 = new Seat { Id = srm1.SeatDomainModel.Id, AuditoriumId = srm1.SeatDomainModel.AuditoriumId, Number = srm1.SeatDomainModel.Number, Row = srm1.SeatDomainModel.Row }; Seat s2 = new Seat { Id = srm2.SeatDomainModel.Id, AuditoriumId = srm2.SeatDomainModel.AuditoriumId, Number = srm2.SeatDomainModel.Number, Row = srm2.SeatDomainModel.Row }; List <Seat> seats = new List <Seat>(); seats.Add(s1); seats.Add(s2); CreateReservationModel reservation = new CreateReservationModel { ProjectionId = projection.Id, UserId = Guid.NewGuid(), SeatIds = seats.Select(s => new SeatDomainModel { Id = s.Id, AuditoriumId = s.AuditoriumId, Number = s.Number, Row = s.Row }) }; //TO BE CONTINUED. Reservation reservation2 = new Reservation { Id = Guid.NewGuid(), ProjectionId = reservation.ProjectionId, UserId = reservation.UserId, ReservationSeats = new List <ReservationSeat>() }; ReservationSeat rs1 = new ReservationSeat { SeatId = s1.Id, Seat = s1, ReservationId = Guid.NewGuid(), Reservation = reservation2 }; reservation2.ReservationSeats.Add(rs1); _mockReservationService.Setup(x => x.GetTakenSeats(It.IsAny <Guid>())).Returns(seatResults); _mockSeatRepository.Setup(x => x.GetAll()).ReturnsAsync(seats); _mockProjectionRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(projection); _mockSeatRepository.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(s1); _mockReservationRepository.Setup(x => x.Insert(It.IsAny <Reservation>())).Returns(reservation2); //Assert var resultAction = _reservationService.CreateReservation(reservation); //Act Assert.IsNotNull(resultAction); }
public void ReservationService_GetTakenSeats_ReturnsListOfSeats() { //Arrange var expectedSeatCount = 2; Seat s1 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 1, Row = 1, ReservationSeats = new List <ReservationSeat>() }; Seat s2 = new Seat { Id = Guid.NewGuid(), AuditoriumId = 1, Number = 2, Row = 1, ReservationSeats = new List <ReservationSeat>() }; ReservationSeat rs1 = new ReservationSeat { ReservationId = _reservation.Id, SeatId = s1.Id, Seat = s1, Reservation = _reservation }; ReservationSeat rs2 = new ReservationSeat { ReservationId = _reservation.Id, SeatId = s2.Id, Seat = s2, Reservation = _reservation }; Projection projection = new Projection { Id = _reservation.ProjectionId, AuditoriumId = 1, MovieId = Guid.NewGuid(), DateTime = DateTime.Now.AddDays(4) }; List <Reservation> reservations = new List <Reservation>(); List <Seat> seats = new List <Seat>(); seats.Add(s1); seats.Add(s2); _reservation.ReservationSeats.Add(rs1); _reservation.ReservationSeats.Add(rs2); s1.ReservationSeats.Add(rs1); s2.ReservationSeats.Add(rs2); reservations.Add(_reservation); _mockReservationRepository.Setup(x => x.GetReservationByProjectionId(It.IsAny <Guid>())).Returns(reservations); //Act var resultAction = _reservationService.GetTakenSeats(projection.Id); var result = resultAction.ToList(); //Assert Assert.AreEqual(expectedSeatCount, result.Count); Assert.AreEqual(result[0].SeatDomainModel.Id, s1.Id); Assert.AreEqual(result[1].SeatDomainModel.Id, s2.Id); Assert.IsTrue(result[0].IsSuccessful); Assert.IsNull(result[0].ErrorMessage); Assert.IsInstanceOfType(result[0].SeatDomainModel, typeof(SeatDomainModel)); Assert.IsInstanceOfType(resultAction, typeof(IEnumerable <SeatResultModel>)); }
public void Update(ReservationSeat resSeat) { db.Entry(resSeat).State = EntityState.Modified; db.SaveChanges(); }
public void Create(ReservationSeat resSeat) { db.ReservationSeats.Add(resSeat); db.SaveChanges(); }
public void Update(ReservationSeat resSeat) { reservSeatRepo.Update(resSeat); }
public void Create(ReservationSeat resSeat) { reservSeatRepo.Create(resSeat); }