示例#1
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));;
        }
示例#2
0
        public async Task <AirplaneSeat> GetSeatByIdAsync(int seatId)
        {
            AirplaneSeatEntity seatDal = await _airplaneRepository.GetSeatById(seatId);

            return(_mapper.Map <AirplaneSeat>(seatDal));
        }