Exemple #1
0
        /// <summary>
        /// Print this menu.
        /// </summary>
        public void PrintMenu()
        {
            Console.Clear();
            CliPrinter.Title("Order Items");
            this.ApplicationState.UserData.RefreshCurrentOrder();

            if (this.ApplicationState.UserData.CurrentOrderId == null)
            {
                using (var db = new StoreContext(this.ApplicationState.DbOptions))
                {
                    var customer = db.GetCustomerById(this.ApplicationState.UserData.CustomerId);
                    var location = db.GetLocationById(this.ApplicationState.UserData.OperatingLocationId);
                    var order    = new Order(customer, location);
                    order.Customer = customer;
                    db.Add(order);
                    db.SaveChanges();
                    this.ApplicationState.UserData.CurrentOrderId = order.OrderId;
                }
            }

            using (var db = new StoreContext(this.ApplicationState.DbOptions))
            {
                var inventory = db.GetProductsAvailable(this.ApplicationState.UserData.OperatingLocationId);

                var order = db.GetOrderById(this.ApplicationState.UserData.CurrentOrderId);

                var i = 1;
                this.InventoryIds = inventory.Select(i => i.LocationInventoryId).ToList();
                Console.WriteLine("#\tStock\tName");
                foreach (var stock in inventory)
                {
                    var projectedQuantity = db.ProjectStockBasedOnOrder(order, stock.Product);
                    if (projectedQuantity < 0)
                    {
                        projectedQuantity = 0;
                    }
                    Console.WriteLine($"{i}.\t{projectedQuantity}\t{stock.Product.Name}");
                    i += 1;
                }
                Console.Write("\n----------------------------------------------\n");
            }
        }
Exemple #2
0
        /// <summary>
        /// Sets the default location to be used by a customer.
        /// </summary>
        /// <param name="options">Options for creating a new context.</param>
        /// <param name="customerId">The ID of the customer to operate upon.</param>
        /// <param name="locationId">The location ID to set as the default.</param>
        /// <returns>Whether the operation succeeded.</returns>
        public static bool SetDefaultLocation(this DbContextOptions <StoreContext> options, Guid?customerId, Guid?locationId)
        {
            if (customerId == null || locationId == null)
            {
                return(false);
            }

            using (var db = new StoreContext(options))
            {
                var location = db.GetLocationById(locationId);
                var customer = db.GetCustomerById(customerId);
                if (location == null || customer == null)
                {
                    return(false);
                }

                customer.DefaultLocation = location;
                db.SaveChanges();
                return(true);
            }
        }