Example #1
0
 public ActionResult Delete(int?id)
 {
     if (id != null)
     {
         Tareas TTareas = db.Tareas.Find(id);
         db.Tareas.Remove(TTareas);
         db.SaveChanges();
     }
     TempData["ShowModal1"] = "TareaEliminada";
     return(RedirectToAction("Index"));
 }
        public ActionResult Create([Bind(Include = "id,UserName,Rol,Name,BornDate,Password,LastLogin")] CT_Users cT_Users)
        {
            //VALIDA PRIMERO SI EL USUARIO EXISTE YA EN LA DB ANTES DE SALVAR Y EN CASO DE QUE YA EXISTA MUESTRA UN MENSAJE
            bool isViewNameInvalid = db.CT_Users.Any(v => v.UserName == cT_Users.UserName);

            if (isViewNameInvalid)
            {
                TempData["ShowModal1"] = 1;
                return(RedirectToAction("Index", cT_Users));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    if (cT_Users.Password != null && cT_Users.UserName != null)
                    {
                        //string Key = "1234567890abcdef"; //key must have 16 chars, other wise you may get error "key size in not valid".
                        //string Password2 = cT_Users.Password;
                        //EncryptionModel Crypt = new EncryptionModel();
                        //string EncryptedPassword = (string)Crypt.Crypt(CryptType.ENCRYPT, CryptTechnique.RIJ, Password2, Key);
                        string Password2 = cT_Users.Password;


                        cT_Users.Password = crypto.Encrypt(Password2);
                        cT_Users.BornDate = DateTime.Now.ToString();
                        db.CT_Users.Add(cT_Users);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["ShowModal1"] = "2";
                        return(RedirectToAction("Create", cT_Users));
                    }
                }
            }

            ViewBag.Rol = new SelectList(db.CT_Roles, "id", "Role", cT_Users.Rol);
            return(View(cT_Users));
        }
Example #3
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"));
                }
            }
        }