public ActionResult EditMesh(MeshViewModel 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("IndexMesh") }); } 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 = "EditMesh"; return PartialView("_EditAndCreateMesh", c); }
public ActionResult EditMesh(string id) { MeshViewModel viewModel = new MeshViewModel(); viewModel.Article = (Mesh)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 = "EditMesh"; return View("EditMesh", viewModel); }
public ActionResult CreateMesh(MeshViewModel 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("IndexMesh") }); } 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 = "CreateMesh"; return PartialView("_EditAndCreateMesh", c); }