示例#1
0
        protected void btnAddRol_Click(object sender, EventArgs e)
        {
            try
            {
                Roles oRol;

                if (!string.IsNullOrEmpty(this.lblRolId.Text))
                {
                    oRol = new Admin().GetRol(int.Parse(this.lblRolId.Text));
                    oRol.Descripcion = this.txtRolDesc.Text;
                    oRol.Activo = this.ddlActivo.SelectedValue == "1" ? true : false;

                    new Admin().UpdateRol(oRol);
                }
                else
                {
                    oRol = new Roles
                        {
                            Descripcion = this.txtRolDesc.Text,
                            Activo = this.ddlActivo.SelectedValue == "1" ? true : false
                        };

                    new Admin().AddRol(oRol);
                }

                this.FillGridRol();
            }
            catch (Exception ex)
            {
                this.lblErrorRol.Text = ex.Message;
            }
        }
        /// <summary>
        /// Ensures that the principal represents a user with the specified role.
        /// </summary>
        public void EnsureUserInRole(Roles role)
        {
            bool isInRole = CheckUserInRole(role);

            if (!isInRole)
            {
                string message = string.Format("The user is not associated with the {0} role.", role);
                throw new SecurityException(message);
            }
        }
        /// <summary>
        /// Checks that the principal represents a user with the specified role.
        /// </summary>
        public bool CheckUserInRole(Roles role)
        {
            var userId = userContext.UserId.ToString();

            return context.CompetentAuthorityUsers.Single(u => u.UserId == userId).Role.Name == role.ToString();
        }
示例#4
0
文件: MenusRoles.cs 项目: GeraElem/VS
        private void FixupRoles(Roles previousValue)
        {
            if (previousValue != null && previousValue.MenusRoles.Contains(this))
            {
                previousValue.MenusRoles.Remove(this);
            }

            if (Roles != null)
            {
                if (!Roles.MenusRoles.Contains(this))
                {
                    Roles.MenusRoles.Add(this);
                }
                if (RolId != Roles.RolId)
                {
                    RolId = Roles.RolId;
                }
            }
            else if (!_settingFK)
            {
                RolId = null;
            }
        }
示例#5
0
文件: Admin.cs 项目: GeraElem/VS
        public void UpdateRol(Roles rol)
        {
            using (var context = new QuirofanoEntities())
            {
                Roles rol2 = context.Roles.First(i => i.RolId == rol.RolId);

                rol2.Descripcion = rol.Descripcion;
                rol2.Activo = rol.Activo;

                context.SaveChanges();
            }
        }
示例#6
0
文件: Admin.cs 项目: GeraElem/VS
        public void AddRol(Roles rol)
        {
            try
            {
                using (var context = new QuirofanoEntities())
                {
                    context.Roles.AddObject(rol);

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException.Message.Contains("23505"))
                    throw new Exception("Error: no puede asignar dos roles con el mismo nombre.");
            }
        }