public async Task <int> AddIngredientAsync(IngredientCreationBindingModel model) { try { var ingredient = this.Mapper.Map <Ingredient>(model); this.DbContext.Ingredients.Add(ingredient); await this.DbContext.SaveChangesAsync(); } catch { //failure return(0); } //success return(1); }
public async Task <IActionResult> AddIngredient(IngredientCreationBindingModel model) { if (!ModelState.IsValid) { return(View()); } var result = await this.storageService.AddIngredientAsync(model); if (result == 0) { this.TempData[WebConstants.BadMessage] = string.Format(Messages.AddingFailureMessage, typeof(Ingredient).Name, model.Name); } else { this.TempData[WebConstants.GoodMessage] = string.Format(Messages.AddingSuccessMessage, typeof(Ingredient).Name, model.Name); } return(RedirectToAction("AddIngredient", "Storage", new { Area = WebConstants.AdminArea })); }