Beispiel #1
0
        public async Task <IActionResult> DeleteClaim(int claimid, [Bind("ClaimType", "ClaimValue")] EditClaimModel Input)
        {
            var claim = _context.RoleClaims.Where(c => c.Id == claimid).FirstOrDefault();

            if (claim == null)
            {
                return(NotFound("Không tìm thấy role"));
            }

            var role = await _roleManager.FindByIdAsync(claim.RoleId);

            if (role == null)
            {
                return(NotFound("Không tìm thấy role"));
            }
            Input.role = role;
            if (!ModelState.IsValid)
            {
                return(View(Input));
            }
            if (_context.RoleClaims.Any(c => c.RoleId == role.Id && c.ClaimType == Input.ClaimType && c.ClaimValue == Input.ClaimValue && c.Id != claim.Id))
            {
                ModelState.AddModelError(string.Empty, "Claim này đã có trong role");
                return(View(Input));
            }


            await _roleManager.RemoveClaimAsync(role, new Claim(claim.ClaimType, claim.ClaimValue));

            StatusMessage = "Vừa xóa claim";


            return(RedirectToAction("Edit", new { roleid = role.Id }));
        }
Beispiel #2
0
        public async Task <IActionResult> EditRoleClaim(int claimid)
        {
            var claim = _context.RoleClaims.Where(c => c.Id == claimid).FirstOrDefault();

            if (claim == null)
            {
                return(NotFound("Không tìm thấy role"));
            }

            var role = await _roleManager.FindByIdAsync(claim.RoleId);

            if (role == null)
            {
                return(NotFound("Không tìm thấy role"));
            }
            ViewBag.claimid = claimid;

            var Input = new EditClaimModel()
            {
                ClaimType  = claim.ClaimType,
                ClaimValue = claim.ClaimValue,
                role       = role
            };


            return(View(Input));
        }
Beispiel #3
0
        public async Task <IActionResult> AddRoleClaimAsync(string roleid)
        {
            if (roleid == null)
            {
                return(NotFound("Không tìm thấy role"));
            }
            var role = await _roleManager.FindByIdAsync(roleid);

            if (role == null)
            {
                return(NotFound("Không tìm thấy role"));
            }

            var model = new EditClaimModel()
            {
                role = role
            };

            return(View(model));
        }
Beispiel #4
0
        public async Task <IActionResult> AddRoleClaimAsync(string roleid, [Bind("ClaimType", "ClaimValue")] EditClaimModel model)
        {
            if (roleid == null)
            {
                return(NotFound("Không tìm thấy role"));
            }
            var role = await _roleManager.FindByIdAsync(roleid);

            if (role == null)
            {
                return(NotFound("Không tìm thấy role"));
            }
            model.role = role;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            if ((await _roleManager.GetClaimsAsync(role)).Any(c => c.Type == model.ClaimType && c.Value == model.ClaimValue))
            {
                ModelState.AddModelError(string.Empty, "Claim này đã có trong role");
                return(View(model));
            }

            var newClaim = new Claim(model.ClaimType, model.ClaimValue);
            var result   = await _roleManager.AddClaimAsync(role, newClaim);

            if (!result.Succeeded)
            {
                ModelState.AddModelError(result);
                return(View(model));
            }

            StatusMessage = "Vừa thêm đặc tính (claim) mới";

            return(RedirectToAction("Edit", new { roleid = role.Id }));
        }