protected FarmUnit(string id, int health, int productionQuantity, Product product)
     : base(id)
 {
     this.Health = health;
     this.ProductionQuantity = productionQuantity;
     this.Product = product;
 }
Esempio n. 2
0
        public override Product GetProduct()
        {
            if (!this.HasGrown) { throw new Exception("Plant is not grown yet");}
            if (!this.IsAlive) { throw new Exception("Tabacco plant is dead");}
            var product= new Product(string.Format(this.Id+"Product"),ProductType.Tobacco,productionQuantity);

            return product;
        }
Esempio n. 3
0
 public void AddProduct(Product product)
 {
     var foundProduct = this.Products.FirstOrDefault(x => x.Id == product.Id);
     if (foundProduct != null)
     {
         foundProduct.Quantity += product.Quantity;
     }
     else
     {
         this.Products.Add(product);
     }
 }
 public void AddProduct(Product product)
 {
     var productWithSameId = this.Products.Where(p => p.Id == product.Id).Select(p => p).FirstOrDefault();
     if (productWithSameId != null)
     {
         productWithSameId.Quantity += product.Quantity;
     }
     else
     {
         this.Products.Add(product);
     }
 }
Esempio n. 5
0
        public void AddProduct(Product productToBeAdded)
        {
            Product currentProduct = this.products.Find(x => x.Id == productToBeAdded.Id);

            if (currentProduct == null)
            {
                this.products.Add(productToBeAdded);
            }
            else
            {
                currentProduct.Quantity += productToBeAdded.Quantity;
            }
        }
Esempio n. 6
0
        public void AddProduct(Product product)
        {
            var existingProduct = this.Products
                .FirstOrDefault(p => p.Id == product.Id);

            if (existingProduct != null)
            {
                existingProduct.Quantity += product.Quantity;
            }
            else
            {
                this.Products.Add(product);
            }
        }
Esempio n. 7
0
        public override Product GetProduct()
        {
            if (!this.IsAlive)
            {
                throw new InvalidOperationException("Tobacco is dead!");
            }

            if (!this.HasGrown)
            {
                throw new InvalidOperationException("Tobacco is still growing!");
            }

            var product = new Product(this.Id + "Product", ProductType.Tobacco, this.ProductionQuantity);

            return product;
        }
Esempio n. 8
0
 public static Product ProduceProduct(string originalID, ProductType productType)
 {
     string productID = originalID + PlantValues.PlantProductIDIndex;
     Product currentProduct;
     switch (productType)
     {
         case ProductType.Grain:
             {
                 currentProduct = new Food(productID);
                 LoadGrainProductValues(currentProduct as Food);
                 return currentProduct as Food;
             }
         case ProductType.Tobacco:
             {
                 currentProduct = new Product(productID);
                 LoadTobaccoProductValues(currentProduct);
                 return currentProduct;
             }
         case ProductType.Cherry:
             {
                 currentProduct = new Food(productID);
                 LoadCherryProductValues(currentProduct as Food);
                 return currentProduct;
             }
         case ProductType.Milk:
             {
                 currentProduct = new Food(productID);
                 LoadMilkProductValues(currentProduct as Food);
                 return currentProduct as Food;
             }
         case ProductType.PorkMeat:
             {
                 currentProduct = new Food(productID);
                 LoadPorkMeatProductValues(currentProduct as Food);
                 return currentProduct as Food;
             }
         default:
             {
                 throw new NotImplementedException("Unknown product type " + productType);
             }
     }
 }
Esempio n. 9
0
        public void AddProduct(Product product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }

            // If a product with a given Id is added to the farm and another product with the same Id already exists, only the quantity of the existing product is increased
            if (this.products.Any(x => x.Id == product.Id))
            {
                foreach (var item in this.products.Where(item => item.Id == product.Id))
                {
                    item.Quantity += product.Quantity;
                }
            }
            else
            {
                this.products.Add(product);
            }
        }
Esempio n. 10
0
 public void AddProduct(Product product)
 {
     bool alreadyExcists = false;
     for (int i = 0; i < Products.Count; i++)
     {
         if (Products[i].Id == product.Id)
         {
             alreadyExcists = true;
         }
     }
     if (alreadyExcists)
     {
         for (int i = 0; i < Products.Count; i++)
         {
             if (Products[i].Id == product.Id)
             {
                 Products[i].Quantity += product.Quantity;
             }
         }
     }
     else { this.Products.Add(product);}
 }
Esempio n. 11
0
 private static void LoadTobaccoProductValues(Product currentProduct)
 {
     currentProduct.Quantity = PlantValues.TobaccoPlantProductQuantity;
 }
Esempio n. 12
0
 public void AddProduct(Product product)
 {
     this._products.Add(product);
 }
Esempio n. 13
0
 public void AddProduct(Product product)
 {
     throw new NotImplementedException();
 }
Esempio n. 14
0
 public virtual Product GetProduct()
 {
     Product product = new Product(this.productId, this.productType, this.ProductionQuantity);
     return product;
 }