Example #1
0
        public async Task <ActionResult> Edit(Guid id, RoleAccountRegister collection)
        {
            try
            {
                await _unitOfWork.RoleAccount.EditRole(collection, id);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #2
0
        public async Task <ActionResult> Create(RoleAccountRegister collection)
        {
            try
            {
                await _unitOfWork.RoleAccount.AddRole(collection);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #3
0
        public async Task <ActionResult> Delete(Guid id, RoleAccountRegister model)
        {
            try
            {
                await _unitOfWork.RoleAccount.RemoveRole(id);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
Example #4
0
        public async Task EditRole(RoleAccountRegister entity, Guid id)
        {
            try
            {
                var role = await _roleManager.FindByIdAsync(entity.Id.ToString());

                role.Name = entity.Name;
                await _roleManager.UpdateAsync(role);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #5
0
 public async Task AddRole(RoleAccountRegister entity)
 {
     try
     {
         var role = new ClamRoles {
             Name = entity.Name
         };
         await _roleManager.CreateAsync(role);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #6
0
        public async Task <RoleAccountRegister> ViewRole(Guid id)
        {
            var role = await _roleManager.FindByIdAsync(id.ToString());

            var model = new RoleAccountRegister {
                Id = role.Id, Name = role.Name, Users = new List <string>(), Claims = new List <string>()
            };
            var getUsers  = _userManager.Users.ToList();
            var getClaims = _roleManager.GetClaimsAsync(role);

            foreach (var user in getUsers)
            {
                if (await _userManager.IsInRoleAsync(user, role.Name))
                {
                    model.Users.Add(user.FirstName);
                }
            }
            foreach (Claim claim in getClaims.Result)
            {
                model.Claims.Add(claim.Value);
            }
            return(model);
        }