Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Commit

Permalink
Edit todo section functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
liamspitaels committed Jan 17, 2021
1 parent dc389b6 commit a99c767
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Vecto.Api/Controllers/ItemsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public IActionResult Update(Guid tripId, Guid sectionId, Guid itemId, ItemDTO it
_tripsRepository.Update(trip);
_tripsRepository.SaveChanges();

return Ok();
return Ok(item);
}

[HttpDelete("{itemId}")]
Expand Down
12 changes: 11 additions & 1 deletion Vecto.UWP/Pages/Sections/TodoSectionPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,21 @@
PrimaryButtonText="Add"
CloseButtonText="Cancel">
<StackPanel Spacing="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBlock Text="Add Todo Item"/>
<TextBox Name="AddTodoName" Header="Title" />
<TextBox Name="AddTodoDesc" Header="Description" />
</StackPanel>
</ContentDialog>

<ContentDialog
Name="EditTodoDialog"
Title="Edit Todo Item"
PrimaryButtonText="Apply"
CloseButtonText="Cancel">
<StackPanel Spacing="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<TextBox Name="EditTodoName" Header="Title" />
<TextBox Name="EditTodoDesc" Header="Description" />
</StackPanel>
</ContentDialog>
</StackPanel>
</Page>

Expand Down
27 changes: 25 additions & 2 deletions Vecto.UWP/Pages/Sections/TodoSectionPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,32 @@ private async void AddTodo_Button_OnClick(object sender, RoutedEventArgs e)
}
}

private void EditTodo_Click(object sender, RoutedEventArgs e)
private async void EditTodo_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException(); //TODO
var todo = (sender as MenuFlyoutItem).DataContext as TodoItem;

EditTodoName.Text = todo.Title;
EditTodoDesc.Text = todo.Description;
if (await EditTodoDialog.ShowAsync() != ContentDialogResult.Primary) return;

try
{
var editedTodo = new ItemDTO()
{
Title = EditTodoName.Text,
Description = EditTodoDesc.Text
};

var updated = (TodoItem)await _service.UpdateTodoItem(_tripId, _sectionId, todo.Id, editedTodo);
var index = _todoItems.IndexOf(todo);
if (index != -1) _todoItems[index] = updated;

//Frame.Navigate(GetType(), new SurpressNavigationTransitionInfo());
}
catch
{
//TODO exception handling
}
}

private async void DeleteTodo_Click(object sender, RoutedEventArgs e)
Expand Down
7 changes: 7 additions & 0 deletions Vecto.UWP/Services/IApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Vecto.Application.Sections;
using Vecto.Application.Trips;
using Vecto.Core.Entities;
using Vecto.Core.Interfaces;

namespace Vecto.UWP.Services
{
Expand Down Expand Up @@ -65,6 +66,12 @@ public interface IApiService
[Post("/trips/{tripId}/sections/{sectionId}/items/{itemId}/toggle")]
Task ToggleItem(Guid tripId, Guid sectionId, Guid itemId);

[Patch("/trips/{tripId}/sections/{sectionId}/items/{itemId}")]
Task<TodoItem> UpdateTodoItem(Guid tripId, Guid sectionId, Guid itemId, ItemDTO model);

[Patch("/trips/{tripId}/sections/{sectionId}/items/{itemId}")]
Task<PackingItem> UpdatePackingItem(Guid tripId, Guid sectionId, Guid itemId, ItemDTO model);

[Delete("/trips/{tripId}/sections/{sectionId}/items/{itemId}")]
Task DeleteItem(Guid tripId, Guid sectionId, Guid itemId);

Expand Down

0 comments on commit a99c767

Please sign in to comment.