public async Task <IActionResult> GetTodoById(long todoId) { Devon4NetLogger.Debug("Executing GetTodoById from controller MediatRController"); var query = new GetTodoQuery(todoId); return(Ok(await MediatRHandler.QueryAsync(query).ConfigureAwait(false))); }
private static IQueryable <Todo> AddFiltersOnQuery(GetTodoQuery filter, IQueryable <Todo> queryable) { if (!string.IsNullOrEmpty(filter?.UserId)) { queryable = queryable.Where(x => x.UserId == filter.UserId); } return(queryable); }
public async Task <List <TodoDTO> > GetTodosAsync(GetTodoQuery filter = null, PaginationFilter paginationFilter = null) { var queryable = _todoRepository.AsQueryable(); if (paginationFilter == null) { var check = await queryable.Include(x => x.Tag).ToListAsync(); return(check.ConvertTo().ToList()); } queryable = AddFiltersOnQuery(filter, queryable); var skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize; var listTodo = await queryable.Include(x => x.Tag).Skip(skip).Take(paginationFilter.PageSize).ToListAsync(); return(listTodo.ConvertTo().ToList()); }
public ActionResult <IList <TodoDTO> > Get([FromQuery] GetTodoQuery query) { try { var todos = _todoService.ListTodoAsync(GetUserId(), query)?.Result;// Testing return(Ok(todos)); } catch (TodoValidationException todoValidationEx) when(todoValidationEx.InnerException is NotFoundUserException) { return(NotFound(todoValidationEx.InnerException.Message)); } catch (TodoValidationException todoValidationEx) when(todoValidationEx.InnerException is RecordNotFoundException) { return(NotFound(todoValidationEx.InnerException.Message)); } catch (TodoDIException diEx) { return(Problem(diEx.Message)); } }
public Task <IEnumerable <TodoDTO> > ListTodoAsync(string userId, GetTodoQuery query) { if (userId == null) { return(null); } Expression <Func <Todo, bool> > predicate = x => x.UserId == userId; var userTodos = _todoCollection.Find(predicate).ToList(); if (query.Date != null) { userTodos = userTodos.FindAll(x => x.Datetime == new DateTime(query.Date.Value.Year, query.Date.Value.Month, query.Date.Value.Day)); } if (query.SortByDate) { userTodos = userTodos.OrderByDescending(x => x.Datetime).ToList(); } if (query.TodoStatus != null) { userTodos = userTodos.FindAll(x => x.Status == query.TodoStatus); } return(Task.FromResult(userTodos.ConvertTo())); }