Example #1
0
        public async Task <bool> CreateSeatConfiguration(SeatConfiguration seatConfiguration)
        {
            try
            {
                _context.SeatConfiguration.Add(seatConfiguration);
                await _context.SaveChangesAsync();

                return(true);
            }catch (Exception e)
            {
                return(false);
            }
        }
Example #2
0
        public async Task <bool> CreateFlight(Flight flight)
        {
            try
            {
                AirlineCompany company = (await _context.AirlineCompany.ToListAsync()).FirstOrDefault(x => x.Id == flight.AvioCompany.Id);

                PlaneType planeType = (await _context.PlaneType.ToListAsync()).FirstOrDefault(x => x.Id == flight.SeatConfiguration.PlaneType.Id);


                List <Destination> destinations = new List <Destination>();   //ovo cemo dodati kao polje, to popunjavamo
                Destination        destination;
                foreach (var d in flight.Destinations)
                {
                    destination = new Destination()
                    {
                        Address     = d.Address,
                        City        = d.City,
                        AirportName = d.AirportName,
                        Country     = d.Country
                    };

                    await _context.Destination.AddAsync(destination);

                    destinations.Add(destination);
                }

                List <Row> allRows = new List <Row>();
                Row        r;
                //List<Seat> seatsInRow = new List<Seat>();
                Seat s;
                for (var rowIndex = 0; rowIndex < flight.SeatConfiguration.Seats.Count; rowIndex++)
                {
                    r = new Row()
                    {
                        RowNo = rowIndex,
                        Seats = new List <Seat>()
                    };
                    foreach (var seat in flight.SeatConfiguration.Seats[rowIndex].Seats)
                    {
                        s = new Seat()
                        {
                            ForFastReservation = seat.ForFastReservation,
                            PassengerEmail     = seat.PassengerEmail,
                            SeatNo             = seat.SeatNo,
                            SeatStatus         = seat.SeatStatus,
                        };

                        await _context.Seat.AddAsync(s);

                        await _context.SaveChangesAsync();

                        r.Seats.Add(s);
                    }

                    await _context.Row.AddAsync(r);

                    allRows.Add(r);
                }
                //cuvam sve prethodne promene
                //await _context.SaveChangesAsync();


                SeatConfiguration seatConfiguration = new SeatConfiguration()
                {
                    PlaneType = planeType,
                    Seats     = allRows
                };

                var f = new Flight()
                {
                    AvioCompany       = company,
                    StartDate         = flight.StartDate,
                    ArrivingDate      = flight.ArrivingDate,
                    StartTime         = flight.StartTime,
                    ArrivingTime      = flight.ArrivingTime,
                    EstimationTime    = flight.EstimationTime,
                    Distance          = flight.Distance,
                    Discount          = flight.Discount,
                    SeatConfiguration = seatConfiguration,
                    Destinations      = destinations,
                    OtherServices     = flight.OtherServices,
                    Price             = flight.Price,
                    Luggage           = flight.Luggage,
                };


                _context.Flight.Add(f);
                await _context.SaveChangesAsync();

                return(true);
            }catch (Exception e)
            {
                return(false);
            }
        }
Example #3
0
 public async Task <bool> CreateSeatConfiguration(SeatConfiguration seatConfiguration)
 {
     return(await _service.CreateSeatConfiguration(seatConfiguration));
 }