Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Library.eCommerce/Models/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Item
public ProductDTO Product { get; set; }
public int? Quantity { get; set; }

public int Price { get; set; }

public ICommand? AddCommand { get; set; }

public override string ToString()
Expand All @@ -26,7 +28,7 @@ public override string ToString()
public string Display {
get
{
return $"{Product?.Display ?? string.Empty} {Quantity}";
return $"{Product?.Display ?? string.Empty} x{Quantity} ${Price}";
}
}

Expand All @@ -48,6 +50,7 @@ public Item(Item i)
Product = new ProductDTO(i.Product);
Quantity = i.Quantity;
Id = i.Id;
Price = i.Price;

AddCommand = new Command(DoAdd);
}
Expand Down
6 changes: 3 additions & 3 deletions Library.eCommerce/Services/ProductServiceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ private ProductServiceProxy()
{
Products = new List<Item?>
{
new Item{ Product = new ProductDTO{Id = 1, Name ="Product 1"}, Id = 1, Quantity = 1 },
new Item{ Product = new ProductDTO{Id = 2, Name ="Product 2"}, Id = 2 , Quantity = 2 },
new Item{ Product = new ProductDTO{Id = 3, Name ="Product 3"}, Id=3 , Quantity = 3 }
new Item{ Product = new ProductDTO{Id = 1, Name ="Product 1"}, Id = 1, Quantity = 1, Price = 5 },
new Item{ Product = new ProductDTO{Id = 2, Name ="Product 2"}, Id = 2 , Quantity = 2,Price = 50 },
new Item{ Product = new ProductDTO{Id = 3, Name ="Product 3"}, Id=3 , Quantity = 3, Price = 500 }
};
}

Expand Down
4 changes: 4 additions & 0 deletions Library.eCommerce/Services/ShoppingCartService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class ShoppingCartService
{
private ProductServiceProxy _prodSvc = ProductServiceProxy.Current;
private List<Item> items;
public double CheckoutPrice;
public List<Item> CartItems
{
get
Expand All @@ -29,6 +30,9 @@ private ShoppingCartService() {
items = new List<Item>();
}

public void ClearList() { items = new List<Item>(); }
//Sets the list to an empty, new, list

public Item? AddOrUpdate(Item item)
{
var existingInvItem = _prodSvc.GetById(item.Id);
Expand Down
4 changes: 4 additions & 0 deletions Maui.eCommerce/AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
Title="Shop"
ContentTemplate="{DataTemplate views:ShoppingManagementView}"
Route="ShoppingManagement" />
<ShellContent
Title="Shop"
ContentTemplate="{DataTemplate views:CheckoutView}"
Route="CheckoutPage" />
</Shell>
7 changes: 5 additions & 2 deletions Maui.eCommerce/Maui.eCommerce.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.7"/>
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.7"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.7" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>

Expand All @@ -67,6 +67,9 @@
</ItemGroup>

<ItemGroup>
<MauiXaml Update="Views\CheckoutView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\InventoryManagementView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
Expand Down
14 changes: 14 additions & 0 deletions Maui.eCommerce/ViewModels/ProductViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public int? Quantity
}
}

public int? Price
{
get
{
return Model?.Price;
}
set
{
if (Model != null && Model.Price != value)
{
Model.Price = value ?? 0;
}
}
}
public Item? Model { get; set; }

public void AddOrUpdate()
Expand Down
26 changes: 24 additions & 2 deletions Maui.eCommerce/ViewModels/ShoppingManagementViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Maui.eCommerce.ViewModels
{
public class ShoppingManagementViewModel : INotifyPropertyChanged
{
private ProductServiceProxy _invSvc = ProductServiceProxy.Current;
private ShoppingCartService _cartSvc = ShoppingCartService.Current;
private ProductServiceProxy _invSvc = ProductServiceProxy.Current;
private ShoppingCartService _cartSvc = ShoppingCartService.Current;
public Item? SelectedItem { get; set; }
public Item? SelectedCartItem { get; set; }

Expand Down Expand Up @@ -84,5 +84,27 @@ public void ReturnItem()
}
}
}
//Do stuff on list, then the next page will be a readout
public void Checkout()
{
/* int totalCost = 0;
foreach (var item in ShoppingCart)
{
totalCost += item?.Price ?? 0;
}
// _cartSvc.ClearList();

if (totalCost > 0)
{
NotifyPropertyChanged(nameof(ShoppingCart));
}
_cartSvc.CheckoutPrice = totalCost;
NotifyPropertyChanged(nameof(_cartSvc.CheckoutPrice));
*/
// _cartSvc.ClearList();
NotifyPropertyChanged(nameof(ShoppingCart));

}

}
}
78 changes: 78 additions & 0 deletions Maui.eCommerce/ViewModels/TotalCostViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Library.eCommerce.Models;
using Library.eCommerce.Services;

namespace Maui.eCommerce.ViewModels
{
public class TotalCostViewModel : INotifyPropertyChanged
{
private ShoppingCartService __svc = ShoppingCartService.Current;

public event PropertyChangedEventHandler? PropertyChanged;


public double CheckoutCost
{
get {
var rounded = Math.Round(__svc.CheckoutPrice + (__svc.CheckoutPrice * .07), 2);
return rounded;
}
set
{
__svc.CheckoutPrice = value;

}
}

public ObservableCollection<Item?> ShoppingCart
{
get
{
int totalCost = 0;
foreach (var item in __svc.CartItems)
{
totalCost += item?.Price ?? 0;
}
CheckoutCost = totalCost;
NotifyPropertyChanged(nameof(CheckoutCost));

var toRet = new ObservableCollection<Item?>(__svc.CartItems
.Where(i => i?.Quantity > 0)
);
// __svc.CartItems.Clear();



return toRet;
}
}

public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (propertyName is null)
{
throw new ArgumentNullException(nameof(propertyName));
}

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

public void RefreshUI()
{
NotifyPropertyChanged(nameof(CheckoutCost));
NotifyPropertyChanged(nameof(ShoppingCart));
}
public void ClearOnLeave()
{
__svc.CartItems.Clear();
CheckoutCost = 0;
}
}
}
43 changes: 43 additions & 0 deletions Maui.eCommerce/Views/CheckoutView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.eCommerce.Views.CheckoutView"
Title="CheckoutView">
<VerticalStackLayout>
<Button Text="CheckOut" Clicked="CheckOutClicked"/>
<Label
Text="You Spent: $"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Label Text="{Binding CheckoutCost}"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ListView Grid.Row="0"
ItemsSource="{Binding ShoppingCart}"
>
<!--<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>

</ViewCell>
</DataTemplate>

</ListView.ItemTemplate>-->
</ListView>
</Grid>
</Grid>


<Button Text="Go Home" Clicked="GoHome"/>
</VerticalStackLayout>
</ContentPage>
29 changes: 29 additions & 0 deletions Maui.eCommerce/Views/CheckoutView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Spring2025_Samples.Models;
using Maui.eCommerce.ViewModels;
using System.ComponentModel;
namespace Maui.eCommerce.Views;

//[QueryProperty(nameof(TotalPrice), "PriceKey")]

public partial class CheckoutView : ContentPage
{
// public int TotalPrice { get; set; }
public CheckoutView()
{
InitializeComponent();
BindingContext = new TotalCostViewModel();
// (BindingContext as TotalCostViewModel).setDefaults();
}

public void GoHome(object sender, EventArgs e)
{
(BindingContext as TotalCostViewModel).RefreshUI();
Shell.Current.GoToAsync($"//MainPage");
}

public void CheckOutClicked(object sender, EventArgs e)
{
(BindingContext as TotalCostViewModel).RefreshUI();
(BindingContext as TotalCostViewModel).ClearOnLeave();
}
}
7 changes: 7 additions & 0 deletions Maui.eCommerce/Views/ProductDetails.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
<Entry
Text="{Binding Quantity}"
/>
<Label
Text="Price:"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Entry
Text="{Binding Price}"
/>
<Button Text="Ok" Clicked="OkClicked"/>
<Button Text="Go Back" Clicked="GoBackClicked"/>
</VerticalStackLayout>
Expand Down
3 changes: 3 additions & 0 deletions Maui.eCommerce/Views/ShoppingManagementView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.eCommerce.Views.ShoppingManagementView"
Title="ShoppingManagementView">
<VerticalStackLayout>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/><!--STORE-->
Expand Down Expand Up @@ -66,4 +67,6 @@
<Button Grid.Row="1" Text="-" Clicked="RemoveFromCartClicked"/>
</Grid>
</Grid>
<Button Text="Checkout" Clicked="GoToCheckoutClicked" />
</VerticalStackLayout>
</ContentPage>
6 changes: 6 additions & 0 deletions Maui.eCommerce/Views/ShoppingManagementView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ private void InlineAddClicked(object sender, EventArgs e)
{
(BindingContext as ShoppingManagementViewModel).RefreshUX();
}

public void GoToCheckoutClicked(object sender, EventArgs e)
{
Shell.Current.GoToAsync($"//CheckoutPage");
(BindingContext as ShoppingManagementViewModel).Checkout();
}
}
3 changes: 1 addition & 2 deletions Spring2025_Samples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spring2025_Samples", "Sprin
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library.eCommerce", "Library.eCommerce\Library.eCommerce.csproj", "{B113257B-6F53-4B61-B796-F733AAF021AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maui.eCommerce", "Maui.eCommerce\Maui.eCommerce.csproj", "{0335E701-5D1D-449A-8615-BDC200AE7C4D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maui.eCommerce", "Maui.eCommerce\Maui.eCommerce.csproj", "{0335E701-5D1D-449A-8615-BDC200AE7C4D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,7 +16,6 @@ Global
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8B000EBC-E610-4D5F-ABEE-E9CECF89C2D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B000EBC-E610-4D5F-ABEE-E9CECF89C2D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B000EBC-E610-4D5F-ABEE-E9CECF89C2D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B000EBC-E610-4D5F-ABEE-E9CECF89C2D3}.Release|Any CPU.Build.0 = Release|Any CPU
{B113257B-6F53-4B61-B796-F733AAF021AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down
4 changes: 4 additions & 0 deletions Spring2025_Samples/Spring2025_Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Program.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Library.eCommerce\Library.eCommerce.csproj" />
</ItemGroup>
Expand Down