Example #1
0
 private void Display()
 {
     context = new TravelExpertsContext();
     dataGridproduct.AutoGenerateColumns = false;
     dataGridproduct.DataSource          = context.Products.ToList();
     //Display();
 }
Example #2
0
        // Irada: Get all booking Details from DB
        public static List <BookingDetails> GetAllBookingDetails()
        {
            var context = new TravelExpertsContext();
            var listOfBookingDetails = context.BookingDetails.Include(b => b.Booking);

            return(listOfBookingDetails.ToList());
        }
Example #3
0
        //[Holly]
        public static IEnumerable <Packages> GetAll()
        {
            var context = new TravelExpertsContext();
            var pack    = context.Packages.ToList();

            return(pack);
        }
Example #4
0
        /// <summary>
        /// User is authenticated based on credentials and a user returned if exists or null if not.
        /// </summary>
        /// <param name="login">Login as string</param>
        /// <param name="pass">Password as string</param>
        /// <returns>A user data transfer object or null.</returns>
        public static CredentialModel Authenticate(string login, string pass)
        {
            // Initialize a user object with null reference
            CredentialModel user = null;

            // Connect to the db
            TravelExpertsContext context = new TravelExpertsContext();

            // Search db for Customer with matching credentials
            TravelExperts.Repository.Domain.Customer cust = context.Customers.SingleOrDefault(c =>
                                                                                              c.UserLogin == login);

            // If a match was found, create a DTO with needed information
            if (cust != null && // if the login matched in the db
                bcrypt.Verify(pass, cust.UserPass))    // and bcrypt confirms the password
            {
                user = new CredentialModel
                {
                    CustId    = cust.CustomerId,
                    Login     = cust.UserLogin,
                    FirstName = cust.CustFirstName
                };
            }

            return(user); //this will either be null or an object
        }
Example #5
0
 private void ProductFrm_Load(object sender, EventArgs e)
 {
     context = new TravelExpertsContext();
     dataGridproduct.AutoGenerateColumns = false;
     dataGridproduct.DataSource          = context.Products.ToList();
     Display();
 }
Example #6
0
        //Irada Shamilova: manager to pull Packages from the DB
        public static List <Packages> GetAllPackages()
        {
            var context      = new TravelExpertsContext();
            var packagesList = context.Packages;

            return(packagesList.ToList());
        }
Example #7
0
        /// <summary>
        /// Updates customer data in db based on corresponding customer object [Eric]
        /// </summary>
        /// <param name="editedCustomer"></param>
        public static void Update(Customer editedCustomer)
        {
            // Connect to db
            TravelExpertsContext db = new TravelExpertsContext();

            // Grab the original record
            Customer custRecord = db.Customers.Single(c => c.CustomerId == editedCustomer.CustomerId);

            // Assign updated props to the record
            custRecord.CustFirstName = editedCustomer.CustFirstName;
            custRecord.CustLastName  = editedCustomer.CustLastName;
            custRecord.CustAddress   = editedCustomer.CustAddress;
            custRecord.CustCity      = editedCustomer.CustCity;
            custRecord.CustProv      = editedCustomer.CustProv;
            custRecord.CustPostal    = editedCustomer.CustPostal;
            custRecord.CustCountry   = editedCustomer.CustCountry;
            custRecord.CustHomePhone = editedCustomer.CustHomePhone;
            custRecord.CustBusPhone  = editedCustomer.CustBusPhone;
            custRecord.CustEmail     = editedCustomer.CustEmail;
            custRecord.UserLogin     = editedCustomer.UserLogin;
            custRecord.UserPass      = editedCustomer.UserPass;

            // Update DB
            db.SaveChanges();
        }
Example #8
0
        /// <summary>
        /// Search the database for a customer with a given ID. [Eric]
        /// </summary>
        /// <param name="custId">Customer ID as an INT.</param>
        /// <returns>Matching customer object if one was found, null if no match.</returns>
        public static Customer FindById(int custId)
        {
            TravelExpertsContext db        = new TravelExpertsContext();
            Customer             matchCust = db.Customers.SingleOrDefault(c => c.CustomerId == custId);

            return(matchCust);
        }
Example #9
0
        public static void Add(Customer customer)
        {
            var db = new TravelExpertsContext();

            db.Customers.Add(customer);
            db.SaveChanges();
        }
        public static List <Packages> GetAll()
        {
            var context = new TravelExpertsContext();

            var packages = context.Packages.ToList();

            return(packages);
        }
Example #11
0
        //Irada Shamilova: manager to pull Current Packages from the DB based on current date
        public static List <Packages> GetAllCurrent()
        {
            var context      = new TravelExpertsContext();
            var packagesList = context.Packages.
                               Where(a => a.PkgStartDate > DateTime.Today);

            return(packagesList.ToList());
        }
Example #12
0
        // Irada - added a manager for FirstName grabber
        public static string GetUserName(string userName)
        {
            var    context       = new TravelExpertsContext();
            string userFirstName = context.Customers.Where(u => u.Username == userName).
                                   Select(u => u.CustFirstName).FirstOrDefault();

            return(userFirstName);
        }
Example #13
0
        // Irada: Get booking Details from DB by Booking ID
        public static List <BookingDetails> GetAllByBookingId(int id)
        {
            var context      = new TravelExpertsContext();
            var filteredList = context.BookingDetails.
                               Where(bid => bid.BookingId == id).
                               Include(b => b.Booking).ToList();

            return(filteredList);
        }
Example #14
0
        // Irada: Get all booking Details from DB by Customer ID from Bookings table (joining 2 tables)
        public static List <BookingDetails> GetAllByBCustomerId(int id)
        {
            var context = new TravelExpertsContext();
            var listOfBookingDetails = context.BookingDetails.
                                       Include(b => b.Booking).
                                       Where(c => c.Booking.CustomerId == id);

            return(listOfBookingDetails.ToList());
        }
Example #15
0
        /// <summary>
        /// Uses customer's past trips to recommend new trips for them, based on other customers who have gone on the same trips. [Eric]
        /// NOTE: This should eventually only return recommendations for trips with future start dates. We don't have the data for that yet, so ommitting it.
        /// </summary>
        /// <param name="custID">The customer's ID</param>
        /// <param name="numberOfRecs"> The number of recommendations to provide</param>
        /// <returns>A list of (numberOfRecs) recommendations</returns>
        public static IEnumerable <BookingDetails> GetRecommendations(int custID, int numberOfRecs)
        {
            //open the DB
            TravelExpertsContext db = new TravelExpertsContext();

            // Get a list of all trips the customer has been on
            // This is hard to quantify in the existing data, since no Packages have been ordered in the database (otherwise this method would search them).
            // And a single product/supplier can represent a wide array of things (Hotel - MARKETING AHEAD has a record for a past victoria, autstralia, and toronto trip)
            // As is, we'll use the Description field for booking details, which typically represents a whole booking
            List <string> previousCustTrips = db.Bookings                                              // Search bookings..
                                              .Include(booking => booking.BookingDetails)              // .. with associated booking details..
                                              .Where(booking => booking.CustomerId == custID)          // .. with the given customer ID ..
                                              .SelectMany(booking => booking.BookingDetails)           // .. grabbing all booking details in a flattened list ..
                                              .Where(bd => !(bd.Description.Contains("cancellation"))) // .. flesh out non-fun products ..
                                              .Select(bd => bd.Description)                            // .. getting just Descriptions ..
                                              .Distinct().ToList();                                    // .. removing duplicates and converting to list.

            // Next, find all customers who have been on the same trips
            List <int?> customersWhoTookSameTrip = db.Bookings                                                                              // Search bookings..
                                                   .Join(db.BookingDetails, b => b.BookingId, bd => bd.BookingId, (b, bd) => new { b, bd }) // .. join associated booking details..
                                                   .Where(join => join.b.CustomerId != custID && join.b.CustomerId != null)                 // ..excluding the customer themselves (and nulls) ..
                                                   .Where(join => previousCustTrips.Contains(join.bd.Description))                          // ..where the trip is among those that the customer has had..
                                                   .Select(join => (join.b.CustomerId))                                                     // .. grabbing only customers
                                                   .Distinct().ToList();

            // Finally, find all other trips those customers have been on, sorted by most popular
            IEnumerable <BookingDetails> recommendations = db.Bookings                                                                       // Search bookings..
                                                           .Include(booking => booking.BookingDetails)                                       // .. with associated booking details..
                                                           .Where(b => customersWhoTookSameTrip.Contains(b.CustomerId))                      // .. get all bookings of the chosen customers ...
                                                           .SelectMany(booking => booking.BookingDetails)                                    // .. grabbing all booking details in a flattened list ..
                                                           .Where(bd => bd.Description != "" && !previousCustTrips.Contains(bd.Description)) // .. removing trips the customer has already gone on and nulls..
                                                           .Where(bd => !(bd.Description.Contains("cancellation")))                          // .. flesh out non-fun products ..
                                                           .AsEnumerable().GroupBy(bd => bd.Description)                                     // .. group by description..
                                                           .OrderByDescending(bdGroup => bdGroup.Count())                                    // sort by the description with the most bookings (most popular)
                                                           .Select(bdGroup => bdGroup.First())                                               // we don't need the groups anymore, so we just take one instance of the booking detail
                                                           .Take(numberOfRecs);                                                              // Just need top X

            // This works for a demonstration, but with the data we have in the database we can't arrive at a proper future-trip recommendation.
            // This is because all existing customer records store trip details in bookingdetails (no customers have packages recorded),
            // while packages are the only entity with a description that can reflect a future trip.
            // On the other hand, the current method as-is could be a good means of gathering past data, to be used to inform future packages.

            //If we don't get enough recommendations, we pad them with the general most popular ones
            int recordsDearth = numberOfRecs - recommendations.ToList().Count;

            if (recordsDearth > 0)
            {
                // get the top x most popular trips
                var recPadding = GetMostPopularTrips(recordsDearth);

                // add them to the list so we reach the number of recommendations
                recommendations = recommendations.Concat(recPadding);
            }

            return(recommendations);
        }
Example #16
0
        ///// <summary>
        /// Find a certain customer using id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Customers object.</returns>
        public static Customers Find(int id)
        {
            var context = new TravelExpertsContext();

            // find the domain entity with this context that has the same id as
            // the entity passed
            var customer = context.Customers.
                           Include(agt => agt.Agent).
                           SingleOrDefault(ast => ast.CustomerId == id);

            return(customer);
        }
Example #17
0
        public static Bookings Find(int id)
        {
            var context = new TravelExpertsContext();

            var booking = context.Bookings
                          .Include(customer => customer.Customer)
                          .Include(trip => trip.TripType)
                          .Include(package => package.Package)
                          .Include(bookingDetail => bookingDetail.BookingDetails)
                          .SingleOrDefault(bk => bk.BookingId == id);

            return(booking);
        }
Example #18
0
        public static List <Bookings> GetAllBookingsByCustomer(int customerId)
        {
            var context  = new TravelExpertsContext();
            var bookings = context.Bookings
                           .Include(customer => customer.Customer)
                           .Include(trip => trip.TripType)
                           .Include(package => package.Package)
                           .Include(bookingDetail => bookingDetail.BookingDetails)
                           .Where(booking => booking.CustomerId == customerId)
                           .ToList();

            return(bookings);
        }
Example #19
0
        public static bool Exists(string username)
        {
            var db = new TravelExpertsContext();
            var custFromContext = db.Customers.SingleOrDefault(s => s.UserLogin == username);

            if (custFromContext == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        public static List <BookingDetails> GetAllBookingsDetailsByCustomer(int bookingId)
        {
            var context        = new TravelExpertsContext();
            var bookingDetails = context.BookingDetails
                                 .Include(itinerary => itinerary.ItineraryNo)
                                 .Include(tripStart => tripStart.TripStart)
                                 .Include(tripEnd => tripEnd.TripEnd)
                                 .Include(description => description.Description)
                                 .Include(destination => destination.Destination)
                                 .Include(price => price.BasePrice)
                                 .Where(bk => bk.BookingId == bookingId)
                                 .ToList();

            return(bookingDetails);
        }
Example #21
0
        /// <summary>
        /// Get the top X most popular trips from the database [Eric]
        /// </summary>
        /// <param name="numberOfRecs"></param>
        /// <returns></returns>
        public static IEnumerable <BookingDetails> GetMostPopularTrips(int numberOfRecs)
        {
            //open the DB
            TravelExpertsContext db = new TravelExpertsContext();

            // Get all booking details, group them by description, and order them by popularity
            IEnumerable <BookingDetails> mostPopular = db.Bookings                                    // Search bookings..
                                                       .Include(booking => booking.BookingDetails)    // .. with associated booking details..
                                                       .SelectMany(booking => booking.BookingDetails) // .. grabbing all booking details in a flattened list ..
                                                       .AsEnumerable().GroupBy(bd => bd.Description)  // .. group by description..
                                                       .OrderByDescending(list => list.Count())       // sort by the description with the most bookings (most popular)
                                                       .Select(list => list.First())                  // we don't need the groups anymore, so we just take one instance of the booking detail
                                                       .Take(numberOfRecs);                           // Just need top X

            return(mostPopular);
        }
Example #22
0
        //To display packages -- Holly
        public IActionResult Package()
        {
            var context = new TravelExpertsContext();
            var package = PackageManager.GetAll()
                          .Select(p => new PackageViewModel
            {
                PackageId    = p.PackageId,
                PkgName      = p.PkgName,
                PkgDesc      = p.PkgDesc,
                PkgStartDate = p.PkgStartDate,
                PkgEndDate   = p.PkgEndDate,
                PkgBasePrice = p.PkgBasePrice.ToString("c"),
            }).ToList();

            return(View(package));
        }
Example #23
0
 //[Ronnie]
 public IActionResult Record()
 {
     int custId  = Convert.ToInt32(User.Identity.Name);
     var context = new TravelExpertsContext();
     var record  = PackageManager.GetPackagesByCustId(custId)
                   .Select(b => new BookingModel
     {
         BookingId      = b.BookingId,
         BookingDate    = b.BookingDate,                               // cast is safe since if the customer booked it, it has a date
         BookingNo      = b.BookingNo,
         PackageName    = b.Package is null? null : b.Package.PkgName, //ternary check - if this booking has a package associated, we grab its name
         TravelerCount  = b.TravelerCount,
         CustomerId     = b.CustomerId,
         TripType       = b.TripType,
         BookingDetails = b.BookingDetails
     }).ToList();
Example #24
0
        //[Chris]
        public static List <Bookings> GetPackagesByCustId(int id)
        {
            var context = new TravelExpertsContext();
            //var pack = context.Bookings.Where(a => a.CustomerId ==  id).Include(a => a.Package).ToList();
            //return pack;

            var pack = context.Bookings
                       .Where(b => b.CustomerId == id)
                       .Include(b => b.Customer)
                       .Include(b => b.Package)
                       .Include(b => b.BookingDetails)
                       .ThenInclude(bd => bd.Fee)
                       .ToList();

            return(pack);
        }
Example #25
0
        public async Task <IActionResult> LogIn([Bind("CustEmail,PasswordNotHashed")] Customers customers)
        {
            TravelExpertsContext db = new TravelExpertsContext();
            var customer            = (from b in db.Customers
                                       where b.CustEmail.Equals(customers.CustEmail) && b.PasswordNotHashed.Equals(customers.PasswordNotHashed)
                                       select b).FirstOrDefault();

            if (customer == null)
            {
                return(View("~/Views/Home/Index.cshtml"));
            }
            else
            {
                HttpContext.Session.SetString("userEmail", customers.CustEmail);
                Debug.WriteLine("\n\n\n\n" + HttpContext.Session.GetString("userEmail"));
                return(Redirect("~/"));
            }
            return(Redirect("~/"));
            //return View(customers);
        }
Example #26
0
        /// <summary>
        /// Compares the login.
        /// </summary>
        /// <returns>The login.</returns>
        /// <param name="username">Username.</param>
        /// <param name="password">Password.</param>
        public static async Task <Customers> CompareLogin(string username, string password)
        {
            var context = new TravelExpertsContext();
            // use username to find a customer, if cannot find one, return null
            var cust = context.Customers.SingleOrDefault(c => c.Username == username);

            if (cust == null)
            {
                return(null);
            }
            // if find a customer, compare password
            if (cust.Password == password)
            {
                return(cust);
            }
            else
            {
                return(null);
            }
        }
Example #27
0
        ////
        /// <summary>
        /// Add a new customer to database.
        /// </summary>
        /// <param name="newCust">Customers object need to be added.</param>
        /// <returns>A bool indicate if added successfully.</returns>
        public static async Task <bool> Add(Customers newCust)
        {
            bool isSucceed = false;
            var  context   = new TravelExpertsContext();

            context.Customers.Add(newCust);
            try
            {
                int i = await context.SaveChangesAsync();

                if (i > 0)
                {
                    isSucceed = true;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(isSucceed);
        }
 private void Display()
 {
     context = new TravelExpertsContext();
     dataGridpakage.AutoGenerateColumns = false;
     dataGridpakage.DataSource          = context.Packages.ToList();
 }
Example #29
0
 public PackagesAPIController(TravelExpertsContext context)
 {
     _context = context;
 }
Example #30
0
 public CustomersController(TravelExpertsContext context)
 {
     _context = context;
 }