private void Add(Product product, bool checkAddCodes)
 {
     if (null == product)
     {
         throw new Exception("A product must be provided");
     }
     inventoryRepository.Add(product);
     if (checkAddCodes)
     {
         List <Category>   existingCategories  = categoryRepository.Fetch();
         List <Contract>   existingContracts   = contractRepository.Fetch(0, int.MaxValue);
         List <Contractor> existingContractors = contractorRepository.Fetch(0, int.MaxValue);
         AddCategory(existingCategories, product.Category, product.ProductType);
         AddContract(existingContracts, product.ContractNumber);
         AddContractor(existingContractors, product.Contractor);
     }
 }
        public string GenerateOrders(int count)
        {
            var products = inventoryRepository.Fetch(0, int.MaxValue);

            if (null == products || products.Count == 0)
            {
                return("Products must first be added to the catalog.");
            }
            var contractors = contractorRepository.Fetch(0, int.MaxValue);

            if (null == contractors || contractors.Count == 0)
            {
                return("Products with Contractors must first be added to the catalog.");
            }
            var users = userRepository.GetUsers();

            if (null == users || users.Count == 0)
            {
                return("Users must first be added to the system.");
            }
            Random        random         = new Random((int)DateTime.Now.Ticks);
            StringBuilder result         = new StringBuilder();
            int           orderCount     = 0;
            int           orderItemCount = 0;
            HashSet <int> includedItems  = new HashSet <int>();

            for (int i = 0; i < count; i++)
            {
                orderCount++;
                int   itemCount = random.Next(10) + 1;
                Order order     = BuildRandomOrder(random, users);
                orderRepository.Add(order);
                includedItems.Clear();
                for (int j = 0; j < itemCount; j++)
                {
                    orderItemCount++;
                    var       product = GetNextProduct(products, random, includedItems);
                    OrderItem item    = new OrderItem();
                    item.OrderId   = order.Id;
                    item.Price     = product.ContractPrice;
                    item.ProductId = product.Id;
                    item.Quantity  = 1 + random.Next(6);
                    orderItemRepository.Add(item);
                }
            }
            result.AppendFormat("Added {0} orders\r\n", orderCount);
            result.AppendFormat("Added {0} order items\r\n", orderItemCount);
            return(result.ToString());
        }
 public IEnumerable <Contractor> Fetch(int start, int count)
 {
     return(contractorRepository.Fetch(start, count));
 }