public async Task <IActionResult> Create([Bind("Name,IdCategory,Price")] Product product) { try { if (ModelState.IsValid) { await productComponent.Create(product); return(RedirectToAction("Index")); } } catch (Exception ex) { //Log the error ModelState.AddModelError("", ex.Message); } var categories = await categoryComponent.GetAllCategories(); if (categories == null) { RedirectToAction("Index"); } ViewBag.CategoryList = new SelectList(categories, "Id", "Name"); return(View(product)); }
public async Task <JsonResult> CreateProduct([FromBody] Product newProduct) { var newProductId = await productComponent.Create(newProduct); return(Json(newProductId)); }