public void PurchaseProducts(NewPurchaseDto dto)
        {
            // check if user can purchase these products
            // save products with decreased quantity
            // handle concurent purchasing
            // create event based on database data

            var @event = new ProductsPurchased();

            mediator.Publish(@event);
        }
 public SubscriptionDTO ToDTO()
 {
     return(new SubscriptionDTO
     {
         Id = Id.ToString(),
         TotalDurationMonths = TotalDurationMonths,
         StartDate = Purchased?.ToString("yyyy-MM-dd"),
         EndDate = Expires?.ToString("yyyy-MM-dd"),
         PurchasedProducts = ProductsPurchased.Select(purchased => purchased.ToDTO()).OrderBy(purchase => purchase.DateOfPurchase),
         TotalPurchaseCostUSD = TotalPurchaseCostUSD,
         TotalTaxCostUSD = TotalTaxCostUSD,
         DatePaused = ActivePause?.Started.ToString("yyyy-MM-dd")
     });
 }
Exemple #3
0
        /// <summary>
        /// Selects product from vending machine.
        /// </summary>
        /// <param name="productKeyEntered"></param>
        public void SelectProduct(string productKeyEntered)
        {
            bool containsKey = inventory.ContainsKey(productKeyEntered);

            try
            {
                if (containsKey == true)
                {
                    if (inventory[productKeyEntered].Count <= 0)
                    {
                        Console.WriteLine("This product is sold out.");
                        Console.ReadLine();
                    }
                    else if (inventory[productKeyEntered].Price > MachineBalance)
                    {
                        Console.WriteLine("Insufficient funds.");
                        Console.ReadLine();
                    }
                    else
                    {
                        inventory[productKeyEntered].Count -= 1;
                        MachineBalance -= inventory[productKeyEntered].Price;
                        ProductsPurchased.Add(inventory[productKeyEntered].Type);
                        string productName = inventory[productKeyEntered].Name;

                        using (StreamWriter sw = new StreamWriter("logs.txt", true))
                        {
                            sw.WriteLine($"{DateTime.Now.ToString()} {inventory[productKeyEntered].Name} {productKeyEntered} {MachineBalance + inventory[productKeyEntered].Price:C2} {MachineBalance:C2}", -10);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("This code is invalid.");
                    Console.ReadLine();
                }
            }
            catch (IOException ex)
            {
                Console.WriteLine($"Error writing to log: {ex.Message}");
            }
        }