public async Task <IActionResult> GetStoreUsers([FromQuery] GetStoreUsers get) { try { var result = await Mediator.Send(get); return(Ok(result)); } catch (Exception e) { return(BadRequestWithMessage(e.Message)); } }
public async Task <IEnumerable <StoreUserModel> > Handle(GetStoreUsers request, CancellationToken cancellationToken) { var correctRoles = new[] { Role.StoreEmployee, Role.StoreOwner }; if (!correctRoles.Contains(request.Role)) { throw new ArgumentException($"{nameof(request.Role)} must be {string.Join(" or ", correctRoles)}"); } return(await context.StoreUsers.AsNoTracking() .Where(storeUser => storeUser.Role == Role.StoreEmployee || storeUser.Role == Role.StoreOwner) .Select(storeUser => new StoreUserModel { Id = storeUser.Id, Role = storeUser.Role, Username = storeUser.Username }) .ToListAsync()); }
public static Task <StoreUserModel[]> GetStoreUsers(this IFlurlClient http, GetStoreUsers model) { return(http.Request("api", "storeuser", "users") .SetQueryParams(model) .GetJsonAsync <StoreUserModel[]>()); }