Пример #1
0
        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);
        }
Пример #2
0
        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));;
        }
Пример #3
0
        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));
        }
Пример #4
0
        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);
        }
Пример #5
0
 public async Task <int> AddAccountFlightInfoAsync(FlightBookInfoEntity bookInfo)
 {
     return(0);
 }