Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
 private double GetProductPrice(Product product)
 {
     if (ProductQuantities.TryGetValue(product, out int quantity))
     {
         return(product.Price * quantity);
     }
     throw new KeyNotFoundException(nameof(product));
 }
Exemplo n.º 3
0
        private void CheckQuantityAvailableForRevert(IIncomingProduct incoming)
        {
            ProductQuantity productQuantity = ProductQuantities
                                              .SingleOrDefault(p => p.Id == incoming.ProductId);

            InsufficientBalance =
                productQuantity == null ||
                productQuantity.TotalAvailable < incoming.Quantity;
        }
Exemplo n.º 4
0
        private void CheckQuantityAvailableFor(IOutgoingProduct outgoing)
        {
            ProductQuantity productQuantity = ProductQuantities
                                              .SingleOrDefault(p => p.Id == outgoing.ProductId);

            InsufficientBalance =
                productQuantity == null ||
                productQuantity.TotalAvailable < outgoing.Quantity;
        }
Exemplo n.º 5
0
        protected override async void ResetProperties()
        {
            await UpdateDataSets();

            OrderDate           = DateTime.Now;
            DeliveryDate        = DateTime.Now;
            Delivered           = false;
            ClientUsernameIndex = 0;
            ProductQuantities.Clear();
        }
Exemplo n.º 6
0
 private void ExecuteDecrementQuantity(ProductQuantityViewModel pq)
 {
     if (pq.Quantity == 1U)
     {
         ProductQuantities.Remove(pq);
     }
     else
     {
         --pq.Quantity;
     }
 }
Exemplo n.º 7
0
 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);
     }
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
 private bool CanAddProduct(IProduct product)
 {
     return(ProductQuantities.FirstOrDefault(pq => pq.Product == product) == null);
 }
Exemplo n.º 11
0
 private void ExecuteAddProduct(IProduct product)
 {
     ProductQuantities.Add(new ProductQuantityViewModel(product, 1U));
 }
Exemplo n.º 12
0
 protected override bool CanApply()
 {
     // TODO: add ProductIdQuantityMap GUI configuration and adjust CanApply here
     return(ProductQuantities.Any() && ClientUsernameIndex != -1 && (!Delivered || DeliveryDate >= OrderDate));
 }
Exemplo n.º 13
0
 public int GetNumberOfDeliveries()
 {
     return(ProductQuantities.GroupBy(e => e.Key.Category.Title).Count());
 }
Exemplo n.º 14
0
 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));
 }
Exemplo n.º 15
0
 public double GetTotalAmount()
 {
     return(ProductQuantities.Sum(e => e.Key.Price * e.Value));
 }