public IActionResult GetById(long id) { try { var query = new GetTodoItemsById(id); query.Validate(); if (query.Invalid) { return(BadRequest(query)); } var result = _todoItemQueryHandler.Handle(query); var todoItemDto = new TodoItemDto(); todoItemDto.InjectFrom(result); return(Ok(todoItemDto)); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception e) { return(BadRequest(e)); } }
public IActionResult Get(int skip = 0, int top = 0) { var query = new GetAllTodoItemsQuery(skip, top); query.Validate(); if (query.Invalid) { return(BadRequest(query)); } var result = _todoItemQueryHandler.Handle(query); var listDto = new List <TodoItemDto>(); foreach (var item in result) { var todoItemDto = new TodoItemDto(); todoItemDto.InjectFrom(item); listDto.Add(todoItemDto); } return(Ok(listDto.AsEnumerable())); }