public ActionResult Login(string user, string pass)
        {
            try
            {
                using (Models.ArandaDBEntities db = new Models.ArandaDBEntities())
                {
                    var GetUser = (from usr in db.a_user
                                   where usr.usr_name == user.Trim() &&
                                   usr.usr_password == pass.Trim()
                                   select usr).FirstOrDefault();

                    if (GetUser == null)
                    {
                        ViewBag.Error = "Credenciales Incorrectas";
                        return(View());
                    }

                    Session["User"] = GetUser;
                }
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View());
            }
        }
 public ActionResult GuardarNuevo(a_user usuario)
 {
     using (Models.ArandaDBEntities db = new Models.ArandaDBEntities())
     {
         if (usuario != null)
         {
             db.a_user.Add(usuario);
             db.SaveChanges();
             return(RedirectToAction("../Users/Users"));
         }
         return(View());
     }
 }
Beispiel #3
0
        // GET: Users
        public ActionResult Users()
        {
            var User = (a_user)Session["User"];

            if (User != null)
            {
                TempData["rol"] = User.role_fk;
            }

            using (Models.ArandaDBEntities db = new Models.ArandaDBEntities())
            {
                var GetUsers = (from usr in db.a_user
                                select usr);

                return(View(GetUsers.ToList()));
            }
        }
        // GET: CrearUsuario
        public ActionResult Crear()
        {
            var User = (a_user)Session["User"];

            if (User != null)
            {
                TempData["rol"] = User.role_fk;
            }

            using (Models.ArandaDBEntities db = new Models.ArandaDBEntities())
            {
                var GetRoles = (from rol in db.a_role
                                select rol);
                ViewBag.listaRoles = GetRoles.ToList();
                return(View());
            }
        }
 public ActionResult Editar(a_user usuario)
 {
     using (Models.ArandaDBEntities db = new Models.ArandaDBEntities())
     {
         int id      = (int)TempData["UserID"];
         var GetUser = db.a_user.Where(x => x.id == id).FirstOrDefault();
         if (GetUser != null)
         {
             GetUser.fname           = usuario.fname;
             GetUser.lname           = usuario.lname;
             GetUser.usr_name        = usuario.usr_name;
             GetUser.usr_password    = usuario.usr_password;
             GetUser.address         = usuario.address;
             GetUser.phone           = usuario.phone;
             GetUser.email           = usuario.email;
             db.Entry(GetUser).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
         return(RedirectToAction("../Users/Users"));
     }
 }
        // GET: EditarUsuario
        public ActionResult Editar(int?id)
        {
            var User = (a_user)Session["User"];

            if (User != null)
            {
                TempData["rol"] = User.role_fk;
            }

            using (Models.ArandaDBEntities db = new Models.ArandaDBEntities())
            {
                var GetUser = db.a_user.Where(x => x.id == id).FirstOrDefault();

                if (GetUser != null)
                {
                    TempData["UserID"] = id;
                    TempData.Keep();
                    return(View(GetUser));
                }
                return(View());
            }
        }
Beispiel #7
0
        // GET: EliminarUsuario
        public ActionResult Eliminar(int?id)
        {
            var User = (a_user)Session["User"];

            if (User != null)
            {
                TempData["rol"] = User.role_fk;
            }

            using (Models.ArandaDBEntities db = new Models.ArandaDBEntities())
            {
                if (id > 0)
                {
                    var usuarioId = db.a_user.Where(x => x.id == id).FirstOrDefault();
                    if (usuarioId != null)
                    {
                        db.Entry(usuarioId).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                }
            }
            return(RedirectToAction("../Users/Users"));
        }