Ejemplo n.º 1
0
        public async Task <TResponse <bool> > CheckRole(string username,
                                                        int roleId)
        {
            try
            {
                var user = await GetByUsername(username);

                if (user.IsSuccess)
                {
                    var role = await _roleGroupService.GetById(roleId);

                    if (role.IsSuccess)
                    {
                        var roleUser = await _readOnlyRepository.QueryAsync <int>(SqlQuery.GET_ROLE_USERS_BY_ID, new
                        {
                            RoleId = roleId,
                            UserId = user.Data.Id
                        });

                        if (roleUser.IsSuccess)
                        {
                            if (roleUser.Data != null && roleUser.Data.Any())
                            {
                                return(await Ok(true));
                            }

                            return(await Fail <bool>(""));
                        }

                        return(await Fail <bool>(roleUser.Message));
                    }
                }

                return(await Fail <bool>(user.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <bool>(exception));
            }
        }
Ejemplo n.º 2
0
 public async Task <ActionResult <RoleGroupRes> > GetById(int id)
 {
     return(Ok(await _roleGroupService.GetById(id)));
 }