public async Task <ActionResult> Get([FromQuery] GetTodoItemsRequest requst) { var query = db.TodoItems.AsQueryable(); // filter if (!string.IsNullOrEmpty(requst.Filter.Title)) { query = query.Where(a => a.Title.Contains(requst.Filter.Title)); } if (requst.Filter.Status.HasValue) { query = query.Where(a => a.Status == requst.Filter.Status); } var total = await query.CountAsync(); var items = await query .OrderByDescending(a => a.CreateOn) .Skip(requst.Skip) .Take(GetTake(requst.Take)) .ToArrayAsync(); var response = new GetTodoItemsResponse { Items = items, Total = total }; return(Ok(response));
public override async Task <GetTodoItemsResponse> GetTodoItems(Empty request, ServerCallContext context) { var result = await _unitOfWork.TodoItems.FindAllAsync(); var response = new GetTodoItemsResponse(); foreach (var todo in result) { response.Todos.Add(todo); } return(response); }