public async Task <ActionResult <ProductGetDto> > Post(ProductPostDto productDto) { var product = _mapper.Map <Product>(productDto); var createdProduct = await _productsService.CreateProductAsync(product); return(CreatedAtAction(nameof(Get), new { id = createdProduct.ProductId }, _mapper.Map <ProductGetDto>(createdProduct))); }
public async Task <IActionResult> Post([FromBody] ProductEntity product) { if (product == null || string.IsNullOrWhiteSpace(product.Name) || string.IsNullOrWhiteSpace(product.Description) || product.Price == 0) { return(BadRequest("Please specify Name, Description and Price")); } return(Ok(await _productsService.CreateProductAsync(product))); }
public async Task <ActionResult> Create([Bind(Include = "Id,Name")] Product product, HttpPostedFileBase image) { if (ModelState.IsValid) { await _productsService.CreateProductAsync(product, image); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <IActionResult> CreateProduct(ProductWriteItemViewModel createModel) { if (ModelState.IsValid) { Products product = _mapper.Map <Products>(createModel); await _productsService.CreateProductAsync(product); return(RedirectToAction("Index")); } await FillSelectLists(createModel); return(View("CreateProduct", createModel)); }
public async Task <IActionResult> Post([FromBody] ProductWriteItemDto createModel) { if (ModelState.IsValid == false) { return(BadRequest(ModelState)); } Products product = _mapper.Map <Products>(createModel); var cereatedProduct = await _productsService.CreateProductAsync(product); var result = _mapper.Map <ProductReadItemDto>(cereatedProduct); return(CreatedAtAction("Get", new { id = cereatedProduct.ProductId }, result)); }
public async Task <IActionResult> Create(ProductCreateModel productViewModel) { var product = _mapper.Map <Product>(productViewModel); if (ModelState.IsValid) { await _productsService.CreateProductAsync(product); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList( await _categoriesService.GetCategoriesAsync(), "CategoryId", "CategoryName", product.CategoryId); ViewData["SupplierId"] = new SelectList( await _suppliersService.GetSuppliersAsync(), "SupplierId", "CompanyName", product.SupplierId); return(View(_mapper.Map <ProductViewModel>(product))); }
public async Task <IActionResult> Create([Bind("ProductId,ProductName,SupplierId,CategoryId,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] ProductCreate productToCreate) { if (ModelState.IsValid) { var createdProduct = await _productsService.CreateProductAsync <Product>(productToCreate); return(RedirectToAction(nameof(Index))); } var categories = await _categoriesService.GetCategoriesAsync <Category>(); var suppliers = await _suppliersService.GetSuppliersAsync <Supplier>(); ViewData["CategoryId"] = new SelectList(categories, "CategoryId", "CategoryName"); ViewData["SupplierId"] = new SelectList(suppliers, "SupplierId", "CompanyName"); return(View(productToCreate)); }
public async Task <WebApiResult> CreateProduct([FromBody] ProductCreate productCreate) { try { var createdProduct = await _productsService.CreateProductAsync <Product>(productCreate); var result = new WebApiResult { Data = createdProduct, StatusCode = HttpStatusCode.OK, Message = "Success" }; return(result); } catch (Exception ex) { _logger.LogError(ex, $"Error occured while creating product with id {productCreate.ProductId}", null); var exceptionMessageBuilder = new StringBuilder($"Error: {ex.Message};"); var innerException = ex?.InnerException; while (innerException != null) { exceptionMessageBuilder.Append($"{ex.InnerException};"); innerException = innerException.InnerException; } var result = new WebApiResult { Data = null, StatusCode = HttpStatusCode.InternalServerError, Message = exceptionMessageBuilder.ToString() }; return(result); } }
public async Task <IHttpActionResult> Post(CreateProductCommand cmd) { var result = await productsService.CreateProductAsync(cmd); return(CreatedAtRoute("GetProductById", new { id = result.Id }, result)); }
public async Task <IActionResult> Create([FromBody] Product product) { var response = await _productsService.CreateProductAsync(product); return(Ok(response)); }
public async Task <ActionResult> Create(ProductsRequestModel model) { return(await _products .CreateProductAsync(model) .ToActionResult()); }