public IActionResult AddProduct(Product product) { try { _productServices.AddProduct(product); return(CreatedAtAction("AddProduct", product)); } catch (Exception) { return(BadRequest()); } }
public IHttpActionResult AddToCart(Product productId) { try { ProductServices service = new ProductServices(); service.AddProduct(productId.ProductGuid); return(Ok()); } catch (Exception) { throw; } }
private void btnProductAdd_Click(object sender, EventArgs e) { Products product = new Products(); product.Name = txtProductName.Text; product.Price = (float)Convert.ToDecimal(txtProductPrice.Text); //? product.Description = txtProductDescription.Text; product.CategoryId = cmbProductCategory.SelectedIndex + 1; //zerobase (index + 1)=categoryId productsServices.AddProduct(product); FillProductsDataGridView(); FillProductsComboBox(); }
public void DeleteproductTestNegative(string id) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var sut = services.DeleteProduct(id); sut.Should().NotBeNull(); sut.IsSuccess.Should().Be(false); sut.Error.Should().NotBeNullOrWhiteSpace(); }
public void DeleteproductTestPositive(string id) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var sut = services.DeleteProduct(id); sut.Should().NotBeNull(); sut.IsSuccess.Should().Be(true); sut.Value.Count().Should().Be(_products.Count - 1); }
public void AddFeedbackTestPositive(string id, string key, int value) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var sut = services.AddFeedback(id, new KeyValuePair <string, int> (key, value)); sut.Should().NotBeNull(); sut.IsSuccess.Should().Be(true); sut.Value.FeedBacks.Last().Value.Should().Be(value); sut.Value.FeedBacks.Last().Key.Should().Be(key); }
public void RatingTestPositive(string id, decimal rating) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var searchModel = new ProductSearchModel() { Id = id }; var sut = services.GetProducts(searchModel); sut.Value.First().Rating.Should().Be(rating); }
public void GetByRatingTestPositive(decimal ratingmin, decimal ratingmax, int result) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var searchModel = new ProductSearchModel() { RatingMin = ratingmin, RatingMax = ratingmax }; var sut = services.GetProducts(searchModel); sut.Value.Count.Should().Be(result); }
public void GetByBrandTestPositive(string brand, int rez) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var searchModel = new ProductSearchModel() { Brand = brand }; var sut = services.GetProducts(searchModel); sut.Value.Should().NotBeNullOrEmpty(); sut.Value.Count.Should().Be(rez); sut.Value.First().Id.Should().Be(_products.First(p => p.Brand == brand).Id); }
public void GetByProductNameTestPositive(string name) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var searchModel = new ProductSearchModel() { ProductName = name }; var sut = services.GetProducts(searchModel); sut.Value.Should().NotBeNullOrEmpty(); sut.Value.Count.Should().Be(1); sut.Value.First().Id.Should().Be(_products.First(p => p.ProductName == name).Id); }
private void button3_Click(object sender, EventArgs e) { ProductInfo product = new ProductInfo(); product.Productaddr = this.tex_productaddr.Text; product.Productdru = this.tex_productdru.Text; product.Productname = this.text_productname.Text; product.Productnum = this.tex_productnum.Text; product.Productpd = this.cmb_pd.SelectedText; product.Productpprice = float.Parse(this.tex_productpprice.Text); product.Productprice = float.Parse(this.tex_productprice.Text); if (this.chk_prista.Checked) { product.Productpristata = "是"; } else { product.Productpristata = "否"; } if (this.chk_psta.Checked) { product.Productstata = "是"; } else { product.Productstata = "否"; } product.Producttype = "无类型"; //*做提交操作,*/ int ret = ProductServices.AddProduct(product); if (ret > 0) { MessageBox.Show("添加成功!"); this.dataGridView1.DataSource = ProductServices.GetAllProduct(); } else { MessageBox.Show("添加失败!"); } }
public void UpdateProductTestPositive(string id, string productName) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var product = new Product() { Id = id, Brand = "BMW", ProductName = productName, FeedBacks = new Dictionary <string, int>() { { "good", 3 }, { "very good", 4 } } }; var sut = services.UpdateProduct(id, product); sut.IsSuccess.Should().Be(true); sut.Value.ProductName.Should().Be(productName); }
public void UpdateProductTestNegative(string id, string productName) { var cache = new MemoryCache(new Mock <MemoryCacheOptions>().Object); var cacheManager = new CacheManager(cache, options); var services = new ProductServices(cacheManager); services.AddProduct(_products); var product = new Product() { Id = id, Brand = "BMW", ProductName = productName, FeedBacks = new Dictionary <string, int>() { { "good", 3 }, { "very good", 4 } } }; var sut = services.UpdateProduct(id, product); sut.Should().NotBeNull(); sut.IsSuccess.Should().Be(false); sut.Error.Should().NotBeNullOrWhiteSpace(); }
public IActionResult Tambah() { var tambah = _service.AddProduct(); return(View()); }
protected void btnSave_Click(object sender, EventArgs e) { string response = ""; if (lblProductId.Text == "") { if (!productServices.IsProductAlreadyExists(0, "Add", tbProductName.Text)) { string ext = System.IO.Path.GetExtension(fileProductImage.FileName); if (ext.ToLower() == ".jpg" || ext.ToLower() == ".png" || ext.ToLower() == ".jpeg" || ext.ToLower() == ".gif") { fileProductImage.SaveAs(Server.MapPath("~/Admin/ProductImages/" + fileProductImage.FileName)); product.ProductName = tbProductName.Text; product.CategoryId = Convert.ToInt32(ddlCategory.SelectedValue); product.Price = Convert.ToDouble(tbPrice.Text); product.IsFeature = Convert.ToByte(chkIsFeature.Checked); product.Ingredients = tbProductIngridents.Text; product.Image = "~/Admin/ProductImages/" + fileProductImage.FileName; response = productServices.AddProduct(product); if (response == "Success") { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Success','Product is added.')", true); Clear(); BindProductsGv(); } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','" + response + "')", true); } } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','Please select image only.')", true); } } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','Product name is already exists.')", true); } } else { if (!productServices.IsProductAlreadyExists(Convert.ToInt32(lblProductId.Text), "Update", tbProductName.Text)) { if (fileProductImage.HasFile) { string ext = System.IO.Path.GetExtension(fileProductImage.FileName); if (ext.ToLower() == ".jpg" || ext.ToLower() == ".png" || ext.ToLower() == ".jpeg" || ext.ToLower() == ".gif") { fileProductImage.SaveAs(Server.MapPath("~/Admin/ProductImages/" + fileProductImage.FileName)); Product oldProduct = new Product(); oldProduct = productServices.GetProductById(Convert.ToInt32(lblProductId.Text)); oldProduct.ProductName = tbProductName.Text; oldProduct.CategoryId = Convert.ToInt32(ddlCategory.SelectedValue); oldProduct.Price = Convert.ToDouble(tbPrice.Text); oldProduct.IsFeature = Convert.ToByte(chkIsFeature.Checked); oldProduct.Ingredients = tbProductIngridents.Text; oldProduct.Image = "~/Admin/ProductImages/" + fileProductImage.FileName; response = productServices.UpdateProduct(oldProduct); if (response == "Success") { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Success','Product is updated.')", true); Clear(); BindProductsGv(); } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','" + response + "')", true); } } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','Please select image only.')", true); } } else { Product oldProduct = new Product(); oldProduct = productServices.GetProductById(Convert.ToInt32(lblProductId.Text)); oldProduct.ProductName = tbProductName.Text; oldProduct.CategoryId = Convert.ToInt32(ddlCategory.SelectedValue); oldProduct.Price = Convert.ToDouble(tbPrice.Text); oldProduct.IsFeature = Convert.ToByte(chkIsFeature.Checked); oldProduct.Ingredients = tbProductIngridents.Text; response = productServices.UpdateProduct(oldProduct); if (response == "Success") { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Success','Product is updated.')", true); Clear(); BindProductsGv(); } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','" + response + "')", true); } } } else { ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "showAlert('Error!','Product name is already exists.')", true); } } }
public void TestMethodAddProdcut() { productServices.AddProduct("ABC123", "Pencil 2B", (decimal)15.00, (decimal)25.00); }