public ActionResult Create(FormCollection fc) { string newProductName = fc.Get("productName"); int categoryId = Convert.ToInt32(fc.Get("categoryId")); _productService.CreateProduct(newProductName, categoryId); return(View("Product")); }
public ActionResult Create(ProductEntity productEntity) { if (ModelState.IsValid) { _productServices.CreateProduct(productEntity); return(RedirectToAction("Index", "Home")); } return(View(productEntity)); }
public bool Post([FromBody] ProductEntity productEntity) { try { return(_productServices.CreateProduct(productEntity)); } catch (Exception ex) { throw new ApiDataException(1000, "Product Not Found", HttpStatusCode.NotFound); } }
public IActionResult CreateProduct(CreateProductListVM createProduct) { var product = _productServices.CreateProduct(createProduct); if (!ModelState.IsValid) { return(RedirectToAction("CreateProduct", new { error = "Product is not created, fields are required!" })); } return(RedirectToAction("Index", "Home", new { message = "Product was created!" })); }
public HttpResponseMessage CreateProduct([FromBody] ProductEntity productEntity) { try { _productServices.CreateProduct(productEntity); } catch (Exception) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something went wrong, product is not created")); } return(Request.CreateResponse(HttpStatusCode.OK, "Product has been created")); }
public async Task <IActionResult> Create([Bind("Code,Name,Number,MFG,EXP,Country,Description,Price,MainImage,RecieveDate,SupplyId,StockId,BrandId,Id,CreatedDate,ModifiedDate,ImageFile,DisplayName")] Product product) { if (ModelState.IsValid) { await _productServices.CreateProduct(product); return(RedirectToAction(nameof(Index))); } ViewData["BrandId"] = new SelectList(await _brandServices.GetBrand(), "Id", "ShortName", product.Brand.ShortName); ViewData["StockId"] = new SelectList(await _stockServices.GetStock(), "Id", "Name", product.Stock.Name); ViewData["SupplyId"] = new SelectList(await _userServices.GetSupply(), "Id", "SupplyName", product.User.SupplyName); return(View(product)); }
public IActionResult AddProduct([FromBody] ProductViewModel product) { var res = _productService.CreateProduct( new ProductDto { Name = product.Name, Description = product.Description, Discount = product.Discount, Price = product.Price, Quantity = product.Quantity }); return(Ok(res)); }
public async Task Put([FromBody] ProductCreationDTO value) { var dto = new ProductDTO(); dto.Active = true; dto.Title = value.Title; dto.Description = value.Description; dto.MinimalAmount = int.Parse(value.MinimalAmount ?? "0"); dto.StartsAt = double.Parse(value.StartsAt.Replace("R", "").Replace("$", "").Replace(",", ".").Replace(" ", "")); dto.Tags = value.Tags.Split(' ', StringSplitOptions.RemoveEmptyEntries); dto.UnitName = value.UnitName ?? "Unidade"; await _productServices.CreateProduct(dto); }
public async Task <IActionResult> Create(Data.Entities.Products.Product product, IFormFile productImage) { if (ModelState.IsValid) { var res = await _productServices.CreateProduct(product, productImage); if (!res.DidError) { return(RedirectToAction("Index")); } ModelState.AddModelError("ProductTitle", res.Message); } return(View(product)); }
public void CreateNewProductCallsProductServicesNewProduct() { var controller = new ProductsController(); IProductServices services = SetUpProductServices(); try { controller.CreateNewProduct(); Isolate.Verify.WasCalledWithAnyArguments(() => services.CreateProduct()); } catch (VerifyException) { Assert.Fail("ProductsController did not call ProductsServices.CreateNewProduct"); } }
public ActionResult Create(ProductViewModel productViewModel) { if (ModelState.IsValid) { User user = _userServices.GetUser(User.Identity.Name); Product product = Mapper.Map <ProductViewModel, Product>(productViewModel); _productServices.CreateProduct(product, user.Id); return(RedirectToAction("Index")); } else { return(View(productViewModel)); } }
public void AddNewProductTest() { var newProduct = new ProductEntity(); newProduct.ProductName = "Android Phone"; var maxProductIdBeforeAdd = _products.Max(a => a.ProductId); newProduct.ProductId = maxProductIdBeforeAdd + 1; _productService.CreateProduct(newProduct); var addedProduct = new Product { ProductId = newProduct.ProductId, ProductName = newProduct.ProductName }; AssertObjects.PropertyValuesAreEquals(addedProduct, _products.Last()); Assert.That(maxProductIdBeforeAdd + 1, Is.EqualTo(_products.Last().ProductId)); }
public void Given_a_product_repository_When_added_new_product_Then_retrieve_the_newly_added_product_from_repository() { var newProduct = new ProductModel() { ProductCode = "B002", Price = 120 }; _productService.CreateProduct(newProduct); var addedproduct = new Product() { ProductCode = newProduct.ProductCode, Price = newProduct.Price }; Assert.AreEqual(4, _products.Count); Assert.IsNotNull(_products.Find(a => a.ProductCode.Contains("B002"))); }
public async Task <IActionResult> CreateProduct(ProductForCreation productDto) { try { var product = await _productServices.CreateProduct(productDto); if (product == null) { return(new BadRequestObjectResult(new { Message = "Tạo sản phẩm thất bại" })); } return(Ok(product)); } catch (Exception ex) { return(new BadRequestObjectResult(new { Message = ex.Message.ToString() })); } }
public ActionResult Create(ProductViewModel productViewModel) { if (ModelState.IsValid) { Product product = Mapper.Map <ProductViewModel, Product>(productViewModel); product.ProductMacronutrients = _productServices.UpdateProductMacronutrients(productViewModel.MacroNutrients); product.ProductMicronutrients = _productServices.UpdateProductMicronutrients(productViewModel.MicroNutrients); _productServices.CreateProduct(product, UserId); return(RedirectToAction("Index")); } else { return(View(productViewModel)); } }
public void AddNewProductTest() { var newProduct = new ProductEntity() { ProductName = "Android Phone" }; var maxProductIDBeforeAdd = _products.Max(a => a.ProductId); newProduct.ProductId = maxProductIDBeforeAdd + 1; _productService.CreateProduct(newProduct); var addedproduct = new Product() { ProductName = newProduct.ProductName, ProductId = newProduct.ProductId }; Assert.True((maxProductIDBeforeAdd + 1).Equals(_products.Last().ProductId)); }
public void AddNewProductTest() { var newProduct = new ProductEntity() { Name = "Web Api Service", CreateDate = DateTime.Now, isActive = false }; var maxProductIDBeforeAdd = expectedProducts.Max(a => a.Id); newProduct.Id = maxProductIDBeforeAdd + 1; productService.CreateProduct(newProduct); var addedproduct = new Product { Id = newProduct.Id, Name = newProduct.Name, CreateDate = newProduct.CreateDate, isActive = newProduct.isActive }; AssertObjects.PropertyValuesAreEquals(addedproduct, expectedProducts.Last()); Assert.That(maxProductIDBeforeAdd + 1, Is.EqualTo(expectedProducts.Last().Id)); }
// POST api/product public HttpResponseMessage Post([FromBody] ProductModel productModel) { ValidationProcessor validationProc = new ValidationProcessor(); ValidationModel validModel = validationProc.ValidateProduct(productModel); if (validModel.Status == ValidationStatus.OK) { bool status = _productServices.CreateProduct(productModel); if (status) { return(Request.CreateResponse(HttpStatusCode.OK, true)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error occurred in creating a product")); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, validModel.ValidationMessage)); } }
// POST api/product public int Post([FromBody] ProductEntity productEntity) { return(_productServices.CreateProduct(productEntity)); }
// POST api/product public int Post([FromBody] Product Product) { return(_productServices.CreateProduct(Product)); }
public async Task <BaseResponse <bool> > createProduct([FromBody] Product product) { bool result = await _productServices.CreateProduct(product); return(new BaseResponse <bool>(result)); }
// POST api/product public int Post([FromBody] ProductDto productDto) { return(_productServices.CreateProduct(productDto)); }