public ActionResult Edit([Bind(Include = "id,UserName,Rol,Name,BornDate,Password,LastLogin")] CT_Users cT_Users)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cT_Users).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Rol = new SelectList(db.CT_Roles, "id", "Role", cT_Users.Rol);
     return(View(cT_Users));
 }
Пример #2
0
        public ActionResult Authorize(CT_UsersCE userModel)
        {
            using (MedicalAppEntities1 db = new MedicalAppEntities1())
            {
                string EncryptedPassword = crypto.Encrypt(userModel.Password);

                var userDetails = db.CT_Users.Where(x => x.UserName == userModel.UserName && x.Password == EncryptedPassword).FirstOrDefault();
                if (userDetails == null)
                {
                    TempData["ShowModal"] = 1;
                    LoginModels rec = new LoginModels
                    {
                        msgColorTitle = "#e57373",
                        msgTitle      = "Incorrect Credentials",
                        msgBody       = "Wrong username or password."
                    };
                    ViewBag.Message = rec;


                    return(View("Index", userModel));
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        //UPDATE EN LASTLOGIN DEL USUARIO Y SALVA EN DB
                        CT_Users f = db.CT_Users.SingleOrDefault(x => x.UserName == userModel.UserName);
                        f.LastLogin       = DateTime.Now;
                        db.Entry(f).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    var TUsers = db.CT_Users.Where(x => x.UserName == userModel.UserName).FirstOrDefault();

                    Session["User"]         = userDetails.UserName;
                    Session["FullUserName"] = userDetails.Name;
                    Session["PKUser"]       = TUsers.id;


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