コード例 #1
0
ファイル: RolesABM.aspx.cs プロジェクト: GeraElem/VS
        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;
            }
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        /// <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.");
            }
        }