Beispiel #1
0
        public ActionResult Login(UserDataViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (ZOOM3Entities db = new ZOOM3Entities()){
                    var query = db.UserData.Where(e => e.US_Email.Equals(model.US_Email) && e.US_Password.Equals(model.US_Password)).FirstOrDefault();
                    if (query != null)
                    {
                        Session["UserId"]       = query.US_Id;
                        Session["UserName"]     = query.US_Name;
                        Session["UserLastname"] = query.US_LastName;
                        Session["PhotosNo"]     = query.Photo.Count();
                        Session["ProfilePhoto"] = query.US_HasImage;
                        var cartUnits = db.Cart.Where(u => u.C_US_Id == query.US_Id);
                        var not       = db.Notifications.Where(u => u.NOT_U_Id == query.US_Id && u.NOT_Leido == false);
                        Session["Cart"]          = cartUnits.Count();
                        Session["Notifications"] = not.Count();
                        Session["Rol"]           = query.US_ROL_Id;
                        ViewBag.noti             = not;
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Email o Contraseña Incorrectos");
                        return(View());
                    }
                }

                return(RedirectToAction("Index", "Home"));
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Login(UserDataViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (ZOOM3Entities db = new ZOOM3Entities()){
                   

                    var query = db.UserData.Where(e => e.US_Email.Equals(model.US_Email) && e.US_Password.Equals(model.US_Password)).FirstOrDefault();
                    if (query != null)
                    {
                        Session["UserId"] = query.US_Id;
                        Session["UserName"] = query.US_Name;
                        Session["UserLastname"] = query.US_LastName;
                        Session["PhotosNo"] = query.Photo.Count();
                        Session["ProfilePhoto"] = query.US_HasImage;
                        var cartUnits = db.Cart.Where(u => u.C_US_Id == query.US_Id);
                        var not = db.Notifications.Where(u => u.NOT_U_Id == query.US_Id && u.NOT_Leido == false);
                        Session["Cart"] = cartUnits.Count();
                        Session["Notifications"] = not.Count();
                        Session["Rol"] = query.US_ROL_Id;
                        ViewBag.noti = not;
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Email o Contraseña Incorrectos");
                        return View();
                    }
                }

                return RedirectToAction("Index", "Home");
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }