Beispiel #1
0
        public async Task <TResponse <PageResult <RoleGroupRes> > > GetByUserId(GetRoleGroupByUserIdReq req)
        {
            try
            {
                if (req.Page <= 1)
                {
                    req.Page = 1;
                }

                if (req.PageSize <= 5)
                {
                    req.PageSize = 5;
                }

                var result = await _readOnlyRepository.QueryMultipleLFAsync <RoleGroup, int>(
                    SqlQuery.ROLE_GROUP_BY_USER_ID_GET_PAGING, new
                {
                    Name = $"%{req.Name}%",
                    req.UserId,
                    Skip = (req.Page - 1) * req.PageSize,
                    Take = req.PageSize
                });

                if (result != null)
                {
                    if (result.IsSuccess)
                    {
                        return(await Ok(new PageResult <RoleGroupRes>(req.Page, req.PageSize, result.Data.Item2,
                                                                      Mapper.Map <IEnumerable <RoleGroupRes> >(result.Data.Item1))));
                    }

                    return(await Fail <PageResult <RoleGroupRes> >(result.Message));
                }

                return(await Ok(new PageResult <RoleGroupRes>(1, req.PageSize, 0, null)));
            }
            catch (Exception exception)
            {
                return(await Fail <PageResult <RoleGroupRes> >(exception));
            }
        }
 public async Task <ActionResult <RoleGroupRes> > GetByUserId([FromQuery] GetRoleGroupByUserIdReq req)
 {
     return(Ok(await _roleGroupService.GetByUserId(req)));
 }