示例#1
0
 /// <summary>
 /// Retrieve customer by email
 /// </summary>
 /// <param name="email">email of customer</param>
 /// <returns>Customer object</returns>
 public static Customer GetCustomer(string email)
 {
     using (TravelExpertsEntities db = new TravelExpertsEntities())
     {
         return(db.Customers.SingleOrDefault(cust => cust.CustEmail == email));
     }
 }
        public ActionResult Login(LoginVM user)
        {
            // To acces data using LINQ
            TravelExpertsEntities userdt = new TravelExpertsEntities();

            if (ModelState.IsValid)
            {
                try
                {
                    using (SHA256 sha256Hash = SHA256.Create())
                    {
                        user.Password = PasswordHelper.GetHash(sha256Hash, user.Password);
                    }
                    var q = userdt.Customers.Where(m => m.UserName == user.UserName && m.Password == user.Password).ToList();

                    if (q.Count > 0)
                    {
                        if (q.FirstOrDefault() != null)
                        {
                            Session["CustomerId"] = q.FirstOrDefault().CustomerId;
                            Session["Username"]   = q.FirstOrDefault().UserName;
                            return(RedirectToAction("Index", "BookingsVM"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
                catch (Exception)
                {
                }
            }
            return(View(user));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var db = new TravelExpertsEntities();

            GridViewSuppliers.DataSource = db.Suppliers.ToList();
            GridViewSuppliers.DataBind();
        }
        /// <summary>
        /// Update customer with new email
        /// </summary>
        /// <param name="customer">updated customer</param>
        /// <returns>True on success, false otherwise</returns>
        public bool Update(Customer customer)
        {
            bool flag = false;

            // update in customers table
            using (TravelExpertsEntities db = new TravelExpertsEntities())
            {
                // get customer from Customer table by phone number
                var cust = db.Customers.SingleOrDefault(c => c.CustBusPhone == customer.CustBusPhone);
                if (cust != null) // found customer
                {
                    cust.CustEmail = customer.CustEmail;
                    db.SaveChanges();
                    flag = true;
                }
            }

            // update in accounts table
            using (AccountEntities db = new AccountEntities())
            {
                // get account
                var account = db.AspNetUsers.SingleOrDefault(accnt => accnt.PhoneNumber == customer.CustBusPhone);
                if (account != null) // found account
                {
                    if (flag)        // make sure customers table update succesfully
                    {
                        account.Email = customer.CustEmail;
                        db.SaveChanges();
                        return(true);
                    }
                }
                return(false); // one or both failed
            }
        }
示例#5
0
        public ActionResult LogIn(string userName, string password)
        {
            try
            {
                using (var context = new TravelExpertsEntities())
                {
                    var getUser = (from s in context.Customers where s.CustUsername == userName select s).FirstOrDefault();
                    if (getUser != null)
                    {
                        //var hashCode = Helper.GeneratePassword(10);   //get the salt from the database
                        //Password Hasing Process Call Helper Class Method
                        // var encodingPasswordString = Helper.EncodePassword(password, hashCode);  //has the input password again the salt stored in the database
                        var encodingPasswordString = Helper.HashEncrypt(password);  //encrypt pass word before checking database
                        Session["CustomerID"]   = getUser.CustomerId.ToString();
                        Session["CustomerName"] = getUser.CustFirstName;

                        //Check Login Detail User Name Or Password
                        var query = (from s in context.Customers where (s.CustUsername == userName) && s.CustPassword.Equals(encodingPasswordString) select s).FirstOrDefault();
                        if (query != null)
                        {
                            ViewBag.SuccessMessage = $"Login Completed with Customer ID of {Session["CustomerID"]}";
                        }
                        ViewBag.ErrorMessage = "Invallid User Name or Password";
                        return(View());
                    }
                    ViewBag.ErrorMessage = "Invallid User Name or Password";
                    return(View());
                }
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = " Some database error ocurred, Please try again";
                return(View());
            }
        }
示例#6
0
 /// <summary>
 /// Insert a customer into the Customer table of Travel Experts database
 /// </summary>
 /// <param name="customer"></param>
 public static void InsertCustomer(Customer customer)
 {
     using (TravelExpertsEntities db = new TravelExpertsEntities())
     {
         db.Customers.Add(customer);
         db.SaveChanges();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         var db = new TravelExpertsEntities();
         GridViewPackages.DataSource = db.Packages.ToList();
         GridViewPackages.DataBind();
     }
 }
示例#8
0
 public bool UsernameTaken(string username)
 {
     using (TravelExpertsEntities ent = new TravelExpertsEntities())
     {
         // Looks for the first or default instance of entered string
         var v = ent.CustomerRegistrationDatas.Where(a => a.Username == username).FirstOrDefault();
         // If the username exists (value is not null), return true
         return(v != null);
     }
 }
示例#9
0
        /// <summary>
        /// See if a customer exists in Customer table of Travel Experts Database
        ///     check against business phone number (assume unique)
        /// </summary>
        /// <param name="customer">Customer object to check</param>
        /// <returns>True if customer exists, false otherwise</returns>
        public static bool CustomerExists(Customer customer)
        {
            using (TravelExpertsEntities db = new TravelExpertsEntities())
            {
                // find customer by phone number
                var result = db.Customers.SingleOrDefault(cust => cust.CustBusPhone == customer.CustBusPhone);

                return(result != null);
            }
        }
示例#10
0
 /// <summary>
 /// Get all bookings linked to a customer
 /// </summary>
 /// <param name="customerId">Customer object</param>
 /// <returns>List of Bookings</returns>
 public static List <Booking> GetBookings(Customer customer)
 {
     using (TravelExpertsEntities db = new TravelExpertsEntities())
     {
         // get customer and their bookings
         Customer customerAndBookings = db.Customers.Include("Bookings")
                                        .Where(c => c.CustomerId == customer.CustomerId)
                                        .SingleOrDefault();
         return(customerAndBookings.Bookings.ToList());
     }
 }
示例#11
0
        /// <summary>
        /// Get fees associated to a booking detail
        /// </summary>
        /// <param name="detailId">booking detail identification</param>
        /// <param name="customer">Customer object</param>
        /// <returns>FEe object</returns>
        public static Fee GetFee(Customer customer, int detailId)
        {
            using (TravelExpertsEntities db = new TravelExpertsEntities())
            {
                // get customer with fee loaded
                var detail = db.BookingDetails.Include("Fee")
                             .Where(d => d.BookingDetailId == detailId)
                             .SingleOrDefault();

                return(detail.Fee);
            }
        }
示例#12
0
        /// <summary>
        /// Get Booking details of a booking
        /// </summary>
        /// <param name="bookingNo">Booking number</param>
        /// <param name="customer">Customer</param>
        /// <returns>List of booing details</returns>
        public static List <BookingDetail> GetBookingDetails(Customer customer, string bookingNo)
        {
            using (TravelExpertsEntities db = new TravelExpertsEntities())
            {
                // get customer with booking details loaded
                var withDetails = db.Customers.Include("Bookings.BookingDetails")
                                  .Where(c => c.CustomerId == customer.CustomerId)
                                  .SingleOrDefault();
                // get booking
                Booking booking = withDetails.Bookings.Where(b => b.BookingNo == bookingNo).SingleOrDefault();

                return(booking.BookingDetails.ToList());
            }
        }
示例#13
0
        public ActionResult Registration(Customer customer)
        {
            try
            {
                using (var context = new TravelExpertsEntities())
                {
                    var    chkUser      = (from s in context.Customers where s.CustUsername == customer.CustUsername select s).FirstOrDefault();
                    string name         = customer.CustFirstName; //get the customer first name from the customer object
                    string username     = customer.CustUsername;  //get the customer username from the customer object
                    string userPassword = customer.CustPassword;  //get the customer password from the customer object



                    if (chkUser == null)
                    {
                        //var keyNew = Helper.GenerateSalt(10);  //generate salt
                        //var password = Helper.EncodePassword(customer.CustPassword, keyNew);
                        var password = Helper.HashEncrypt(customer.CustPassword);

                        customer.CustPassword = password;
                        //create a salt table in the database and save the kewNew
                        context.Customers.Add(customer);
                        context.SaveChanges();

                        //call the SendEmail method
                        //send registration email to new customer
                        SendEmail(customer.CustEmail, "Registration Confirmed",
                                  $"<p>Hi {name},<br/>Thank you for registering with Travel Experts where you explore, journey, discover and adventure.<br/>" +
                                  $"Your username: {username}<br/> Your password: {userPassword}<br/> <br/> Travel Experts</p>");

                        ModelState.Clear();

                        ViewBag.SuccessMessage = "Registration Successful!\nA Confirmation email has been sent to your Email address.";
                        //return RedirectToAction("LogIn", "Login");
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Username Already Exists! Please enter a new username.";
                    }

                    return(View());
                }
            }
            catch (Exception e)
            {
                ViewBag.ErrorMessage = "Some exception occured" + e;
                return(View());
            }
        }
 /// <summary>
 /// Update cusomter with new home phone number
 /// </summary>
 /// <returns>true on success, false otherwise</returns>
 /// <param name="customer">updated customer</param>
 public bool Update(Customer customer)
 {
     using (TravelExpertsEntities db = new TravelExpertsEntities())
     {
         // get customer from Customer table by phone number
         var cust = db.Customers.SingleOrDefault(c => c.CustBusPhone == customer.CustBusPhone);
         if (cust != null) // found customer
         {
             cust.CustHomePhone = customer.CustHomePhone;
             db.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
示例#15
0
 public bool EmailTaken(string emailID)
 {
     using (TravelExpertsEntities ent = new TravelExpertsEntities())
     {
         // Looks for the first or default instance of entered string
         var v = ent.CustomerRegistrationDatas.Where(a => a.CustEmail == emailID).FirstOrDefault();
         // If the entered email was null, allow it by returning false, "email is not taken"
         if (emailID == null)
         {
             return(false);
         }
         // If the email exists (value is not null), return true
         return(v != null);
     }
 }
示例#16
0
 /// <summary>
 /// Update a customer's email in Customers table
 /// </summary>
 /// <param name="customer">Customer to update</param>
 /// <returns>True on success, false otherwise</returns>
 public static bool UpdateCustomerUserName(Customer newCustomer)
 {
     // update customer table
     using (TravelExpertsEntities db = new TravelExpertsEntities())
     {
         // get customer from Customer table by phone number
         var customer = db.Customers.SingleOrDefault(cust => cust.CustBusPhone == newCustomer.CustBusPhone);
         if (customer != null) // found customer
         {
             customer.UserName = newCustomer.UserName;
             db.SaveChanges();
             return(true);
         }
         return(false); // one or both failed
     }
 }
 /// <summary>
 /// Update customer with new address
 /// </summary>
 /// <param name="customer">updated customer</param>
 /// <returns>True on success, false otherwise</returns>
 public bool Update(Customer customer)
 {
     using (TravelExpertsEntities db = new TravelExpertsEntities())
     {
         // get customer from Customer table by phone number
         var cust = db.Customers.SingleOrDefault(c => c.CustBusPhone == customer.CustBusPhone);
         if (cust != null) // found customer
         {
             cust.CustAddress = customer.CustAddress;
             cust.CustCity    = customer.CustCity;
             cust.CustProv    = customer.CustProv;
             cust.CustPostal  = customer.CustPostal;
             cust.CustCountry = customer.CustCountry;
             db.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
        // GET: BookingsVM

        public ActionResult Index()
        {
            TravelExpertsEntities bks            = new TravelExpertsEntities();
            List <BookingsVM>     BookingsVMList = new List <BookingsVM>();

            var bookingList = (from b in bks.Bookings
                               join c in bks.Customers on b.CustomerId equals c.CustomerId
                               join p in bks.Packages on b.PackageId equals p.PackageId
                               join d in bks.BookingDetails on b.BookingId equals d.BookingId
                               select new { b.CustomerId, b.BookingDate, b.BookingNo, b.TravelerCount, c.CustFirstName, c.CustLastName, p.PkgName, p.PkgBasePrice, d.BasePrice, d.Description }).ToList();

            foreach (var item in bookingList)

            {
                BookingsVM objcvm = new BookingsVM(); // ViewModel

                objcvm.CustomerId = item.CustomerId;

                objcvm.BookingDate = item.BookingDate;

                objcvm.BookingNo = item.BookingNo;

                objcvm.TravelerCount = item.TravelerCount;

                objcvm.CustFirstName = item.CustFirstName;

                objcvm.CustLastName = item.CustLastName;

                objcvm.PkgName = item.PkgName;

                objcvm.PkgBasePrice = item.PkgBasePrice;

                objcvm.BasePrice = item.BasePrice;

                objcvm.Description = item.Description;

                BookingsVMList.Add(objcvm);
            }

            return(View(BookingsVMList));
        }