protected async Task MoveUpItemAsync(ItemApiModel item) { int indexOfItem = Items.IndexOf(item); int indexOfPrevItem = indexOfItem - 1; await SwapItemsAsync(item, indexOfItem, indexOfPrevItem); }
protected async Task MoveDownItemAsync(ItemApiModel item) { int indexOfItem = Items.IndexOf(item); int indexOfNextItem = indexOfItem + 1; await SwapItemsAsync(item, indexOfItem, indexOfNextItem); }
protected async Task UpdateItemTextAsync(ChangeEventArgs e, ItemApiModel item) { string?text = e.Value as string; if (!string.IsNullOrWhiteSpace(text)) { item.Text = text; await UpdateItemAsync(item); } }
public async Task <IActionResult> UpdateAsync(int id, ItemApiModel item, CancellationToken cancellationToken) { if (id != item.Id) { return(BadRequest()); } UpdateItemCommand command = new(item.Id, item.IsDone, item.Text, item.Priority, User.GetIdentityId()); await mediator.Send(new RemoveCachedItemsCommand <UpdateItemCommand, Unit>(command), cancellationToken); return(Ok()); }
private Task SwapItemsAsync(ItemApiModel item, int indexOfSelectedItem, int indexOfAnotherItem) { ItemApiModel anotherItem = Items[indexOfAnotherItem]; Items[indexOfSelectedItem] = anotherItem; Items[indexOfAnotherItem] = item; int itemPriority = item.Priority; item.Priority = anotherItem.Priority; anotherItem.Priority = itemPriority; return(Task.WhenAll(UpdateItemAsync(item), UpdateItemAsync(anotherItem))); }
public async Task When_ItemIsFound_Expect_Deleted() { ItemApiModel itemSaved = await SaveItemAsync(new Item(UserId, "itemText", 1, ItemStatus.Todo)); // Act HttpResponseMessage response = await DeleteAsync($"{url}/{itemSaved.Id}"); response.EnsureSuccessStatusCode(); Item?itemDeleted = (await GetAllItemsAsync()) .SingleOrDefault(i => i.Id == itemSaved.Id); itemDeleted.Should().BeNull(); }
public async Task When_InputModelIsValid_Expect_Saved() { ItemCreateApiModel itemToSave = new() { Text = "itemText" }; // Act HttpResponseMessage response = await PostAsync(url, itemToSave); response.EnsureSuccessStatusCode(); ItemApiModel itemSaved = await DeserializeResponseBodyAsync <ItemApiModel>(response); ItemApiModel expectedItem = new() { IsDone = false, Text = itemToSave.Text, Priority = 1 }; itemSaved.Should().BeEquivalentTo(expectedItem, o => o.Excluding(m => m.Id)); itemSaved.Id.Should().NotBe(default);
public async Task When_InputModelIsValid_Expect_Updated() { ItemApiModel itemToUpdate = await SaveItemAsync( new Item(UserId, "itemText", 10, ItemStatus.Todo) ); itemToUpdate.IsDone = true; itemToUpdate.Text = "newItemText"; itemToUpdate.Priority = 25; // Act HttpResponseMessage response = await PutAsync($"{url}/{itemToUpdate.Id}", itemToUpdate); response.EnsureSuccessStatusCode(); Item itemUpdated = (await GetAllItemsAsync()) .Single(i => i.Id == itemToUpdate.Id); itemUpdated.Status.Should().BeEquivalentTo(ItemStatus.Done); itemUpdated.Text.Should().BeEquivalentTo(itemToUpdate.Text); itemUpdated.Priority.Should().Be(itemToUpdate.Priority); }
public IActionResult Put(int id, [FromBody] ItemApiModel updatedItem) { try { var item = updatedItem.ToDomainModel(); item.Id = id; if (updatedItem.VehicleId > 0 && updatedItem.UseTicketId > 0) { item.VehicleId = updatedItem.VehicleId; item.UseTicketId = updatedItem.UseTicketId; } _itemService.Update(item); return(Ok(item)); } catch (Exception ex) { ModelState.AddModelError("UpdateResourceItem", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Post([FromBody] ItemApiModel newItem) { try { var item = newItem.ToDomainModel(); if (newItem.VehicleId > 0 && newItem.UseTicketId > 0) { item.VehicleId = newItem.VehicleId; item.UseTicketId = newItem.UseTicketId; } _itemService.Add(item); return(Ok(item)); } catch (Exception ex) { ModelState.AddModelError("AddResourceItem", ex.Message); return(BadRequest(ModelState)); } }
protected async Task DeleteItemAsync(ItemApiModel item) { Items.Remove(item); await AppHttpClient.DeleteAsync(ApiUrls.DeleteItem.Replace(ApiUrls.IdTemplate, item.Id.ToString())); }
protected async Task UpdateItemStatusAsync(ChangeEventArgs e, ItemApiModel item) { item.IsDone = e.Value is bool isDone && isDone; await UpdateItemAsync(item); }
private Task UpdateItemAsync(ItemApiModel item) { return(AppHttpClient.PutAsync(ApiUrls.UpdateItem.Replace(ApiUrls.IdTemplate, item.Id.ToString()), item)); }