Exemplo n.º 1
0
        public ActionResult ManCustLogin(Customer cust, string returnUrl)
        {
            //string returnUrl = "";
            //int id = (int)TempData["id"];
            //var cust = Database.Customers.Where(u => (u.custID == id)).FirstOrDefault();
            var model = Database.Accounts.Where(b => (b.userName == cust.userName)).FirstOrDefault();

            // Lets first check if the Model is valid or not
            //if (ModelState.IsValid)
            //{
                using (EasyHouseEntities1 entities = new EasyHouseEntities1())
                {
                    string username = model.userName;
                    string password = model.password;

                    // Now if our password was enctypted or hashed we would have done the
                    // same operation on the user entered password here, But for now
                    // since the password is in plain text lets just authenticate directly

                    var userValid = entities.Accounts.FirstOrDefault(user => user.userName == username && user.password == password);

                    // User found in the database
                    if (userValid != null)
                    {
                        Session["username"] = username.ToString();
                        registerLogin(username, userValid.role);

                        //FormsAuthentication.SetAuthCookie(username, false);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        else if (userValid.role == "unassigned")
                        {
                            return RedirectToAction("UnassignedCustLanding", "Home", model);
                        }
                        else
                        {
                            return RedirectToAction("CustLanding", "Home", model);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            //}

            // If we got this far, something failed, redisplay form
            return View("CustLanding", "Home", model);
        }
Exemplo n.º 2
0
 public ActionResult CustCreate(Customer item)
 {
     if (ModelState.IsValid)
     {
         Database.Customers.Add(item);
         Database.SaveChanges();
         return RedirectToAction("Login", "Account");
     }
     else
         return View("CustCreate", item);
 }
Exemplo n.º 3
0
        public ActionResult CustEdit(int id, Customer item)
        {
            if (item.active)
            {
                var model = Database.Accounts.Where(c => (c.userName == item.userName)).FirstOrDefault();
                model.role = "customer";
            }
            else
            {
                var model = Database.Accounts.Where(c => (c.userName == item.userName)).FirstOrDefault();
                model.role = "unassigned";
            }
            if (ModelState.IsValid)
            {
                var dbItem = Database.Customers.Find(id);
                TryUpdateModel(dbItem);

                Database.SaveChanges();
                return RedirectToAction("Customer");
            }
            else
                return View(item);
        }
Exemplo n.º 4
0
 public ActionResult CustCreate(string username)
 {
     var model = new Customer();
     model.userName = username;
     return View(model);
 }