예제 #1
0
        protected async Task MoveUpItemAsync(ItemApiModel item)
        {
            int indexOfItem     = Items.IndexOf(item);
            int indexOfPrevItem = indexOfItem - 1;

            await SwapItemsAsync(item, indexOfItem, indexOfPrevItem);
        }
예제 #2
0
        protected async Task MoveDownItemAsync(ItemApiModel item)
        {
            int indexOfItem     = Items.IndexOf(item);
            int indexOfNextItem = indexOfItem + 1;

            await SwapItemsAsync(item, indexOfItem, indexOfNextItem);
        }
예제 #3
0
        protected async Task UpdateItemTextAsync(ChangeEventArgs e, ItemApiModel item)
        {
            string?text = e.Value as string;

            if (!string.IsNullOrWhiteSpace(text))
            {
                item.Text = text;

                await UpdateItemAsync(item);
            }
        }
예제 #4
0
        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());
        }
예제 #5
0
        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)));
        }
예제 #6
0
            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();
            }
예제 #7
0
            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);
예제 #8
0
            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);
            }
예제 #9
0
        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));
            }
        }
예제 #10
0
        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));
            }
        }
예제 #11
0
        protected async Task DeleteItemAsync(ItemApiModel item)
        {
            Items.Remove(item);

            await AppHttpClient.DeleteAsync(ApiUrls.DeleteItem.Replace(ApiUrls.IdTemplate, item.Id.ToString()));
        }
예제 #12
0
        protected async Task UpdateItemStatusAsync(ChangeEventArgs e, ItemApiModel item)
        {
            item.IsDone = e.Value is bool isDone && isDone;

            await UpdateItemAsync(item);
        }
예제 #13
0
 private Task UpdateItemAsync(ItemApiModel item)
 {
     return(AppHttpClient.PutAsync(ApiUrls.UpdateItem.Replace(ApiUrls.IdTemplate, item.Id.ToString()), item));
 }