public ActionResult AddProductPost(Product product) { try { List <KeyValuePair <string, string> > errors = productValidator.CanAddProduct(product); if (errors.Count == 0) { int id = productHandler.Add(product); if (id > 0) { return(RedirectToAction("GetProductList")); } else { this.ModelState.AddModelError("", "Something got wrong when adding product. Product not added!"); return(AddProduct(product)); } } else { foreach (KeyValuePair <string, string> error in errors) { this.ModelState.AddModelError(error.Key, error.Value); } return(AddProduct(product)); } } catch (Exception ex) { this.ModelState.AddModelError("", ex.Message); if (ex.InnerException != null) { this.ModelState.AddModelError("", ex.InnerException.Message); } return(AddProduct(product)); } }
public async Task Add(Product product) { await Task.Run(() => { _productHandler.Add(product); }); }