public static void GuardarLogInLog(User user)
        {
            using (var db = new SisparkModel())
            {
            var sysUserLog = db.UserLog.Create();
            sysUserLog.UserId = user.UserId;
            sysUserLog.FechaYHora = DateTime.Now;
            sysUserLog.Accion = "Login";

            db.UserLog.Add(sysUserLog);
            db.SaveChanges();
            }
        }
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                var crypto = new SimpleCrypto.PBKDF2();

                var encrpPass = crypto.Compute(user.Clave);

                user.Clave = encrpPass;
                user.ClaveSalt = crypto.Salt;

                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();

                return RedirectToAction("Index");
            }
            ViewBag.UserTypeId = new SelectList(db.Usertype, "usertypeid", "description", user.UserTypeId);
            return View(user);
        }
        public ActionResult LogIn(User user)
        {
            if (IsValid(user.Usuario, user.Clave))
            {

                FormsAuthentication.SetAuthCookie(user.Usuario, false);
                return RedirectToAction("Index", "Tickets");
            }
            else
            {
                ModelState.AddModelError("", "Error en datos de inicio de sesión");
            }

            return View();
        }
        public ActionResult Registration(User user)
        {
            if (ModelState.IsValid)
            {

                var useridentico = db.User.FirstOrDefault(u => u.Usuario == user.Usuario);
                if (useridentico == null)
                {

                    var crypto = new SimpleCrypto.PBKDF2();

                    var encrpPass = crypto.Compute(user.Clave);

                    user.Clave = encrpPass;
                    user.ClaveSalt = crypto.Salt;

                    db.User.Add(user);
                    db.SaveChanges();

                    return RedirectToAction("Index", "Users");
                }
                else
                {
                    ModelState.AddModelError("",String.Concat("Ya hay un usuario '",useridentico.Usuario,"'"));
                }

            }
            else
            {
                ModelState.AddModelError("", "Datos de login erroneos");
            }
            ViewBag.UserTypeId = new SelectList(db.Usertype, "usertypeid", "description", user.UserTypeId);
            return View(user);
        }