/// <summary> /// UI to add a product /// </summary> private void AddAProduct() { Console.WriteLine("\nEnter the details of the product you want to add"); string itemName = _validate.ValidateString("Enter the product name: "); double price = _validate.ValidatePrice("Enter the price of the product: "); string description = _validate.ValidateString("Enter a description for the product: "); Log.Information("Product information input"); try { // New product model created and sent to Business Logic Product newProduct = new Product(itemName, price, description); Log.Information("UI sent new product to BL"); Product createdProduct = _productBL.AddProduct(newProduct); List <int> productQuantity = new List <int>(); List <Location> locations = _locationBL.GetAllLocations(); List <Product> products = _productBL.GetAllProducts(); // Ensure quantity is set to 0 for all locations so customer may not purchase before stocked foreach (Product item in products) { productQuantity.Add(0); } foreach (Location location in locations) { Log.Information("UI sent updated inventory to BL"); _inventoryBL.ReplenishInventory(location.StoreName, productQuantity); } Console.WriteLine("New Product Created\n"); Console.WriteLine(createdProduct.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public ActionResult AddProduct(ProductModel productModel) { if (ModelState.IsValid) { Product product = AutoMapper.Mapper.Map <ProductModel, Product>(productModel); List <Category> categories = productBL.DownDrop(); ViewBag.categories = new SelectList(categories, "CategoryId", "CategoryName"); productBL.AddProduct(product); return(RedirectToAction("ProductDetails")); } return(View()); }
public void CreateProduct() { Product newProduct = new Product(); Console.WriteLine("Enter Product Name: "); newProduct.ProductName = Console.ReadLine(); Console.WriteLine("Enter Product Details: "); newProduct.ProductDescription = Console.ReadLine(); Console.WriteLine("Enter Product ID (####): "); newProduct.ProductID = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Product Price: "); newProduct.ProductPrice = double.Parse(Console.ReadLine()); _productBL.AddProduct(newProduct); Console.WriteLine($"Product {newProduct.ProductName} created successfully!"); }
private void AddProduct() { string name = _validate.ValidateEmptyInput("Enter Product Name:"); decimal price = _validate.ValidatePrice("Enter product Price"); string barcode = _validate.ValidateEmptyInput("Enter Product Barcode:"); try { Product newProdcut = new Product(name, price, barcode); Product createdProduct = _productBL.AddProduct(newProdcut); Console.WriteLine($"Product: {createdProduct.Name} is created successfully."); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void CreateProduct() { Product newProduct = new Product(); Console.Write("Product Name:\t"); newProduct.ProdName = Console.ReadLine(); Console.Write("Price:\t\t"); newProduct.ProdPrice = double.Parse(Console.ReadLine()); Console.Write("\nCategory List:" + "\nBrakes\t\tExhaust\t\tIntake\t\tDrivetrain" + "\nForcedInduction\tStyling\t\tEngine\t\tFueling" + "\nSuspension\tTuningAndGuages\tWheels\t\tAccessories\n\n"); Console.Write("Category:\t\t"); newProduct.ProdCategory = Enum.Parse <Category>(Console.ReadLine()); Console.Write("Brand Name:\t"); newProduct.ProdBrandName = Console.ReadLine(); _productBL.AddProduct(newProduct); }
[HttpPost]//posting to the view public ActionResult AddProduct(ProductModel image) { try { ViewBag.ProductCategories = new SelectList(productCategoryDetails.DisplayProduct(), "ProductCatogeryId", "productCatogeryName"); if (ModelState.IsValid) { string filename = Path.GetFileNameWithoutExtension(image.ImageUpload.FileName); string extension = Path.GetExtension(image.ImageUpload.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; image.ProductImagePath = filename; OnlineJewellShop.Entity.Product productMap = AutoMapper.Mapper.Map <ProductModel, Product>(image); filename = Path.Combine(Server.MapPath("~/ProductImages/"), filename); if (extension == ".jpg" || extension == ".png") { image.ImageUpload.SaveAs(filename); int result = productDetails.AddProduct(productMap); if (result > 0) { return(RedirectToAction("ViewProduct")); } } else { ViewBag.Image = "Selected file is not in the correct format please select image file"; } } return(View()); } catch { return(RedirectToAction("Error", "Error")); } }
public void AddNewProduct(int locId) { //create new product & inventory for that product Product newProduct = new Product(); Inventory newInventory = new Inventory(); Console.WriteLine("Please enter product name: "); newProduct.ProductName = Console.ReadLine(); Console.WriteLine("Please enter price of product per pint: "); newProduct.ProductPrice = decimal.Parse(Console.ReadLine()); Console.WriteLine("Please enter quantity of product in pints: "); newInventory.Quantity = int.Parse(Console.ReadLine()); _productBL.AddProduct(newProduct); newInventory.ProductId = _productBL.GetProducts().Last().ProductID; newInventory.LocationId = locId; _inventoryBL.AddInventory(newInventory); Console.WriteLine($"{newProduct.ProductName} added to products!"); }
public ActionResult Create(ProductCRVM newProduct) { if (ModelState.IsValid) { try { _productBL.AddProduct(_mapper.cast2Product(newProduct)); //Helper.WriteInformation($"Product created-- Email: {newProduct.ProductEmail}"); Log.Information($"Product created-- Name: {newProduct.ProdName}"); return(RedirectToAction(nameof(Index))); } catch (Exception e) { Helper.WriteError(e, "Error"); Helper.WriteFatal(e, "Fatal"); Helper.WriteVerbose(e, "Verbose"); return(View()); } finally { } } return(View()); }
public void AddProduct() { Console.Clear(); AsciiHeader.AsciiHead(); Product newProduct = new Product(); //newProduct.ProductID = _productBL.GenerateID(); Console.WriteLine("Enter new Product Name:"); newProduct.ProductName = Console.ReadLine(); Console.WriteLine("Enter new Product Description:"); newProduct.ProductDescription = Console.ReadLine(); Console.WriteLine("Enter product manufacturer: "); newProduct.Manufacturer = Console.ReadLine(); Console.WriteLine("Enter Product Price"); newProduct.ProductPrice = Decimal.Parse(Console.ReadLine()); _productBL.AddProduct(newProduct); Console.WriteLine($"Product {newProduct.ProductName} created successfully!"); Log.Information("New Product added to system"); Console.WriteLine("Press enter to continue."); Console.ReadLine(); }