public IActionResult GetItem([FromRoute] string itemId, CancellationToken cancelltionToken) { cancelltionToken.ThrowIfCancellationRequested(); if (!Guid.TryParse(itemId, out var modelItemId)) { var error = ServiceErrorResponses.ItemNotFound(itemId); return(this.NotFound(error)); } Model.TodoItems.TodoItem modelItem = null; var userid = this.usersRepository.Get(User.Identity.Name).Id; try { modelItem = this.itemsRepository.GetAsync(modelItemId, cancelltionToken, userid); } catch (Model.TodoItems.TodoItemNotFoundExcepction) { var error = ServiceErrorResponses.ItemNotFound(itemId); return(this.NotFound(error)); } var clientItem = TodoItemConverter.Convert(modelItem); return(this.Ok(clientItem)); }
public async Task <IActionResult> PatchNoteAsync([FromRoute] string itemId, [FromBody] Client.TodoItems.TodoItemPatchInfo patchInfo, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (patchInfo == null) { var error = ServiceErrorResponses.BodyIsMissing("ItemPatchInfo"); return(this.BadRequest(error)); } if (!Guid.TryParse(itemId, out var ItemIdGuid)) { var error = ServiceErrorResponses.ItemNotFound(itemId); return(this.NotFound(error)); } var modelPathInfo = TodoItemPathcInfoConverter.Convert(ItemIdGuid, patchInfo); Model.TodoItems.TodoItem modelItem = null; var userid = this.usersRepository.Get(User.Identity.Name).Id; try { modelItem = await this.itemsRepository.PatchAsync(modelPathInfo, cancellationToken, userid).ConfigureAwait(false); } catch (Model.TodoItems.TodoItemNotFoundExcepction) { var error = ServiceErrorResponses.ItemNotFound(itemId); return(this.NotFound(error)); } var clientItem = TodoItemConverter.Convert(modelItem); return(this.Ok(clientItem)); }
public async Task <IActionResult> PutTodoItem(Guid?id, [FromBody] View.ToDoItemPatchInfo item) { if (id == null) { throw new ArgumentNullException(nameof(id)); } var modelPatchInfo = Converter.ToDoItemPatchInfoConverter.Convert(item); var modelItem = new Model.TodoItem { Id = id.Value, Name = modelPatchInfo.Name, IsComplete = modelPatchInfo.IsComplete }; if (id != modelItem.Id) { var error = ServiceErrorResponses.ItemNotFound(id.ToString()); return(this.NotFound(error)); } context.Entry(modelItem).State = EntityState.Modified; await context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> DeleteTodoItem(Guid id) { var todoItem = await context.TodoItems.FindAsync(id); if (todoItem == null) { var error = ServiceErrorResponses.ItemNotFound(id.ToString()); return(this.NotFound(error)); } context.TodoItems.Remove(todoItem); await context.SaveChangesAsync(); return(NoContent()); }
public async Task <ActionResult <Model.TodoItem> > GetTodoItem(Guid?id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } var todoItem = await context.TodoItems.FindAsync(id); if (todoItem == null) { var error = ServiceErrorResponses.ItemNotFound(id.ToString()); return(this.NotFound(error)); } return(todoItem); }
public async Task <IActionResult> DeleteItemAsync([FromRoute] string itemId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (!Guid.TryParse(itemId, out var itemIdGuid)) { var error = ServiceErrorResponses.ItemNotFound(itemId); return(this.NotFound(error)); } var userid = this.usersRepository.Get(User.Identity.Name).Id; try { await this.itemsRepository.RemoveAsync(itemIdGuid, cancellationToken, userid).ConfigureAwait(false); } catch (Model.TodoItems.TodoItemNotFoundExcepction) { var error = ServiceErrorResponses.ItemNotFound(itemId); return(this.NotFound(error)); } return(this.NoContent()); }