Пример #1
0
        // GET: Administradores/Create
        public ActionResult Create()
        {
            if (Session["nombre_usuario"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            MenuEntities db_menu = new MenuEntities();

            ViewBag.menus = db_menu.manboss_permisos_menu.ToList();
            return(View());
        }
Пример #2
0
 public ActionResult Create([Bind(Include = "id,nombre,correo,usuario,contrasenia")] manboss_usuarios usuario_form)
 {
     if (Session["nombre_usuario"] == null)
     {
         return(RedirectToAction("Index", "Login"));
     }
     if (db.manboss_usuarios.Any(x => x.usuario == usuario_form.usuario))
     {
         ViewBag.Message     = "El usuario ya existe";
         ViewBag.nombre      = usuario_form.nombre;
         ViewBag.correo      = usuario_form.correo;
         ViewBag.contrasenia = usuario_form.contrasenia;
         MenuEntities db_menu = new MenuEntities();
         ViewBag.menus = db_menu.manboss_permisos_menu.ToList();
         return(View());
     }
     else
     {
         string contrasenia_form = usuario_form.contrasenia;
         string hash             = random_string(12);
         usuario_form.contrasenia = encrypt_pass(contrasenia_form + hash).ToLower();
         usuario_form.hash        = hash;
         usuario_form.rol         = 1;
         db.manboss_usuarios.Add(usuario_form);
         db.SaveChanges();
         //Agregar permisos
         NameValueCollection permisos_form = Request.Form;
         string           permisos_str     = permisos_form.AllKeys.ToDictionary(x => x, x => permisos_form[x]).Values.ToList().Last();
         string[]         arr         = permisos_str.Split(',');
         int[]            permisos    = Array.ConvertAll(arr, int.Parse);
         PermisosEntities db_permisos = new PermisosEntities();
         for (int i = 1; i <= 9; i++)
         {
             manboss_permisos permiso = new manboss_permisos();
             if (permisos.Contains(i))
             {
                 permiso.usuario = usuario_form.id;
                 permiso.menu    = i;
                 permiso.estado  = 1;
                 db_permisos.manboss_permisos.Add(permiso);
                 db_permisos.SaveChanges();
             }
             else
             {
                 permiso.usuario = usuario_form.id;
                 permiso.menu    = i;
                 permiso.estado  = 0;
                 db_permisos.manboss_permisos.Add(permiso);
                 db_permisos.SaveChanges();
             }
         }
         return(RedirectToAction("Index"));
     }
 }
Пример #3
0
        // GET: Administradores/Details/5
        public ActionResult Details(int?id)
        {
            if (Session["nombre_usuario"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            manboss_usuarios manboss_model = db.manboss_usuarios.Find(id);
            MenuEntities     db_menu       = new MenuEntities();

            ViewBag.menus = db_menu.manboss_permisos_menu.ToList();
            PermisosEntities db_permisos = new PermisosEntities();
            int usuario = (int)id;

            ViewBag.permisos = db_permisos.manboss_permisos.Where(x => x.usuario == usuario && x.estado == 1).Select(x => x.menu).ToList();
            return(View(manboss_model));
        }
Пример #4
0
 public BaseController()
 {
     db = new MenuEntities();
 }