/// <summary> /// In this form the supllier can add a new product. /// </summary> public void AddNewProduct() { Console.Clear(); Console.Write("\n Please insert the product's name: "); string productName = input.GetUserInput <string>(); Product product = storeDAO.GetProductByName(productName); // if the product name exists in the store, but belongs to another supplier. if (product.ID != 0 && product.SupplierID != currentSupplier.ID) // { Console.WriteLine("\n This product is already being offered by another supplier."); Console.WriteLine(" Press Enter to continue"); Console.ReadKey(); RegisteredSupplierMenuForm(); return; } // if the supplier already have a product with that name. if (product.ID != 0 && product.SupplierID == currentSupplier.ID) { Console.WriteLine("\n This products already being offered by you."); Console.Write(" Would you like to add to the stock? (y/n) "); string choice = input.GetUserInput <string>(); if (choice != "y") { RegisteredSupplierMenuForm(); return; } Console.Write("\n How many items Would you like to add to the stock? "); int quantity = input.GetUserInput <int>(); if ((product.Quantity + quantity) < 0) { HandleError(new ProductQuantityCannotBeNegativeNumberException("Product quantity cannot be a negative number")); RegisteredSupplierMenuForm(); return; } if (mode == TestMode.On) { return; } storeDAO.UpdateProductQuantity(product.ID, product.Quantity + quantity); storeDAO.AddLogRecord( new LogRecord(DateTime.Now, $"The supplier {currentSupplier.UserName} updated the quantity of the product '{product.Name}' to {product.Quantity + quantity}", "Yes", "")); Console.WriteLine("\n Your items has been added to the stock successfully! Press Enter to continue"); Console.ReadKey(); RegisteredSupplierMenuForm(); } product.Name = productName; product.SupplierID = currentSupplier.ID; Console.Write("\n Please insert the price of your product: "); product.Price = input.GetUserInput <decimal>(); if (product.Price < 0) { HandleError(new ProductPriceCannotBeNegativeException("Product's price cannot be negative")); RegisteredSupplierMenuForm(); return; } Console.Write("\n How many items Would you like to add to the stock? "); product.Quantity = input.GetUserInput <int>(); if ((product.Quantity) < 0) { HandleError(new ProductQuantityCannotBeNegativeNumberException("Product quantity cannot be a negative number")); RegisteredSupplierMenuForm(); return; } storeDAO.CreateNewProduct(product); if (mode == TestMode.On) { return; } Console.WriteLine("\n Your product has been added successfully! Press Enter to continue"); Console.ReadKey(); storeDAO.AddLogRecord( new LogRecord(DateTime.Now, $"The supplier {currentSupplier.UserName} added a new product '{product.Name}'", "Yes", "")); RegisteredSupplierMenuForm(); }