private bool BookingExists(int id)
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         return(db.Bookings.Count(e => e.BookingId == id) > 0);
     }
 }
        ///// <summary>
        ///// Method updates the details of existing cutomer's account details
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="booking"></param>
        ///// <returns></returns>
        public bool UpdateBooking(int id, Booking booking)
        {
            using (AirlineDBEntities db = new AirlineDBEntities())
            {
                db.Configuration.LazyLoadingEnabled = false;
                db.Entry(booking).State             = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                    return(true);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookingExists(id))
                    {
                        return(false);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
예제 #3
0
        ///// <summary>
        ///// Method updates the details of existing cancellation details
        ///// </summary>
        ///// <param name="id"></param>
        ///// <param name="customer"></param>
        ///// <returns>return bool value</returns>
        public bool UpdateCancellation(int id, Cancellation cancellation)
        {
            try
            {
                using (AirlineDBEntities db = new AirlineDBEntities())
                {
                    db.Configuration.LazyLoadingEnabled = false;
                    db.Entry(cancellation).State        = EntityState.Modified;

                    try
                    {
                        db.SaveChanges();
                        return(true);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CancellationExists(id))
                        {
                            return(false);
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
            catch (CancellationException)
            {
                throw new CancellationException("Id Doesnt Exists");
            }
        }
 public bool PassengerExists(long id)
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         return(db.Passengers.Count(e => e.PassengerId == id) > 0);
     }
 }
 /// <summary>
 /// Method to check if custor account already exists or not
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public bool CustomerExists(int id)
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         return(db.Customers.Count(e => e.CustomerId == id) > 0);
     }
 }
        /// <summary>
        /// Method Deletes the Flight with flightid from table flights
        /// </summary>
        /// <param name="flightid">integer indicating id of Flight</param>
        /// <returns>boolean value indicating whether flight is deleted or not</returns>
        public bool DeleteFlightById(int flightid)
        {
            try
            {
                //instantiating AirLineDBEntities Context class
                using (AirlineDBEntities db = new AirlineDBEntities())
                {
                    //use LINQ query to find the Flight with id flightid
                    Flight flt = db.Flights.Where(f => f.FlightId == flightid).FirstOrDefault();

                    if (flt != null)
                    //use LINQ query to Add Flight from table flight
                    {
                        //remove item from flight
                        db.Flights.Remove(flt);

                        //save changes to the database
                        db.SaveChanges();

                        return(true);
                    }

                    else
                    {
                        throw new FlightException("flight does not exist");
                    }
                }
            }
            catch (FlightException ex)
            {
                //throw user defined FlightException
                throw new FlightException(ex.Message);
            }
        }
        /// <summary>
        /// AddFlight(Flight flight) adds the flight to the Flights table
        /// </summary>
        /// <param name="flight">object of type Flight</param>
        /// <returns>integer value indicating the Id of the added flight</returns>
        public int AddFlight(Flight flight)
        {
            try
            {
                //instantiating Online_Food_Ordering_SystemEntities3 Context class
                using (AirlineDBEntities db = new AirlineDBEntities())
                {
                    //check if the foodItem already exists
                    Flight flt = db.Flights.Where(f => f.FlightName.Equals(flight.FlightName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                    if (flt != null)
                    {
                        //if exists then throw exception
                        throw new FlightException("Flight already there");
                    }

                    //use LINQ query to Add flight from table flights
                    db.Flights.Add(flight);

                    //save changes to the database
                    db.SaveChanges();

                    Flight flts = db.Flights.Where(f => f.FlightId == flight.FlightId).FirstOrDefault();

                    return(flts.FlightId);
                }
            }
            catch (FlightException ex)
            {
                //throw user defined FlightException
                throw new FlightException(ex.Message);
            }
        }
예제 #8
0
 /// <summary>
 /// Method to add cancelled tickets
 /// </summary>
 /// <returns></returns>
 public bool AddCancellation(Cancellation cancellation)
 {
     try
     {
         using (AirlineDBEntities db = new AirlineDBEntities())
         {
             if ((db.Cancellations.Count(c => c.CancellationId == cancellation.CancellationId)) == 0)
             {
                 //Add command that will add to database
                 db.Cancellations.Add(cancellation);
                 db.SaveChanges();
                 db.Configuration.LazyLoadingEnabled = false;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (CancellationException)
     {
         throw new CancellationException("Internal Error");
     }
 }
예제 #9
0
        public static double GetFlightServiceFee(int RNo)
        {
            db = new AirlineDBEntities();
            var aircraftid = db.Route.FirstOrDefault(r => r.RNo == RNo).RAircraft;

            return(db.Aircraft.FirstOrDefault(a => a.AircraftID == aircraftid).ServiceFee);
        }
 /// <summary>
 /// method to find whether the record exist in cancellation table or not
 /// </summary>
 /// <param name="id">Cancellation ID is the parameter</param>
 /// <returns>return bool value accordingly</returns>
 private bool CancellationExists(int id)
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         return(db.Cancellations.Count(e => e.CancellationId == id) > 0);
     }
 }
 public void Dispose()
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         db.Dispose();
     }
 }
 /// <summary>
 /// Method to get list of all customers
 /// </summary>
 /// <returns></returns>
 public List <Customer> GetALLCustomers()
 {
     AirlineDBEntities db = new AirlineDBEntities();
     {
         db.Configuration.LazyLoadingEnabled = false;
         return(db.Customers.ToList());
     }
 }
예제 #13
0
 /// <summary>
 /// Method to get list of all bookings
 /// </summary>
 /// <returns></returns>
 public List <Booking> GetALLBookings()
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         db.Configuration.LazyLoadingEnabled = false;
         return(db.Bookings.ToList());
     }
 }
예제 #14
0
 /// <summary>
 /// Method to get list of all customers
 /// </summary>
 /// <returns>List of cancelled tickets</returns>
 public List <Cancellation> GetALLCancellation()
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         db.Configuration.LazyLoadingEnabled = false;
         return(db.Cancellations.ToList());
     }
 }
 ///// <summary>
 ///// Method fetches the Customer corresponding to CustomerId
 ///// </summary>
 ///// <param name="id">id of customer</param>
 ///// <returns></returns>
 public Customer GetCustomerById(int id)
 {
     AirlineDBEntities db = new AirlineDBEntities();
     {
         db.Configuration.LazyLoadingEnabled = false;
         Customer customer = db.Customers.Find(id);
         return(customer);
     }
 }
예제 #16
0
 ///// <summary>
 ///// Method fetches the Booking corresponding to BookingId
 ///// </summary>
 ///// <param name="id"></param>
 ///// <returns></returns>
 public Booking GetBookingById(int id)
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         db.Configuration.LazyLoadingEnabled = false;
         Booking booking = db.Bookings.Find(id);
         return(booking);
     }
 }
 ///// <summary>
 ///// Method fetches the Cancelled ticket corresponding to Cancellation Id
 ///// </summary>
 ///// <param name="id"></param>
 ///// <returns>Cancelled ticket</returns>
 public Cancellation GetCancellationById(int id)
 {
     using (AirlineDBEntities db = new AirlineDBEntities())
     {
         db.Configuration.LazyLoadingEnabled = false;
         Cancellation cancellation = db.Cancellations.Find(id);
         return(cancellation);
     }
 }
예제 #18
0
        public static IEnumerable <ALList> TravelAirlines()
        {
            db = new AirlineDBEntities();
            var context = db.Ticket.Where(t => t.Order.Status == 1).Join(db.Flight, t => t.FNo, f => f.FNo, (t, f) => new { t.TicketID, f.Route.RAirline });

            return(context.GroupBy(c => c.RAirline).Select(n => new ALList {
                AirlineID = n.Key, Count = n.Count()
            }).OrderByDescending(a => a.Count));
        }
예제 #19
0
        public static FlightDistance GetFlightDistance(string airport1, string airport2)
        {
            db = new AirlineDBEntities();
            var d = GetFlightDistances().Where(item => item.AirportID1 == airport1 && item.AirportID2 == airport2).FirstOrDefault();

            if (d == null)
            {
                d = GetFlightDistances().Where(item => item.AirportID1 == airport2 && item.AirportID2 == airport1).FirstOrDefault();
            }
            return(d);
        }
예제 #20
0
        /// <summary>
        /// Method that automtically add records to cancellation table and update refunds
        /// </summary>
        /// <param name="bookingId">Takes bookigId as parameters</param>
        /// <returns>Bool value</returns>

        public bool CancellationAuto(int bookingId)
        {
            try
            {
                using (AirlineDBEntities db = new AirlineDBEntities())
                {
                    Booking book = db.Bookings.Find(bookingId);
                    if (book == null)
                    {
                        throw new CancellationException("No Bookings Available");
                    }
                    //checks whether booking is cancelled or not
                    if (book.TicketStatus.Equals("CANC"))
                    {
                        throw new CancellationException("Ticket Already Cancelled");
                    }
                    else
                    {
                        Cancellation can = new Cancellation()
                        {
                            FlightId           = book.FlightId,
                            BookingId          = bookingId,
                            DateOfCancellation = DateTime.Now,
                            //checks whether date of journey is from which date
                            RefundAmount = CalculationOfRefund(bookingId, book.DateOfJourney <= DateTime.Now ? 0 : 1)
                        };
                        db.Cancellations.Add(can);
                        db.SaveChanges();
                        //After adding the object to cancellation table, the status of booking will be updated to Cancelled in bookings table
                        book.TicketStatus = "CANC";
                        book.TicketFare   = book.TicketFare - can.RefundAmount;
                        db.SaveChanges();


                        Flight flight = db.Flights.Find(can.FlightId);
                        //To store null we are giving ?
                        int?flightAvailableSeats = flight.AvailableSeats;
                        int?noOfSeats            = book.NoOfSeats;
                        // Converting int? to int as Available Seats has integer datatype
                        flight.AvailableSeats = (int)(flightAvailableSeats + noOfSeats);
                        //updating the available seats in flight table
                        db.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (CancellationException ex)
            {
                throw new CancellationException(ex.Message);
            }
        }
예제 #21
0
 /// <summary>
 /// method to find whether the record exist in cancellation table or not
 /// </summary>
 /// <param name="id">Cancellation ID is the parameter</param>
 /// <returns>return bool value accordingly</returns>
 private bool CancellationExists(int id)
 {
     try
     {
         using (AirlineDBEntities db = new AirlineDBEntities())
         {
             return(db.Cancellations.Count(e => e.CancellationId == id) > 0);
         }
     }
     catch (CancellationException)
     {
         throw new CancellationException("Cancellation Doesnt Exists");
     }
 }
예제 #22
0
 /// <summary>
 /// Checks if booking exists or not in th
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 private bool BookingExists(int id)
 {
     try
     {
         using (AirlineDBEntities db = new AirlineDBEntities())
         {
             return(db.Bookings.Count(e => e.BookingId == id) > 0);
         }
     }
     catch (BookingsException)
     {
         throw;
     }
 }
        /// <summary>
        /// Method create the new booking account
        /// </summary>
        /// <returns></returns>
        public int AddBooking(Booking booking)
        {
            try {
                using (AirlineDBEntities db = new AirlineDBEntities())
                {
                    // Checks If there is destination and source is availible
                    Flight flight = db.Flights.Where <Flight>(
                        f => booking.Destination.Equals(f.Destination) &&
                        booking.Source.Equals(f.Source)
                        ).First();

                    // If data does not matches with flight data then it is null
                    if (flight == null)
                    {
                        throw new BookingsException("Invalid Details");
                    }

                    // If AvailableSeats is less then user requuired seats then it does not stores data
                    if (booking.NoOfSeats > flight.AvailableSeats)
                    {
                        throw new BookingsException("Seats unavailable");
                    }


                    //Customer customer=db.Customers.Where<Flight>(
                    //    f => booking.Destination.Equals(f.Destination)
                    //    && booking.Source.Equals(f.Source)
                    //    ).First();

                    booking.FlightId   = flight.FlightId;
                    booking.CustomerId = 100;
                    // Counts Ticket Fare
                    booking.TicketFare = booking.NoOfSeats * 2000;

                    // Sets Ticket Status
                    booking.TicketStatus = "NOTC";

                    //Adds booking data to booking table
                    db.Bookings.Add(booking);
                    //Save all cahnges made in the context in database
                    db.SaveChanges();
                    return(booking.BookingId);
                }
            }
            catch (Exception ex)
            {
                //throw user defined FlightException
                throw new BookingsException(ex.Message);
            }
        }
예제 #24
0
        public static void InsertFlight()
        {
            db = new AirlineDBEntities();
            IEnumerable <Route> routeDB = db.Route;

            foreach (var route in routeDB)
            {
                var aircraft = aircraftDB.Where(a => a.AircraftID == route.RAircraft).FirstOrDefault();
                int seatE = aircraft.EconomySeats;
                int seatB = 0, seatF = 0;
                var distance = FlightDistanceDAO.GetFlightDistance(route.Departure.Trim(), route.Destination.Trim());
                if (distance == null)
                {
                    string err = string.Format("{0}:{1}-{2}", route.RNo, route.Departure, route.Destination);
                    error.Add(new ErrorModel {
                        Error = err
                    });
                }
                else
                {
                    if (aircraft.BussinessSeats != null)
                    {
                        seatB = int.Parse(aircraft.BussinessSeats.ToString());
                    }
                    if (aircraft.FirstClassSeats != null)
                    {
                        seatF = int.Parse(aircraft.FirstClassSeats.ToString());
                    }

                    for (int i = 0; i < 20; i++)
                    {
                        var    dist = int.Parse(distance.Distance.ToString());
                        Flight f    = new Flight();
                        f.FNo         = RandomFNo(route.RAirline);
                        f.RNo         = route.RNo;
                        f.AvailSeatsE = seatE;
                        f.AvailSeatsB = seatB;
                        f.AvailSeatsF = seatF;
                        f.BasePrice   = RandomBasePrice(dist);
                        var departureTime = RandomDepartureTime();
                        f.DepartureTime = departureTime;
                        var arrivalTime = DateTime.Parse(departureTime.ToString());
                        f.ArrivalTime = arrivalTime.AddMinutes(MinutesToAdd(dist));
                        f.FlightTime  = (f.ArrivalTime - f.DepartureTime).TotalHours;
                        FlightDAO.AddFlight(f);
                    }
                }
            }
        }
예제 #25
0
 ///// <summary>
 ///// Method fetches the Cancelled ticket corresponding to Cancellation Id
 ///// </summary>
 ///// <param name="id"></param>
 ///// <returns>Cancelled ticket</returns>
 public Cancellation GetCancellationById(int id)
 {
     try
     {
         using (AirlineDBEntities db = new AirlineDBEntities())
         {
             db.Configuration.LazyLoadingEnabled = false;
             Cancellation cancellation = db.Cancellations.Find(id);
             return(cancellation);
         }
     }
     catch (CancellationException)
     {
         throw new CancellationException("Id doesn't Exist");
     }
 }
        /// <summary>
        ///  Method to calculate the refund amount
        /// </summary>
        /// <param name="bookingId">Booking Id is the parameter which will fetch the total fare of ticket </param>
        /// <param name="flightStatus"></param>
        /// <returns>return refund amount</returns>

        private decimal CalculationOfRefund(int bookingId, int flightStatus)
        {
            using (AirlineDBEntities db = new AirlineDBEntities())
            {
                decimal refund = 0;
                if (flightStatus == 0)
                {
                    return(refund);
                }
                else
                {
                    refund = (db.Bookings.Find(bookingId).TicketFare * 75) / 100;
                }
                return(refund);
            }
        }
        ///// <summary>
        ///// Method delete the existing customer account
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        public bool DeleteCustomerById(int id)
        {
            AirlineDBEntities db = new AirlineDBEntities();
            {
                Customer customer = db.Customers.Find(id);
                db.Configuration.LazyLoadingEnabled = false;
                if (customer == null)
                {
                    return(false);;
                }

                db.Customers.Remove(customer);
                db.SaveChanges();

                return(true);
            }
        }
예제 #28
0
        ///// <summary>
        ///// Method delete the existing customer account
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        public bool DeleteCancellationById(int id)
        {
            using (AirlineDBEntities db = new AirlineDBEntities())
            {
                Cancellation cancellation = db.Cancellations.Find(id);
                db.Configuration.LazyLoadingEnabled = false;
                if (cancellation == null)
                {
                    return(false);;
                }

                db.usp_DeleteCancelledTicketById(id);
                db.SaveChanges();

                return(true);
            }
        }
예제 #29
0
        ///// <summary>
        ///// Method delete the existing booking account
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        public bool DeleteBookingBYId(int id)
        {
            using (AirlineDBEntities db = new AirlineDBEntities())
            {
                Booking booking = db.Bookings.Find(id);
                db.Configuration.LazyLoadingEnabled = false;
                if (booking == null)
                {
                    return(false);;
                }

                db.Bookings.Remove(booking);
                db.SaveChanges();

                return(true);
            }
        }
 /// <summary>
 /// Method create the new customer account
 /// </summary>
 /// <returns></returns>
 public bool AddCustomer(Customer customer)
 {
     AirlineDBEntities db = new AirlineDBEntities();
     {
         if ((db.Customers.Count(c => c.Email == customer.Email)) == 0)
         {
             db.Customers.Add(customer);
             db.SaveChanges();
             db.Configuration.LazyLoadingEnabled = false;
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }