public void AddNewProduct_ProductDtoNull_ReturnOperationDetailsWithFalseValue() { repositoryMock.Setup(i => i.Create(new Product())); mock.Setup(i => i.ProductRepository).Returns(repositoryMock.Object); var result = service.AddNewProduct(null); Assert.AreEqual(result.Succedeed, new OperationDetails(false, "", "").Succedeed); }
public ActionResult AddProduct(string name, double price, string description, Category kindOfGoods, Brand brand, HttpPostedFileBase uploadImage) { byte[] imageData = null; if (uploadImage != null) { // var previosCover = editMagazine.Covers.FirstOrDefault(); // editMagazine.Covers.Remove(previosCover); imageData = ImageProcessing.ImageSaver(uploadImage); // editMagazine.Covers.Add(new Cover { CoverForModels = imageData }); } if (name != null && price.ToString() != null) { var newProduct = new Product { Name = name, Price = price, Description = description, KindOfGoods = kindOfGoods, Brand = brand, Picture = imageData }; ProductService.AddNewProduct(newProduct); return(View()); } return(View()); }
public void Start() { string name, description; decimal price; Console.WriteLine("Enter plant name: "); name = Console.ReadLine(); Console.WriteLine("Add plant description: "); description = Console.ReadLine(); Console.WriteLine("Add plant price:"); price = Convert.ToDecimal(Console.ReadLine()); try { productService.AddNewProduct(name, price, description); } catch (Exception ex) { Console.WriteLine(ex.Message); return; } productService.SaveChanges(); Console.WriteLine("New plant added! All plants in catalog listed below:"); foreach (var product in productService.GetAllProducts()) { Console.WriteLine($"\tProduct id: {product.ProductId} \tProduct name: {product.Name}"); } }
public void WhenAddingAProduct_ThatHasInvalidData_ItDoesNotSaveProductAndDoesErrorHandling() { ProductService productService = new ProductService(); Assert.Throws <WebException>(() => productService.AddNewProduct(invalidProductDto)); Assert.True(productService.Products.Count == 0); }
public void WhenAddingAProduct_ThatHasValidData_ItSavesTheProduct() { ProductService productService = new ProductService(); productService.AddNewProduct(validProductDto); Assert.True(productService.Products[0].Equals(validProduct)); }
public ActionResult SubmitProduct(ProductListModel model) { HttpSessionStateBase session = HttpContext.Session; try { Tbl_Products tg = new Tbl_Products(); tg.ProductsName = model.ProductName; tg.Description = model.Description; tg.Products_ID = model.Product_ID; tg.LastUpdateUser_ID = Convert.ToInt32(session["UserID"]); tg.LastUpdateDate = DateTime.Now.ToString("yyyy-MM-dd"); tg.LastUpdateTime = DateTime.Now.ToString("HH:mm"); if (_productService.AddNewProduct(tg)) { var gridModel = new DataSourceResult { ExtraData = new ProductListModel { Message = Message.OperationSuccessful, MessageColor = "green" }, Total = 1 }; return(Json(gridModel)); } else { var gridModel = new DataSourceResult { ExtraData = new ProductListModel { Message = Message.OperationUnsuccessful, MessageColor = "red" }, Total = 1 }; return(Json(gridModel)); } } catch (Exception ex) { var gridModel = new DataSourceResult { ExtraData = new ProductListModel { Message = Message.OperationUnsuccessful, MessageColor = "red" }, Total = 1 }; return(Json(gridModel)); } }
public async Task <IHttpActionResult> AddNewData(ProductAddModel productModel) { try { await _productService.AddNewProduct(productModel); return(Ok()); } catch (Exception e) { return(Content(HttpStatusCode.InternalServerError, e.Message)); } }
[HttpPost("/add")]//add?Name=Greta&&Description=SD public IActionResult AddById([FromBody] Product value) { var product = _productService.AddNewProduct(value.Name, value.Description, value.BrandId, value.CategoryId, value.Price); if (product == null) { return(NotFound("Bad Request")); } else { return(Ok("New produc is added")); } }
protected void btnAdd_Click(object sender, EventArgs e) { var product = new Product { Name = txtName.Text, Price = int.Parse(txtPrice.Text), CategoryId = int.Parse(ddlCategories.SelectedItem.Value) }; ProductService.AddNewProduct(product); UoW.SaveAllChanges(); Response.Redirect("~/Default.aspx"); }
public IActionResult AddById([FromQuery] string name, [FromQuery] string description, [FromQuery] int price) { var product = _productService.AddNewProduct(name, description, price); if (product == false) { return(NotFound("Bad Request")); } else { return(Ok("New produc is added")); } //[FromBody] string name, [FromBody] string description, [FromBody] int price //[FromQuery] string name, [FromQuery] string description, [FromQuery] int price }
public async Task <ActionResult <string> > Post([FromBody] string value) { UserData user = await GetUserData(Request.Headers["token"]); if (user == null) { return(Unauthorized("No valid session found for this token")); } if (user.storeId == null) { return(Unauthorized("No store found for this user")); } Product product = await ProductService.AddNewProduct((int)user.storeId, Json.Deserialize <Product>(value)); return(Ok(Json.Serialize <Product>(product))); }
private void addProductButton_Click(object sender, EventArgs e) { if (productNameTextBox.Text == "" || productPriceTextBox.Text == "" || productQuantityTextBox.Text == "" || productCategoryComboBox.Text == "") { MessageBox.Show("All boxes have to be filled"); } else { ProductService productService = new ProductService(); int result = productService.AddNewProduct(productNameTextBox.Text, productPriceTextBox.Text, productQuantityTextBox.Text, productCategoryComboBox.Text); if (result > 0) { MessageBox.Show("Product added successfully"); } else { MessageBox.Show("Error in adding product"); } } }
public static void AddProductFromConsole() { try { Console.WriteLine("Product name:"); string productName = Console.ReadLine(); Console.WriteLine("Weight unit (g for gramms/ml for mililiters):"); string portionUnit = Console.ReadLine().ToLower(); if (portionUnit != "g" && portionUnit != "ml") { throw (new ArgumentException("Incorrect input, only 'g' or 'ml' is acceptable.")); } Console.WriteLine("Product weight:"); int quantity = int.Parse(Console.ReadLine()); if (quantity < 0) { throw (new ArgumentException("The input cannot have negative value")); } Console.WriteLine("Portion weight:"); int portionQuantity = int.Parse(Console.ReadLine()); if (portionQuantity < 0) { throw (new ArgumentException("The input cannot have negative value")); } if (portionQuantity > quantity) { throw (new ArgumentException("Portion weight cannot be bigger that the Product weight")); } Console.WriteLine($"Energy (kCal) in 100{portionUnit}:"); int energy = int.Parse(Console.ReadLine()); if (energy < 0) { throw (new ArgumentException("The input cannot have negative value")); } Console.WriteLine($"Fat in 100{portionUnit}"); double fat = double.Parse(Console.ReadLine()); if (fat > 100) { throw (new ArgumentException("The weight of macro elements cannot be bigger that 100g")); } if (fat < 0) { throw (new ArgumentException("The input cannot have negative value")); } Console.WriteLine($"Carbohydrates in 100{portionUnit}:"); double carbohydrates = double.Parse(Console.ReadLine()); if (fat + carbohydrates > 100) { throw (new ArgumentException("The weight of macro elements cannot be bigger that 100g")); } if (carbohydrates < 0) { throw (new ArgumentException("The input cannot have negative value")); } Console.WriteLine($"Protein in 100{portionUnit}:"); double protein = double.Parse(Console.ReadLine()); if (fat + carbohydrates + protein > 100) { throw (new ArgumentException("The weight of macro elements cannot be bigger that 100g")); } if (protein < 0) { throw (new ArgumentException("The input cannot have negative value")); } Console.WriteLine($"Salt in 100{portionUnit}"); double salt = double.Parse(Console.ReadLine()); if (salt + fat + carbohydrates + protein > 100) { throw (new ArgumentException("The weight of macro elements cannot be bigger that 100g")); } if (salt < 0) { throw (new ArgumentException("The input cannot have negative value")); } Console.WriteLine($"Fiber in 100{portionUnit}:"); int fiber = int.Parse(Console.ReadLine()); if (fiber + salt + fat + carbohydrates + protein > 100) { throw (new ArgumentException("The weight of macro elements cannot be bigger that 100g")); } if (fiber < 0) { throw (new ArgumentException("The input cannot have negative value")); } Console.WriteLine($"Sugar in 100{portionUnit}:"); int sugar = int.Parse(Console.ReadLine()); if (sugar > carbohydrates) { throw (new ArgumentException("The weight of sugars cannot be bigger that weight of carbohydrates")); } if (sugar < 0) { throw (new ArgumentException("The input cannot have negative value")); } ID++; ProductService.AddNewProduct(ID, productName, portionUnit, quantity, portionQuantity, energy, fat, carbohydrates, protein, sugar, salt, fiber, ListOfProducts); Console.WriteLine($"Product {productName} been added to the product list."); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } catch (Exception error) { Console.WriteLine(error.Message); Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } }
// POST api/<controller> public void Post(Product model) { service.AddNewProduct(model); }