Skip to content

Commit

Permalink
added pricing info to items
Browse files Browse the repository at this point in the history
  • Loading branch information
Programming-With-Chris committed Aug 20, 2022
1 parent 3685992 commit 008ac35
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
10 changes: 9 additions & 1 deletion ShoppingList/Model/Api/ProductSearchResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Datum
public string countryOrigin { get; set; }
public string description { get; set; }
public List<Image> images { get; set; }
public List<Item> items { get; set; }
public List<Items> items { get; set; }
public ItemInformation itemInformation { get; set; }
public Temperature temperature { get; set; }
}
Expand All @@ -35,6 +35,14 @@ public class Items
public bool favorite { get; set; }
public Fulfillment fulfillment { get; set; }
public string size { get; set; }
public Prices price { get; set; }
}

public class Prices
{
public decimal regular { get; set; }
public decimal promo { get; set; }

}

public class ItemInformation
Expand Down
16 changes: 15 additions & 1 deletion ShoppingList/Model/UserList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ public class UserList : ObservableObject
[Column("targetStore")]
public string TargetStore { get; set; }

private decimal _totalPrice;

public decimal TotalPrice {
get
{
_totalPrice = 0m;
foreach(var item in Items)
{
_totalPrice += item.EstimatedPrice;
}
return _totalPrice;
}
}


[OneToMany]
public List<Item> Items { get; set; }
Expand All @@ -40,7 +54,7 @@ public UserList(UserList ul)
this.Id = ul.Id;
this.Name = ul.Name;
this.TargetStore = ul.TargetStore;
this.Items = ul.Items;
this.Items = ul.Items;
}

public UserList(string name, string targetStore)
Expand Down
16 changes: 14 additions & 2 deletions ShoppingList/Services/KrogerAPIService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,20 @@ public async Task<Dictionary<string, string>> GetLocationNearZipAsync(string zip
{
Name = term,
Description = jsonItem.description,
Category = jsonItem.categories[0]
};
Category = jsonItem.categories[0],
};

if (jsonItem.items[0] is not null)
{
if (jsonItem.items[0].price is not null)
{
item.EstimatedPrice = jsonItem.items[0].price.promo;

if (item.EstimatedPrice == 0m)
item.EstimatedPrice = jsonItem.items[0].price.regular;

}
}

return (returnILD, item);
}
Expand Down
18 changes: 17 additions & 1 deletion ShoppingList/View/UserListDetails.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,29 @@
Grid.Column="1"
TextColor="{DynamicResource Accent}"
Grid.RowSpan="1"/>
<Label Text="{Binding Aisle}"
<VerticalStackLayout Grid.Row="1"
Grid.Column="2"
Grid.ColumnSpan="2">

<Label Text="{Binding Aisle}"
Grid.Row="1"
Grid.Column="2"
Grid.ColumnSpan="2"
TextColor="{DynamicResource Accent}"
HorizontalOptions="End"
VerticalOptions="Start"
/>

<Label Text="{Binding EstimatedPrice}"
Grid.Row="1"
Grid.Column="2"
Grid.ColumnSpan="2"
TextColor="{DynamicResource Accent}"
HorizontalOptions="End"
VerticalOptions="End"
/>

</VerticalStackLayout>
</Grid>
</Frame>
</SwipeView>
Expand Down
22 changes: 16 additions & 6 deletions ShoppingList/ViewModel/UserListDetailViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public UserListDetailViewModel(ItemService itemService, KrogerAPIService krogerA
_krogerAPIService = krogerAPIService;
undoItemBuffer = new Stack<Item>();

Console.Write("Test Output");

undoTimer = new System.Timers.Timer(5000);
undoTimer.Elapsed += new ElapsedEventHandler(UndoTimerTick);
}
Expand All @@ -36,9 +34,15 @@ public UserList UserList
{
userList = value;
ListSorter.SortUserListItems(userList);
Title = UserList.Name;

if (UserList.Name.Length > 10)
Title = $"{UserList.Name.Substring(0, 10)}... - est. price: {UserList.TotalPrice}";
else
Title = $"{UserList.Name}... - est. price: {UserList.TotalPrice}";

OnUserListChanged(value);
OnPropertyChanged(nameof(UserList));
OnPropertyChanged(nameof(Title));
OnPropertyChanged(nameof(UserList.Items));
}
}
Expand Down Expand Up @@ -82,7 +86,7 @@ public void RefreshUserListDetailScreen()
public async void GoToItemDetail(Item item)
{
await Shell.Current.DisplayAlert(item.Name, $"Category: {item.Category} \nDescription: {item.Description} \n" +
$"Aisle: {item.Aisle}", "Ok");
$"Aisle: {item.Aisle} \n Estimated Price: {item.EstimatedPrice}", "Ok");
}

[RelayCommand]
Expand Down Expand Up @@ -135,6 +139,7 @@ public async void OnItemEntryCompleted(string itemName)
newItem.LocationData = ild;
newItem.Description = item.Description;
newItem.Category = item.Category;
newItem.EstimatedPrice = item.EstimatedPrice;

newItem.Aisle = ild.Description;
newItem.ParentId = UserList.Id;
Expand All @@ -158,7 +163,7 @@ public void DeleteItem(Item item)
undoItemBuffer.Push(item);

_itemService.DeleteItem(item);
UserList.Items.Remove(item);
UserList.Items.Remove(item);

UserList.Items = ListSorter.SortUserListItems(userList);

Expand Down Expand Up @@ -189,7 +194,7 @@ public void UndoButtonPressed()
undoneItem.LocationData.ParentId = undoneItem.Id;

UserList.Items.Add(undoneItem);
UserListNotifers();
UserListNotifers();
}
else
{
Expand All @@ -201,6 +206,11 @@ public void UndoButtonPressed()

private void UserListNotifers()
{
if (UserList.Name.Length > 10)
Title = $"{UserList.Name.Substring(0, 10)}... - est. price: {UserList.TotalPrice}";
else
Title = $"{UserList.Name}... - est. price: {UserList.TotalPrice}";

OnUserListChanged(UserList);
OnPropertyChanged(nameof(UserList));
OnPropertyChanged(nameof(UserList.Items));
Expand Down

0 comments on commit 008ac35

Please sign in to comment.