Wonky.Client/Wonky.Entity/Models/Cart.cs

37 lines
888 B
C#
Raw Normal View History

2022-03-15 12:04:15 +01:00
using Wonky.Entity.DTO;
2022-03-15 12:04:15 +01:00
namespace Wonky.Entity.Models;
public class CartItem
{
public int Quantity { get; set; }
2022-03-15 12:04:15 +01:00
public SalesItemDto Item { get; set; }
public decimal Price { get; set; }
public decimal Total
{
get
{
2022-03-15 12:04:15 +01:00
var price = (from x in Item.Rates where x.Quantity == Quantity.ToString() select x.Rate).First();
if (string.IsNullOrWhiteSpace(price))
price = Item.Rates[0].Rate;
Price = Convert.ToDecimal(price);
return Price * Quantity;
}
}
}
public class Cart
{
public List<CartItem> Items { get; set; } = new List<CartItem>();
public decimal Total
{
get
{
return Items.Sum(item => item.Total);
}
}
public DateTime LastAccessed { get; set; }
public int TimeToLiveInSeconds { get; set; } = 60; // default
}