public async Task <bool> CheckFinalBookAvailabilityAsync(int bookId, int accountId) { FlightBookInfoEntity bookInfo = _flightBooksInfo.FirstOrDefault( x => x.Id == bookId && x.AccountId == accountId && DateTimeOffset.Now - x.BookTime <= _bookingSettings.ExpirationTime && x.BookType == BookType.AwaitingPayment ); return(bookInfo != null); }
public async Task <AddResult> BookForTimeAsync(FlightBookInfo bookInfo) { FlightEntity flight = await _flightRepository.GetByIdAsync(bookInfo.FlightId); if (flight == null) { return(new AddResult(ResultTypes.NotFound, null)); } for (int seatBookIndex = 0; seatBookIndex < bookInfo.SeatBooks.Length; seatBookIndex++) { SeatBook seatBook = bookInfo.SeatBooks[seatBookIndex]; AirplaneSeatEntity seat = await _airplaneRepository.GetSeatById(seatBook.SeatId); if (seat == null) { return(new AddResult(ResultTypes.NotFound, null)); } bool canBook = await _flightRepository.CheckSeatBookAvailabilityAsync( bookInfo.FlightId, seatBook.SeatId ); if (!canBook) { return(new AddResult(ResultTypes.Duplicate, null)); } } bookInfo.BookType = BookType.AwaitingPayment; bookInfo.BookTime = DateTimeOffset.Now; bookInfo.AccountId = _accountId; FlightBookInfoEntity bookInfoDal = _mapper.Map <FlightBookInfoEntity>(bookInfo); int accountFlightInfoId = await _flightRepository.AddAccountFlightInfoAsync(bookInfoDal); foreach (SeatBook seatBook in bookInfo.SeatBooks) { seatBook.FlightBookInfoId = accountFlightInfoId; SeatBookEntity seatBookDal = _mapper.Map <SeatBookEntity>(seatBook); await _flightRepository.BookSeatAsync(seatBookDal); } return(new AddResult(ResultTypes.Ok, accountFlightInfoId));; }
public async Task <int> AddAccountFlightInfoAsync(FlightBookInfoEntity bookInfo) { using SqlConnection db = new SqlConnection(_dalSettings.ConnectionString); return(await db.QuerySingleOrDefaultAsync <int>( "AddAccountFlightInfo", new { FlightId = bookInfo.FlightId, SuitcaseOverloadCost = bookInfo.SuitcaseOverloadCost, HandLuggageOverloadCost = bookInfo.HandLuggageOverloadCost, BookType = BookType.AwaitingPayment, BookTime = DateTimeOffset.Now, AccountId = bookInfo.AccountId }, commandType : CommandType.StoredProcedure)); }
public async Task <bool> CheckSeatBookAvailabilityAsync(int flightId, int seatId) { SeatBookEntity seat = _flightSeatsInfo.FirstOrDefault(x => x.SeatId == seatId); if (seat == null) { return(true); } FlightBookInfoEntity bookInfo = _flightBooksInfo.FirstOrDefault( x => x.FlightId == flightId && DateTimeOffset.Now - x.BookTime <= _bookingSettings.ExpirationTime && x.Id == seat.FlightBookInfoId ); return(bookInfo == null); }
public async Task <int> AddAccountFlightInfoAsync(FlightBookInfoEntity bookInfo) { return(0); }