Exemple #1
0
        public ActionResult Crear(RolView RolView)
        {
            try
            {
                string nombreRol = Request.Form["txtNombreRol"];

                #region Verificar is ya existe el código del Rol
                RolRepository dr = new RolRepository();
                Rol           d  = dr.ObtenerPorNombre(nombreRol.Trim());
                if (d != null)
                {
                    RolView.Rol.Nombre = nombreRol;
                    RolView.Mensaje    = "El código del Rol ya existe";
                    return(View("Crear", RolView));
                }
                else
                {
                    d        = new Rol();
                    d.Nombre = nombreRol;
                    d        = dr.Actualizar(d);
                    if (d.Id == 0)
                    {
                        RolView.Mensaje = "Hubo un error al crear el Rol";
                        return(View("Crear", RolView));
                    }
                }
                #endregion
                RolView pp = new RolView();
                pp.Mensaje = "Rol Creado";
                return(View("Crear", pp));
            }
            catch (Exception ex)
            {
                return(View("Mensaje", new RolView {
                    Mensaje = ex.Message
                }));
            }
        }