Exemple #1
0
 /// <summary>
 /// converts a production order object into a production order entity
 /// </summary>
 /// <param name="order">product order to be converted</param>
 /// <returns>production order entity</returns>
 public static Entities.ProductOrder MapProductOrder(Business.ProductOrder order)
 {
     return(new Entities.ProductOrder
     {
         Id = order.Id,
         OrderId = order.OrderId,
         ProductId = order.ProductId,
         Quantity = order.Quantity,
     });
 }
        /// <summary>
        /// updates a productOrder in th database
        /// </summary>
        /// <param name="productOrder">product order to update</param>
        public void AddProductOrder(Business.ProductOrder productOrder)
        {
            Entities.ProductOrder entity = new Entities.ProductOrder()
            {
                Id        = 0,
                OrderId   = productOrder.OrderId,
                ProductId = productOrder.ProductId,
                Quantity  = productOrder.Quantity,
            };

            _context.Add(entity);
        }
Exemple #3
0
        /// <summary>
        /// sub menu for creating a new order then adding it to the database
        /// </summary>
        /// <param name="data">the DBcontect for the database</param>
        public static void PlaceOrder(IDataBase data)
        {
            List <Customer> customers = data.GetAllCustomers().ToList();
            List <Location> locations = data.GetAllLocations().ToList();

            if (locations.Count == 0)
            {
                Console.WriteLine("There are no locations to make a puchase: Press enter to return to the main menu");
                Console.ReadLine();
                return;
            }

            if (customers.Count == 0)
            {
                Console.WriteLine("There are no customers to make a puchase: Press enter to return to the main menu");
                Console.ReadLine();
                return;
            }

            Customer customer = customers[GetValidCustomer(customers)];
            Location location = locations[GetValidLocation(locations)];

            if (location.Inventory.Count == 0)
            {
                Console.WriteLine("The location has no products to sell: Press enter to return to the main menu");
                Console.ReadLine();

                return;
            }

            Order order = new Order()
            {
                Id         = 0,
                LocationId = location.Id,
                CustomerId = customer.Id,
            };

            bool orderReady = false;

            while (!orderReady)
            {
                ProductEntery product = location.Inventory[GetValidProductEntery(location.Inventory)];
                Console.WriteLine("Enter the quantity to perchase: ");

                int quantity;
                if (int.TryParse(Console.ReadLine(), out quantity))
                {
                    Business.ProductOrder productOrder = new Business.ProductOrder()
                    {
                        Name         = product.Name,
                        Id           = 0,
                        OrderId      = 0,
                        ProductId    = product.ProductId,
                        Quantity     = quantity,
                        PricePerUnit = product.PricePerUnit,
                    };

                    order.AddProduct(productOrder);
                }
                else
                {
                    Console.WriteLine("Quantity was invalid:");
                }

                Console.WriteLine("---Current order information---");
                PrintOrder(order);

                Console.Write("[y/n] - would you like to add another product to the order: ");

                if (Console.ReadLine() == "n")
                {
                    orderReady = true;

                    try
                    {
                        location.PlaceOrder(order);
                        customer.Orders.Add(order);

                        data.AddOrder(order);
                        data.Save();

                        foreach (ProductEntery p in location.Inventory)
                        {
                            data.UpdateProductEntry(p);
                        }

                        data.UpdateLocation(location);
                        data.UpdateCustomer(customer);
                        data.Save();

                        PrintOrder(order);
                        Console.Write("Order placed: Press enter to return to the main menu: ");
                        Console.ReadLine();
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine($"Error while placing order: {ex.Message}");
                        Console.Write("Press enter to return to the main menu: ");
                        Console.ReadLine();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        Log.Warning("Error in database update {Message}", ex.Message);
                        Console.WriteLine($"Error in updating database: {ex.Message}");
                    }
                    catch (DbUpdateException ex)
                    {
                        Log.Warning("Error in database update {Message}", ex.Message);
                        Console.WriteLine($"Error in updating database: {ex.Message}");
                    }
                }
            }
        }