public ActionResult EditFoil(FoilViewModel c) { if (ModelState.IsValid) { try { articleRepository.SincroSupplier(c.Article, customerSupplierRepository, c.SupplierMaker, c.SupplyerBuy); articleRepository.Edit(c.Article); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("IndexFoil") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { Console.WriteLine(error); } } //If we come here, something went wrong. Return it back. //multi submit ViewBag.ActionMethod = "EditFoil"; return PartialView("_EditAndCreateFoil", c); }
public ActionResult EditFoil(string id) { FoilViewModel viewModel = new FoilViewModel(); viewModel.Article = (Foil)articleRepository.GetSingle(id); //get producer and maker if (viewModel.Article.CodArticle == "") return HttpNotFound(); //is used to know where we are from and go ViewBag.ActionMethod = "EditFoil"; return View("EditFoil", viewModel); }
public ActionResult CreateFoil(FoilViewModel c) { if (ModelState.IsValid) { try { c.Article.CodArticle = articleRepository.GetNewCode(c.Article, customerSupplierRepository, c.SupplierMaker, c.SupplyerBuy); // c.Article.ArticleName = c.Article.ToString(); articleRepository.Add(c.Article); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("IndexFoil") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } //view name is needed for reach right view because to using more than one submit we have to use "Action" in action method name ViewBag.ActionMethod = "CreateFoil"; return PartialView("_EditAndCreateFoil", c); }