public ReturnMessage AddProduct(Product product) { int productNameMaxLength = 40; int quantityPerUnitMaxLength = 20; if (product.ProductName.Length > productNameMaxLength || string.IsNullOrWhiteSpace(product.ProductName)) { message.Value = ValueTooLongOrEmptyMessage(productNameMaxLength, "Product Name"); return(message); } else if (product.QuantityPerUnit.Length > quantityPerUnitMaxLength || string.IsNullOrWhiteSpace(product.QuantityPerUnit)) { message.Value = ValueTooLongOrEmptyMessage(quantityPerUnitMaxLength, "Quantity Per Unit"); return(message); } else if (product.UnitPrice < 0) { message.Value = InvalidNumber("Unit Price"); return(message); } else if (product.UnitsInStock < 0) { message.Value = InvalidNumber("Units In Stock"); return(message); } else if (product.UnitsOnOrder < 0) { message.Value = InvalidNumber("Units On Order"); return(message); } else if (product.ReorderLevel < 0) { message.Value = InvalidNumber("Reorder Level"); return(message); } bool isProductContained = productManagement.IsProductContained(product); if (!isProductContained) { bool isAdded = productManagement.AddProduct(product); if (isAdded) { message.Value = $"{product.ProductName} is successfully added."; message.isSuccessful = true; } else { message.Value = DatabaseErrorMessage(); } return(message); } else { message.Value = AlreadyExists(); return(message); } }
public void ProductManagementCalculate_Incorrect(string name, double price) { var management = new ProductManagement(); var newProduct = new Product { Name = name, Price = price }; management.AddProduct(newProduct); Assert.Empty(management.Products); }
public bool AddProduct(Product product) { if (string.IsNullOrWhiteSpace(product.ProductName) & product.ProductName.Length > 15) { return(false); } bool isAdded = productManagement.AddProduct(product); return(isAdded); }
public void AddProduct(string productName, int supplierID, int categoryID, string quantityPerUnit, bool discontinued, out int effectedRowCount) { if (categoryID == 1) { effectedRowCount = 0; } else { //DAL'a gönder; _productManagement.AddProduct(productName, supplierID, categoryID, quantityPerUnit, discontinued, out effectedRowCount); } }
public void ProductManagementCalculate_MoreThanOneTime_Correct(string name, double price) { var management = new ProductManagement(); var newProduct = new Product { Name = name, Price = price }; var addProductTimes = 3; for (int i = 0; i < addProductTimes; i++) { management.AddProduct(newProduct); } Assert.Equal(addProductTimes, management.Products.Count); }
public ActionResult Create(FormCollection form) { //var listModel = db.ValidateModel(artist); //if (ModelIsValid(listModel)) // return View(artist); //try //{ // db.Create(artist); // return RedirectToAction("Index"); //} //catch (Exception ex) //{ // Logger.Instance.LogException(ex); // ViewBag.MessageDanger = ex.Message; // return View(artist); //} var product = new Product(); product.Title = form["title"]; product.Description = form["description"]; product.ArtistId = Convert.ToInt32(form["artistId"]); product.QuantitySold = Convert.ToInt32(form["quantitySold"]); product.AvgStars = double.Parse(form["avgStars"], System.Globalization.CultureInfo.InvariantCulture); product.Price = Convert.ToInt32(form["price"]); // uploaded image if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Images/Products"), fileName); file.SaveAs(path); product.Image = file.FileName; } } CheckAuditPattern(product, true); ProductManagement.AddProduct(product); return(RedirectToAction("Index")); }
public void AddProduct(Product entity) { _productManagementDAL.AddProduct(entity); }
public void CreateProduct([FromBody] Product product) => _productManagement.AddProduct(product);