private void Display() { context = new TravelExpertsContext(); dataGridproduct.AutoGenerateColumns = false; dataGridproduct.DataSource = context.Products.ToList(); //Display(); }
// 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()); }
//[Holly] public static IEnumerable <Packages> GetAll() { var context = new TravelExpertsContext(); var pack = context.Packages.ToList(); return(pack); }
/// <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 }
private void ProductFrm_Load(object sender, EventArgs e) { context = new TravelExpertsContext(); dataGridproduct.AutoGenerateColumns = false; dataGridproduct.DataSource = context.Products.ToList(); Display(); }
//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()); }
/// <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(); }
/// <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); }
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); }
//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()); }
// 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); }
// 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); }
// 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()); }
/// <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); }
///// <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); }
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); }
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); }
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); }
/// <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); }
//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)); }
//[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();
//[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); }
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); }
/// <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); } }
//// /// <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(); }
public PackagesAPIController(TravelExpertsContext context) { _context = context; }
public CustomersController(TravelExpertsContext context) { _context = context; }