コード例 #1
0
 public RentalsController()
 {
     _context      = new ApplicationDbContext();
     _rentalsDal   = new RentalsDal(_context);
     _customersDal = new CustomersDal(_context);
     _moviesDal    = new MoviesDal(_context);
 }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: gingos/MVCstore
        /// <summary>
        /// Action Handles new customer Registration
        /// </summary>
        /// <returns></returns>
        public ActionResult SubmitRegister()
        {
            if (ModelState.IsValid)
            {
                Customers cust = new Customers();

                cust.FirstName    = Request.Form["FirstName"];
                cust.LastName     = Request.Form["LastName"];
                cust.Email        = Request.Form["Email"];
                cust.PasswordHash = Request.Form["PasswordHash"];
                cust.PhoneNumber  = Request.Form["PhoneNumber"];
                cust.MD5Hash();
                custDal = new CustomersDal();
                custDal.Customers.Add(cust);
                custDal.SaveChanges();

                return(View("Login"));
            }
            else
            {
                return(View("Register", new Customers()));
            }
        }
コード例 #3
0
        public ActionResult SubmitR()
        {
            string Email    = Request.Form["Email"];
            string Password = Request.Form["Password"];

            if (ModelState.IsValid)
            {
                CustomersDal     custDal = new CustomersDal();
                List <Customers> custo   = (from x in custDal.customers where x.Email.Contains(Email) select x).ToList <Customers>();

                if (custo.Count > 0)
                {
                    // existing email
                    TempData["Error1"] = "The Email already exist";
                    return(RedirectToAction("Register", "Home"));
                }
                else
                {
                    Customers cust = new Customers();
                    cust.FirstName        = Request.Form["FirstName"];
                    cust.LastName         = Request.Form["LastName"];
                    cust.Email            = Request.Form["Email"];
                    cust.CustomerPassword = Request.Form["CustomerPassword"];
                    cust.PhoneNumber      = Request.Form["PhoneNumber"];
                    custDal = new CustomersDal();
                    custDal.customers.Add(cust);
                    custDal.SaveChanges();

                    return(View("Login"));
                }
            }
            else
            {
                return(View("Register", new Customers()));
            }
        }
コード例 #4
0
        public ActionResult SubmitL()
        {
            string Email    = Request.Form["Email"];
            string Password = Request.Form["Password"];

            if (Request.Form["EmpRadio"] != null)
            {
                EmployeeDal     empDal = new EmployeeDal();
                List <Employee> emp    = (from x in empDal.employee where x.EmployeeEmail.Contains(Email) select x).ToList <Employee>();
                //List<Employee> emp = empDal.employee.Where(e => e.EmployeeEmail.Equals(Email)).ToList();
                if (emp.Count == 0)
                {
                    // no such email in database
                    TempData["Error"] = "Incorrect Email";
                    return(RedirectToAction("Login", "Home"));
                }
                else
                {
                    //Employee email and password match
                    Employee e = emp[0];
                    if (Password.Equals(e.EmployeePassword))
                    {
                        Session["UserId"]   = emp[0].EmployeeId;
                        Session["UserName"] = emp[0].EmployeeName;
                        Session["type"]     = "Employee";
                        return(View("EmployeeView"));
                    }
                }
            }
            else if (Request.Form["EmpRadio2"] != null)
            {
                if (Request.Form["EmpRadio2"] != null)
                {
                    return(View("CustomersView"));
                }

                else
                {
                    ////search for match in Customers DAL
                    Customers temp = new Customers();
                    temp.Email            = Request.Form["Email"];
                    temp.CustomerPassword = Request.Form["Password"];

                    CustomersDal     custDal = new CustomersDal();
                    List <Customers> cust    = custDal.customers.Where(c => c.Email.Equals(temp.Email)).ToList();
                    if (cust.Count == 0)
                    {
                        TempData["fail"] = "Incorrect Input";
                        return(RedirectToAction("Login", "Home"));
                    }
                    else
                    {
                        //found customer email match, try password match
                        Customers c = cust[0];
                        if (c.CustomerPassword.Equals(temp.CustomerPassword))
                        {
                            Session["type"]     = "Customer";
                            Session["UserName"] = cust[0].FirstName;
                            return(View("CustomersView"));
                        }
                        else
                        {
                            // password doesn't match email
                            TempData["fail"] = "Incorrect Detail Input";
                            return(RedirectToAction("Login", "Home"));
                        }
                    }
                }
            }

            return(View("Enter"));
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: gingos/MVCstore
        /// <summary>
        /// Action handles login: accesses DB and verifies credentials
        /// </summary>
        /// <returns></returns>
        public ActionResult SubmitLogin()
        {
            string logEmail    = Request.Form["logEmail"];
            string logPassword = Request.Form["logPassword"];

            if (Request.Form["typeSwitch"] != null)
            {
                //search for match in Employees DAL

                EmployeeDAL     empDal  = new EmployeeDAL();
                List <Employee> empList = empDal.employees.Where(e => e.EmployeeEmail.Equals(logEmail)).ToList();
                if (empList.Count == 0)
                {
                    // no such email in database
                    TempData["fail"] = "Incorrect Detail Input";
                    return(RedirectToAction("Login", "Home"));
                }
                else
                {
                    //found employee email match, try password match
                    Employee e = empList[0];
                    if (logPassword.Equals(e.EmployeePassword))
                    {
                        Session["UserID"] = empList[0].EmployeeNumber;
                        Session["type"]   = "Employee";
                        return(View("IndexEmployees"));
                    }
                    else
                    {
                        //password doesn't match email
                        TempData["fail"] = "Incorrect Detail Input";
                        return(RedirectToAction("Login", "Home"));
                    }
                }
            }
            else
            {
                ////search for match in Customers DAL
                Customers temp = new Customers();
                temp.Email        = logEmail;
                temp.PasswordHash = logPassword;
                temp.MD5Hash();
                custDal = new CustomersDal();
                List <Customers> custList = custDal.Customers.Where(c => c.Email.Equals(temp.Email)).ToList();
                if (custList.Count == 0)
                {
                    TempData["fail"] = "Incorrect Detail Input";
                    return(RedirectToAction("Login", "Home"));
                }
                else
                {
                    //found customer email match, try password match
                    Customers c = custList[0];
                    if (c.PasswordHash.Equals(temp.PasswordHash))
                    {
                        Session["UserID"] = c.CustomerNumber;
                        Session["type"]   = "Customer";
                        return(View("IndexCustomers"));
                    }
                    else
                    {
                        // password doesn't match email
                        TempData["fail"] = "Incorrect Detail Input";
                        return(RedirectToAction("Login", "Home"));
                    }
                }
            }
        }