protected override async void InjectProperties(IOrder toUpdate) { await UpdateDataSets(); _Id = toUpdate.Id; ProductQuantities.Clear(); foreach (KeyValuePair <uint, uint> pair in toUpdate.ProductIdQuantityMap) { IProduct product = Products.First(p => p.Id == pair.Key); ProductQuantities.Add(new ProductQuantityViewModel(product, pair.Value)); } OrderDate = toUpdate.OrderDate; if (toUpdate.DeliveryDate.HasValue) { DeliveryDate = toUpdate.DeliveryDate.Value; Delivered = true; } else { DeliveryDate = DateTime.Now; Delivered = false; } ClientUsernameIndex = -1; for (int i = 0; i < ClientUsernames.Length; ++i) { if (ClientUsernames[i] == toUpdate.ClientUsername) { ClientUsernameIndex = i; break; } } }
private double GetProductPrice(Product product) { if (ProductQuantities.TryGetValue(product, out int quantity)) { return(product.Price * quantity); } throw new KeyNotFoundException(nameof(product)); }
private void CheckQuantityAvailableForRevert(IIncomingProduct incoming) { ProductQuantity productQuantity = ProductQuantities .SingleOrDefault(p => p.Id == incoming.ProductId); InsufficientBalance = productQuantity == null || productQuantity.TotalAvailable < incoming.Quantity; }
private void CheckQuantityAvailableFor(IOutgoingProduct outgoing) { ProductQuantity productQuantity = ProductQuantities .SingleOrDefault(p => p.Id == outgoing.ProductId); InsufficientBalance = productQuantity == null || productQuantity.TotalAvailable < outgoing.Quantity; }
protected override async void ResetProperties() { await UpdateDataSets(); OrderDate = DateTime.Now; DeliveryDate = DateTime.Now; Delivered = false; ClientUsernameIndex = 0; ProductQuantities.Clear(); }
private void ExecuteDecrementQuantity(ProductQuantityViewModel pq) { if (pq.Quantity == 1U) { ProductQuantities.Remove(pq); } else { --pq.Quantity; } }
public void AddItem(Product product, int amount) { if (product != null && amount > 0) { if (ProductQuantities.TryGetValue(product, out int productAmount)) { ProductQuantities[product] = productAmount + amount; return; } ProductQuantities.Add(product, amount); } }
public bool RemoveItem(Product product, int amount) { Product removeProduct = ProductQuantities.Keys.FirstOrDefault(p => p.Title == product.Title); if (removeProduct != null) { int addedAmount = ProductQuantities[removeProduct]; if (amount >= addedAmount) { return(ProductQuantities.Remove(removeProduct)); } ProductQuantities[removeProduct] = addedAmount - amount; return(true); } return(false); }
public string Print() { StringBuilder builder = new StringBuilder(); var products = ProductQuantities.GroupBy(p => p.Key.Category.Title).ToDictionary(e => e.Key, e => e.ToList()); builder.AppendLine($"{"Category Name",15} {"Product Name",15} {"Quantity",15} {"Unit Price",15} {"Total Price",15}"); foreach (var item in products) { foreach (var p in item.Value) { builder.AppendLine($"{item.Key,15} {p.Key.Title,15} {p.Value,15} {p.Key.Price,15} {GetProductPrice(p.Key),15}\t"); } } builder.AppendLine($"\nTotal Amount: {GetTotalAmount()}\nTotal Amount After Discounts: {GetTotalAmountAfterDiscounts()}" + $"\nTotal Discount: {GetTotalAmount() - GetTotalAmountAfterDiscounts()}\nDelivery Cost: {GetDeliveryCost()}"); return(builder.ToString()); }
private bool CanAddProduct(IProduct product) { return(ProductQuantities.FirstOrDefault(pq => pq.Product == product) == null); }
private void ExecuteAddProduct(IProduct product) { ProductQuantities.Add(new ProductQuantityViewModel(product, 1U)); }
protected override bool CanApply() { // TODO: add ProductIdQuantityMap GUI configuration and adjust CanApply here return(ProductQuantities.Any() && ClientUsernameIndex != -1 && (!Delivered || DeliveryDate >= OrderDate)); }
public int GetNumberOfDeliveries() { return(ProductQuantities.GroupBy(e => e.Key.Category.Title).Count()); }
private Dictionary <Product, int> GetProductsByCategory(Category category) { return(ProductQuantities.Where(e => e.Key.Category == category || IsSubCategory(category, e.Key.Category)).ToDictionary(e => e.Key, e => e.Value)); }
public double GetTotalAmount() { return(ProductQuantities.Sum(e => e.Key.Price * e.Value)); }