public IActionResult List() { var items = _todoRepository.List() .Select(item => ToDoItemDTO.FromToDoItem(item)); return(Ok(items)); }
public IActionResult GetToDoItemById(int id) { myLog.Information("Getting item {ID}", id); var item = ToDoItemDTO.FromToDoItem(_repository.GetById <ToDoItem>(id)); return(Ok(item)); }
public async Task CreatesAToDoItem() { var newToDoItem = new ToDoItem { Title = "Pass Tests", Description = "ToDo item created from the test" }; var newToDoItemDto = ToDoItemDTO.FromToDoItem(newToDoItem); var payload = new StringContent(JsonConvert.SerializeObject(newToDoItemDto), Encoding.UTF8, "application/json"); var response = await _client.PostAsync("/api/v2/todoitems/", payload); response.EnsureSuccessStatusCode(); var stringResponse = await response.Content.ReadAsStringAsync(); var createdToDoItemDTO = JsonConvert.DeserializeObject <ToDoItemDTO>(stringResponse); Assert.True(createdToDoItemDTO.Id != 0); Assert.Equal(newToDoItem.Title, createdToDoItemDTO.Title); Assert.Equal(newToDoItem.Description, createdToDoItemDTO.Description); Assert.Equal(newToDoItem.IsDone, createdToDoItemDTO.IsDone); }
public async Task MarksToDoItemAsComplete() { var newToDoItem = new ToDoItem { Title = "Mark Complete", Description = "ToDo item created from test to mark completed" }; var newToDoItemDto = ToDoItemDTO.FromToDoItem(newToDoItem); var createRequestPayload = new StringContent(JsonConvert.SerializeObject(newToDoItemDto), Encoding.UTF8, "application/json"); var createToDoItemResponse = await _client.PostAsync("/api/v2/todoitems/", createRequestPayload); createToDoItemResponse.EnsureSuccessStatusCode(); var createToDoItemStringResponse = await createToDoItemResponse.Content.ReadAsStringAsync(); var createdToDoItemDTO = JsonConvert.DeserializeObject <ToDoItemDTO>(createToDoItemStringResponse); var markCompleteResponse = await _client.PatchAsync($"/api/v2/todoitems/{createdToDoItemDTO.Id}/complete", new StringContent(string.Empty)); markCompleteResponse.EnsureSuccessStatusCode(); var markCompleteStringResponse = await markCompleteResponse.Content.ReadAsStringAsync(); var markCompleteToDoItemDTO = JsonConvert.DeserializeObject <ToDoItemDTO>(markCompleteStringResponse); Assert.True(markCompleteToDoItemDTO.IsDone); }
public async Task <IActionResult> Complete(int id) { var toDoItem = await _repository.FirstOrDefaultAsync(ToDoItemSpecs.ById(id)); toDoItem.MarkComplete(); _repository.Update(toDoItem); return(Ok(ToDoItemDTO.FromToDoItem(toDoItem))); }
public async Task <IActionResult> Complete(int id) { var toDoItem = await _repository.GetByIdAsync <ToDoItem>(id); toDoItem.MarkComplete(); await _repository.UpdateAsync(toDoItem); return(Ok(ToDoItemDTO.FromToDoItem(toDoItem))); }
public ToDoItemDTO GetById(int id) { ToDoItem todo = _repository.GetById <ToDoItem>(id); var res = ToDoItemDTO.FromToDoItem(todo); return(res); }
public IActionResult Complete(int id) { var toDoItem = _repository.GetById <ToDoItem>(id); toDoItem.MarkComplete(); _repository.Update(toDoItem); return(Ok(ToDoItemDTO.FromToDoItem(toDoItem))); }
public async Task <IActionResult> Complete(int id) { var toDoItem = await _dbContext.FindAsync <ToDoItem>(id); toDoItem.MarkComplete(); await _dbContext.SaveChangesAsync(); return(Ok(ToDoItemDTO.FromToDoItem(toDoItem))); }
public ToDoItemDTO MarkComplete(int id) { ToDoItem todo = _repository.GetById <ToDoItem>(id); todo.MarkComplete(); _repository.Update(todo); var res = ToDoItemDTO.FromToDoItem(todo); return(res); }
public ToDoItemDTO AddTodoItem(ToDoItemDTO toDoItem) { ToDoItem todo = new ToDoItem() { Description = toDoItem.Description, Id = toDoItem.Id, Title = toDoItem.Title }; todo = _repository.Add(todo); return(ToDoItemDTO.FromToDoItem(todo)); }
// POST: api/ToDoItems public IActionResult Post([FromBody] ToDoItemDTO item) { var todoItem = new ToDoItem() { Title = item.Title, Description = item.Description }; _todoRepository.Add(todoItem); return Ok(ToDoItemDTO.FromToDoItem(todoItem)); }
public async Task <IActionResult> Post([FromBody] ToDoItemDTO item) { var todoItem = new ToDoItem() { Title = item.Title, Description = item.Description }; await _repository.AddAsync(todoItem); return(Ok(ToDoItemDTO.FromToDoItem(todoItem))); }
public IActionResult UpdateToDoItem([FromBody] ToDoItemDTO item) { var todoItem = new ToDoItem() { Id = item.Id, Title = item.Title, Description = item.Description }; _repository.Update(todoItem); return(Ok(ToDoItemDTO.FromToDoItem(todoItem))); }
public ToDoItemDTO Update(ToDoItemDTO toDoItem) { ToDoItem todo = new ToDoItem() { Description = toDoItem.Description, Id = toDoItem.Id, Title = toDoItem.Title }; _repository.Update(todo); var res = ToDoItemDTO.FromToDoItem(todo); return(res); }
public async Task <IActionResult> Post([FromBody] ToDoItemDTO item) { var todoItem = new ToDoItem { Title = item.Title, Description = item.Description }; _dbContext.Add(todoItem); await _dbContext.SaveChangesAsync(); return(Ok(ToDoItemDTO.FromToDoItem(todoItem))); }
public IActionResult Complete(int id) { var sampleDataLog = Log.ForContext("ToDoItemId", id); sampleDataLog.Information("Completing ToDoItem"); var toDoItem = _repository.GetById <ToDoItem>(id); toDoItem.MarkComplete(); _repository.Update(toDoItem); sampleDataLog.Information("Finished"); return(Ok(ToDoItemDTO.FromToDoItem(toDoItem))); }
public IActionResult List() { // _loggerFactory logger = _loggerFactory.CreateLogger("LoggerCategory"); // _loggerFactory.LogInformation("Your MSg"); var logger = NLog.LogManager.GetCurrentClassLogger(); // logger.Info("Hello World"); logger.Info("Hello World"); // logger.Debug("Sample debug message"); // logger.Log(LogLevel.Information, "Sample informational message"); logger.Error("ow noos!", ""); var items = _todoRepository.List() .Select(item => ToDoItemDTO.FromToDoItem(item)); return(Ok(items)); }
public async Task <IActionResult> GetById(int id) { var projectSpec = new ProjectByIdWithItemsSpec(id); var project = await _repository.GetBySpecAsync(projectSpec); var result = new ProjectDTO { Id = project.Id, Name = project.Name, Items = new List <ToDoItemDTO> ( project.Items.Select(i => ToDoItemDTO.FromToDoItem(i)).ToList() ) }; return(Ok(result)); }
public async Task OnGetAsync() { var projectSpec = new ProjectByIdWithItemsSpec(ProjectId); var project = await _repository.GetBySpecAsync(projectSpec); if (project == null) { Message = "No project found."; return; } Project = new ProjectDTO { Id = project.Id, Name = project.Name, Items = project.Items .Select(item => ToDoItemDTO.FromToDoItem(item)) .ToList() }; }
public async Task <IActionResult> GetById(int id) { var projectSpec = new ProjectByIdWithItemsSpec(id); var project = await _repository.GetBySpecAsync(projectSpec); if (project == null) { return(NotFound()); } var result = new ProjectDTO ( id: project.Id, name: project.Name, items: new List <ToDoItemDTO> ( project.Items.Select(i => ToDoItemDTO.FromToDoItem(i)).ToList() ) ); return(Ok(result)); }
public IActionResult GetById(int id) { var item = ToDoItemDTO.FromToDoItem(_repository.GetById <ToDoItem>(id)); return(Ok(item)); }
public async Task <IActionResult> GetById(int id) { var item = ToDoItemDTO.FromToDoItem(await _repository.FirstOrDefaultAsync(ToDoItemSpecs.ById(id))); return(Ok(item)); }
public async Task <IActionResult> GetById(int id) { var item = ToDoItemDTO.FromToDoItem(await _repository.GetByIdAsync <ToDoItem>(id)); return(Ok(item)); }
public async Task <IActionResult> GetById(int id) { var item = ToDoItemDTO.FromToDoItem(await _dbContext.FindAsync <ToDoItem>(id)); return(Ok(item)); }
public IActionResult GetById(int id) { var item = ToDoItemDTO.FromToDoItem(_todoRepository.GetById(id)); return Ok(item); }