Ejemplo n.º 1
0
 public bool insertFlight(AdminFlight inFlight)
 {
     using (var db = new WAPPContext())
     {
         try
         {
             var outFlight = new Flight();
             outFlight.TravelDate      = inFlight.TravelDate;
             outFlight.DepartureTime   = inFlight.DepartureTime;
             outFlight.Departure       = inFlight.Departure;
             outFlight.DestinationTime = inFlight.DestinationTime;
             outFlight.Destination     = inFlight.Destination;
             outFlight.ClassType       = inFlight.ClassType;
             outFlight.Airplane        = db.Airplanes.Find(inFlight.Airplane);
             outFlight.Seats           = outFlight.Airplane.Seats;
             outFlight.Price           = inFlight.Price;
             db.Flight.Add(outFlight);
             db.SaveChanges();
             return(true);
         }
         catch (Exception exception)
         {
             LogException(exception);
             return(false);
         }
     }
 }
Ejemplo n.º 2
0
        public AdminFlight oneFlight(int id)
        {
            var db = new WAPPContext();
            var e  = db.Flight.Find(id);

            if (e == null)
            {
                return(null);
            }
            else
            {
                var one = new AdminFlight()
                {
                    ID              = e.ID,
                    TravelDate      = e.TravelDate,
                    DepartureTime   = e.DepartureTime,
                    Departure       = e.Departure,
                    DestinationTime = e.DestinationTime,
                    Destination     = e.Destination,
                    ClassType       = e.ClassType,
                    Seats           = e.Seats,
                    Airplane        = e.Airplane.ID,
                    Price           = e.Price
                };

                return(one);
            }
        }
Ejemplo n.º 3
0
        public bool editEmployee(int id, Employee inEmp)
        {
            var db = new WAPPContext();

            try
            {
                var editEmp = db.Employee.Find(id);
                editEmp.FirstName   = inEmp.FirstName;
                editEmp.LastName    = inEmp.LastName;
                editEmp.PhoneNumber = inEmp.PhoneNumber;
                editEmp.EMail       = inEmp.EMail;
                editEmp.Address     = inEmp.Address;
                if (editEmp.ZipCode != inEmp.ZipCode)
                {
                    if (db.City.FirstOrDefault(z => z.ZipCode == inEmp.ZipCode) == null)
                    {
                        var newCity = new City()
                        {
                            ZipCode  = inEmp.ZipCode,
                            CityName = inEmp.City
                        };
                        db.City.Add(newCity);
                    }
                    editEmp.ZipCode = inEmp.ZipCode;
                }
                db.SaveChanges();
                return(true);
            }
            catch (Exception exception)
            {
                LogException(exception);
                return(false);
            }
        }
Ejemplo n.º 4
0
        public bool editFlight(int id, AdminFlight ef)
        {
            var db = new WAPPContext();

            try
            {
                var editf = db.Flight.Find(id);
                editf.TravelDate      = ef.TravelDate;
                editf.DepartureTime   = ef.DepartureTime;
                editf.Departure       = ef.Departure;
                editf.DestinationTime = ef.DestinationTime;
                editf.Destination     = ef.Destination;
                editf.ClassType       = ef.ClassType;
                editf.Airplane        = db.Airplanes.Find(ef.Airplane);
                editf.Price           = ef.Price;

                db.SaveChanges();
                return(true);
            }
            catch (Exception exception)
            {
                LogException(exception);
                return(false);
            }
        }
Ejemplo n.º 5
0
        public Employee searchEmployee(String uname)
        {
            var db = new WAPPContext();
            int id = db.Shadow.Where(w => w.Username.Equals(uname)).Select(s => s.Employee_ID).FirstOrDefault();

            return(oneEmployee(id));
        }
Ejemplo n.º 6
0
        public bool editCustomer(int id, AdminCustomer inCust)
        {
            var db = new WAPPContext();

            try
            {
                var editCust = db.Customer.Find(id);
                editCust.FirstName   = inCust.FirstName;
                editCust.LastName    = inCust.LastName;
                editCust.PhoneNumber = inCust.PhoneNumber;
                editCust.EMail       = inCust.EMail;
                editCust.Address     = inCust.Address;
                if (editCust.ZipCode != inCust.ZipCode)
                {
                    if (db.City.FirstOrDefault(z => z.ZipCode == inCust.ZipCode) == null)
                    {
                        var newCity = new City()
                        {
                            ZipCode  = inCust.ZipCode,
                            CityName = inCust.City
                        };
                        db.City.Add(newCity);
                    }
                    editCust.ZipCode = inCust.ZipCode;
                }
                db.SaveChanges();
                return(true);
            }
            catch (Exception exception)
            {
                LogException(exception);
                return(false);
            }
        }
Ejemplo n.º 7
0
        public AdminCustomer searchCustomer(int id)
        {
            var db = new WAPPContext();
            var e  = db.Customer.Find(id);

            if (e == null || e.ContactPerson == false)
            {
                return(null);
            }
            else
            {
                var one = new AdminCustomer()
                {
                    ID            = e.ID,
                    FirstName     = e.FirstName,
                    LastName      = e.LastName,
                    PhoneNumber   = e.PhoneNumber,
                    EMail         = e.EMail,
                    Address       = e.Address,
                    ZipCode       = e.ZipCode,
                    City          = e.Cities.CityName,
                    ContactPerson = e.ContactPerson
                };
                return(one);
            }
        }
Ejemplo n.º 8
0
        public AdminBooking oneBooking(int id)
        {
            var db = new WAPPContext();
            var s  = db.Booking.Find(id);

            if (s == null)
            {
                return(null);
            }
            else
            {
                var one = new AdminBooking()
                {
                    ContactName = s.Customers.FirstOrDefault().FirstName + " " + s.Customers.FirstOrDefault().LastName,
                    cID         = s.Customers.FirstOrDefault().ID,
                    ID          = s.ID,
                    RTString    = s.RoundTrip.ToString(),
                    Travelers   = s.Travelers,
                    TravelDate  = s.Flights.FirstOrDefault().TravelDate
                };

                String t = one.RTString;
                one.RTString = roundtripToString(t);

                return(one);
            }
        }
Ejemplo n.º 9
0
        public Employee oneEmployee(int id)
        {
            var db = new WAPPContext();
            var e  = db.Employee.Find(id);

            if (e == null)
            {
                return(null);
            }
            else
            {
                var one = new Employee()
                {
                    ID          = e.ID,
                    FirstName   = e.FirstName,
                    LastName    = e.LastName,
                    PhoneNumber = e.PhoneNumber,
                    EMail       = e.EMail,
                    Address     = e.Address,
                    ZipCode     = e.ZipCode,
                    City        = e.City.CityName,
                    Username    = e.Shadow.Username
                };

                return(one);
            }
        }
Ejemplo n.º 10
0
        public List <AdminAirplane> listAirplanes()
        {
            var db = new WAPPContext();
            List <AdminAirplane> all = db.Airplanes.Select(e => new AdminAirplane()
            {
                ID    = e.ID,
                Name  = e.Name,
                Seats = e.Seats
            }
                                                           ).ToList();

            return(all);
        }
Ejemplo n.º 11
0
        public List <AdminAirport> listAirports()
        {
            var db = new WAPPContext();
            List <AdminAirport> all = db.Airport.Select(e => new AdminAirport()
            {
                ID      = e.ID,
                Name    = e.Name,
                Country = e.Country
            }
                                                        ).ToList();

            return(all);
        }
Ejemplo n.º 12
0
        public List <int> getInfo()
        {
            List <int> info = new List <int>();
            var        db   = new WAPPContext();

            info.Add(db.Employee.Count());
            info.Add(db.Customer.Count());
            info.Add(db.Airplanes.Count());
            info.Add(db.Airport.Count());
            info.Add(db.Booking.Count());
            info.Add(db.Flight.Count());
            return(info);
        }
Ejemplo n.º 13
0
        public List <AdminCustomer> listContactPersons()
        {
            var db = new WAPPContext();
            List <AdminCustomer> contact = db.Customer.Where(w => w.ContactPerson == true).Select(e => new AdminCustomer()
            {
                ID            = e.ID,
                FirstName     = e.FirstName,
                LastName      = e.LastName,
                ContactPerson = e.ContactPerson
            }).ToList();

            return(contact);
        }
Ejemplo n.º 14
0
        public List <Employee> listEmployee()
        {
            var             db  = new WAPPContext();
            List <Employee> all = db.Employee.Select(e => new Employee()
            {
                ID        = e.ID,
                FirstName = e.FirstName,
                LastName  = e.LastName,
                Username  = e.Shadow.Username
            }
                                                     ).ToList();

            return(all);
        }
Ejemplo n.º 15
0
        public bool deleteAirport(int id)
        {
            var db = new WAPPContext();

            try
            {
                db.Airport.Remove(db.Airport.Find(id));
                db.SaveChanges();
                return(true);
            }
            catch (Exception exception)
            {
                LogException(exception);
                return(false);
            }
        }
Ejemplo n.º 16
0
        public bool deleteEmployee(int id)
        {
            var db = new WAPPContext();

            try
            {
                db.Shadow.Remove(db.Shadow.Find(id));
                db.Employee.Remove(db.Employee.Find(id));
                db.SaveChanges();
                return(true);
            }
            catch (Exception exception)
            {
                LogException(exception);
                return(false);
            }
        }
Ejemplo n.º 17
0
 public bool correctOldPassword(int id, String op)
 {
     using (var db = new WAPPContext())
     {
         var foundEmp = db.Shadow.FirstOrDefault(b => b.Employee_ID == id);
         if (foundEmp != null)
         {
             byte[] passwordForTest = Hash(op + foundEmp.Salt);
             bool   rightEmp        = foundEmp.Password.SequenceEqual(passwordForTest);
             return(rightEmp);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 18
0
 public bool getShadow(EmployeeLogin inEmp)
 {
     using (var db = new WAPPContext())
     {
         var foundEmp = db.Shadow.FirstOrDefault(b => b.Username == inEmp.Username);
         if (foundEmp != null)
         {
             byte[] passwordForTest = Hash(inEmp.Password + foundEmp.Salt);
             bool   rightEmp        = foundEmp.Password.SequenceEqual(passwordForTest);
             return(rightEmp);
         }
         else
         {
             return(false);
         }
     }
 }
Ejemplo n.º 19
0
        public bool editAirport(int id, AdminAirport inAir)
        {
            var db = new WAPPContext();

            try
            {
                var editAir = db.Airport.Find(id);
                editAir.Name    = inAir.Name;
                editAir.Country = inAir.Country;
                db.SaveChanges();
                return(true);
            }
            catch (Exception exception)
            {
                LogException(exception);
                return(false);
            }
        }
Ejemplo n.º 20
0
        public bool editAirplane(int id, AdminAirplane inAir)
        {
            var db = new WAPPContext();

            try
            {
                var editAir = db.Airplanes.Find(id);
                editAir.Name  = inAir.Name;
                editAir.Seats = inAir.Seats;
                db.SaveChanges();
                return(true);
            }
            catch (Exception exception)
            {
                LogException(exception);
                return(false);
            }
        }
Ejemplo n.º 21
0
 public bool insertEmployee(EmployeeRegister inEmp)
 {
     using (var db = new WAPPContext())
     {
         try
         {
             var    newEmp        = new Employee_DB();
             var    newShadow     = new Shadow_DB();
             string salt          = Salt();
             var    passwordNSalt = inEmp.Password + salt;
             byte[] passwordDB    = Hash(passwordNSalt);
             newEmp.FirstName   = inEmp.FirstName;
             newEmp.LastName    = inEmp.LastName;
             newEmp.Address     = inEmp.Address;
             newEmp.ZipCode     = inEmp.ZipCode;
             newEmp.EMail       = inEmp.EMail;
             newEmp.PhoneNumber = inEmp.PhoneNumber;
             newShadow.Username = inEmp.Username;
             newShadow.Password = passwordDB;
             newShadow.Salt     = salt;
             newEmp.Shadow      = newShadow;
             var existingZip = db.City.Find(inEmp.ZipCode);
             if (existingZip == null)
             {
                 var newCity = new City()
                 {
                     ZipCode  = inEmp.ZipCode,
                     CityName = inEmp.City
                 };
                 newEmp.City = newCity;
             }
             db.Employee.Add(newEmp);
             db.SaveChanges();
             return(true);
         }
         catch (Exception exception)
         {
             LogException(exception);
             return(false);
         }
     }
 }
Ejemplo n.º 22
0
        public List <AdminBooking> listBookings()
        {
            var db   = new WAPPContext();
            var list = db.Booking.Select(s => new AdminBooking()
            {
                ContactName = s.Customers.FirstOrDefault().FirstName + " " + s.Customers.FirstOrDefault().LastName,
                cID         = s.Customers.FirstOrDefault().ID,
                ID          = s.ID,
                RTString    = s.RoundTrip.ToString(),
                Travelers   = s.Travelers,
                TravelDate  = s.Flights.FirstOrDefault().TravelDate
            }).ToList();

            foreach (var i in list)
            {
                String t = i.RTString;
                i.RTString = roundtripToString(t);
            }
            return(list);
        }
Ejemplo n.º 23
0
 public bool insertAirport(AdminAirport inAir)
 {
     using (var db = new WAPPContext())
     {
         try
         {
             var newAir = new Airport();
             newAir.Name    = inAir.Name;
             newAir.Country = inAir.Country;
             db.Airport.Add(newAir);
             db.SaveChanges();
             return(true);
         }
         catch (Exception exception)
         {
             LogException(exception);
             return(false);
         }
     }
 }
Ejemplo n.º 24
0
 public bool insertAirplane(AdminAirplane inAir)
 {
     using (var db = new WAPPContext())
     {
         try
         {
             var newAir = new Airplane();
             newAir.Name  = inAir.Name;
             newAir.Seats = inAir.Seats;
             db.Airplanes.Add(newAir);
             db.SaveChanges();
             return(true);
         }
         catch (Exception exception)
         {
             LogException(exception);
             return(false);
         }
     }
 }
Ejemplo n.º 25
0
        public List <AdminViewFlight> listAllFlights()
        {
            var db = new WAPPContext();
            List <AdminViewFlight> all = db.Flight.Select(e => new AdminViewFlight()
            {
                ID              = e.ID,
                TravelDate      = e.TravelDate,
                DepartureTime   = e.DepartureTime,
                Departure       = db.Airport.Where(w => w.ID == e.Departure).Select(s => s.Name).FirstOrDefault(),
                DestinationTime = e.DestinationTime,
                Destination     = db.Airport.Where(w => w.ID == e.Destination).Select(s => s.Name).FirstOrDefault(),
                ClassType       = e.ClassType,
                Airplane        = e.Airplane.Name,
                Seats           = e.Seats,
                Price           = e.Price
            }
                                                          ).ToList();

            return(all);
        }
Ejemplo n.º 26
0
        public List <AdminViewFlight> customerBooking(int id)
        {
            var db = new WAPPContext();
            var cp = db.Customer.Find(id);
            List <AdminViewFlight> list = cp.Booking.Flights.Select(e => new AdminViewFlight()
            {
                ID              = e.ID,
                TravelDate      = e.TravelDate,
                DepartureTime   = e.DepartureTime,
                Departure       = db.Airport.Where(w => w.ID == e.Departure).Select(s => s.Name).FirstOrDefault(),
                DestinationTime = e.DestinationTime,
                Destination     = db.Airport.Where(w => w.ID == e.Destination).Select(s => s.Name).FirstOrDefault(),
                ClassType       = e.ClassType,
                Airplane        = e.Airplane.Name,
                Seats           = e.Seats,
                Price           = e.Price,
                BookingID       = id
            }).OrderBy(o => o.TravelDate).ThenBy(o => o.DepartureTime).ToList();

            return(list);
        }
Ejemplo n.º 27
0
        public AdminAirport oneAirport(int id)
        {
            var db = new WAPPContext();
            var e  = db.Airport.Find(id);

            if (e == null)
            {
                return(null);
            }
            else
            {
                var one = new AdminAirport()
                {
                    ID      = e.ID,
                    Name    = e.Name,
                    Country = e.Country
                };

                return(one);
            }
        }
Ejemplo n.º 28
0
        public AdminAirplane oneAirplane(int id)
        {
            var db = new WAPPContext();
            var e  = db.Airplanes.Find(id);

            if (e == null)
            {
                return(null);
            }
            else
            {
                var one = new AdminAirplane()
                {
                    ID    = e.ID,
                    Name  = e.Name,
                    Seats = e.Seats
                };

                return(one);
            }
        }
Ejemplo n.º 29
0
        public List <AdminCustomer> detailCustomer(int id)
        {
            var db = new WAPPContext();
            var CP = oneCustomer(id);
            var cp = db.Customer.Find(id);
            List <AdminCustomer> list = db.Customer.Where(w => w.Booking.ID == cp.Booking.ID &&
                                                          w.ContactPerson == false).Select(e => new AdminCustomer()
            {
                ID          = e.ID,
                FirstName   = e.FirstName,
                LastName    = e.LastName,
                PhoneNumber = e.PhoneNumber,
                EMail       = e.EMail,
                Address     = e.Address,
                ZipCode     = e.ZipCode,
                City        = e.Cities.CityName
            }).ToList();

            list.Insert(0, CP);
            return(list);
        }
Ejemplo n.º 30
0
        public List <AdminCustomer> getPassengers(int id)
        {
            var db = new WAPPContext();
            List <AdminCustomer> list = new List <AdminCustomer>();
            var flight = db.Flight.Find(id);

            foreach (var x in flight.Booking)
            {
                foreach (var y in x.Customers)
                {
                    var temp = new AdminCustomer()
                    {
                        ID            = y.ID,
                        FirstName     = y.FirstName,
                        LastName      = y.LastName,
                        ContactPerson = y.ContactPerson
                    };
                    list.Add(temp);
                }
            }
            return(list);
        }