internal static List <AircraftData> PostAircraftData(AircraftData aircraftData)
 {
     using (var context = new AirportInventoryEntities())
     {
         Aircraft newAircraft = new Aircraft()
         {
             Aircraft_No = aircraftData.aircraft_no,
             Airline     = aircraftData.airline
         };
         context.Aircrafts.Add(newAircraft);
         context.SaveChanges();
         var aircraftList = context.Aircrafts.
                            Where(h => 1 == 1)
                            .Select(x => new AircraftData
         {
             aircraft_id = x.AircraftId,
             airline     = x.Airline,
             aircraft_no = x.Aircraft_No,
         }).ToList();
         if (aircraftList != null)
         {
             return(aircraftList);
         }
         else
         {
             return(null);
         }
     }
 }
 internal static List <AirportData> PostAirportData(AirportData airportData)
 {
     using (var context = new AirportInventoryEntities())
     {
         Airport newAirport = new Airport()
         {
             AirportName             = airportData.airport_name,
             Fuel_Capacity_Available = airportData.fuel_capacity_available
         };
         context.Airports.Add(newAirport);
         context.SaveChanges();
         var airportList = context.Airports.
                           Where(h => 1 == 1)
                           .Select(x => new AirportData
         {
             airport_id              = x.AirportId,
             airport_name            = x.AirportName,
             fuel_capacity_available = x.Fuel_Capacity_Available,
         }).ToList();
         if (airportList != null)
         {
             return(airportList);
         }
         else
         {
             return(null);
         }
     }
 }
Exemple #3
0
        internal static List <TransactionData> PostTransactionData(TransactionData addTransaction)
        {
            using (var context = new AirportInventoryEntities())
            {
                bool type = false;
                //context.SaveChanges();
                if (addTransaction.transaction_type == "IN")
                {
                    type = true;
                    addTransaction.transaction_parent_id = null;
                    addTransaction.aircraft_id           = null;
                    var updateAirport = context.Airports.
                                        Where(x => x.AirportId == addTransaction.airport_id).Select(u => u).FirstOrDefault();
                    if (updateAirport != null)
                    {
                        updateAirport.Fuel_Capacity_Available += addTransaction.quantity;
                    }
                    Transaction newTransaction = new Transaction()
                    {
                        Transaction_DateTime  = DateTime.Parse(addTransaction.transaction_date_time),
                        Quantity              = addTransaction.quantity,
                        Airport_Id            = addTransaction.airport_id,
                        Aircraft_Id           = addTransaction.aircraft_id,
                        Transaction_Type      = type,
                        Transaction_Parent_Id = addTransaction.transaction_parent_id
                    };
                    context.Transactions.Add(newTransaction);
                    context.SaveChanges();
                }
                else if (addTransaction.transaction_type == "OUT")
                {
                    type = false;
                    addTransaction.transaction_parent_id = null;
                    var updateAirport = context.Airports.
                                        Where(x => x.AirportId == addTransaction.airport_id).Select(u => u).FirstOrDefault();
                    if (updateAirport != null)
                    {
                        updateAirport.Fuel_Capacity_Available -= addTransaction.quantity;
                    }
                    Transaction newTransaction = new Transaction()
                    {
                        Transaction_DateTime  = DateTime.Parse(addTransaction.transaction_date_time),
                        Quantity              = addTransaction.quantity,
                        Airport_Id            = addTransaction.airport_id,
                        Aircraft_Id           = addTransaction.aircraft_id,
                        Transaction_Type      = type,
                        Transaction_Parent_Id = addTransaction.transaction_parent_id
                    };
                    context.Transactions.Add(newTransaction);
                    context.SaveChanges();
                }

                var transactionList = context.Transactions.
                                      Where(h => 1 == 1).ToList();
                List <TransactionData> allTransaction = new List <TransactionData>();
                string transactionType = "";
                if (transactionList != null)
                {
                    foreach (var transaction in transactionList)
                    {
                        if (transaction.Transaction_Type)
                        {
                            transactionType = "IN";
                        }
                        else
                        {
                            transactionType = "OUT";
                        }
                        TransactionData transactionData = new TransactionData()
                        {
                            transaction_id        = transaction.Transaction_Id,
                            transaction_date_time = transaction.Transaction_DateTime.ToString(),
                            aircraft_id           = transaction.Aircraft_Id,
                            airport_id            = transaction.Airport_Id,
                            transaction_type      = transactionType,
                            quantity = transaction.Quantity,
                            transaction_parent_id = transaction.Transaction_Parent_Id
                        };
                        allTransaction.Add(transactionData);
                    }
                    return(allTransaction);
                }
                else
                {
                    return(null);
                }
            }
        }