public ActionResult EditRigidPrintableArticle(string id) { RigidPrintableArticleViewModel viewModel = new RigidPrintableArticleViewModel(); viewModel.Article = (RigidPrintableArticle)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 = "EditRigidPrintableArticle"; return View("EditRigidPrintableArticle", viewModel); }
public ActionResult EditRigidPrintableArticle(RigidPrintableArticleViewModel c) { if (ModelState.IsValid) { try { PapiroMVC.Models.CustomerSupplier[] customerSuppliers = customerSupplierRepository.GetAll().ToArray(); var filteredItems = customerSuppliers.Where( item => !(String.IsNullOrEmpty(item.BusinessName)) && item.BusinessName.IndexOf(c.SupplierMaker, StringComparison.InvariantCultureIgnoreCase) >= 0); if (filteredItems.Count() == 0) throw new Exception(); c.Article.CodSupplierMaker = filteredItems.First().CodCustomerSupplier; // customerSuppliers = customerSupplierRepository.GetAll().ToArray(); var filteredItems2 = customerSuppliers.Where( item => !(String.IsNullOrEmpty(item.BusinessName)) && item.BusinessName.IndexOf(c.SupplyerBuy, StringComparison.InvariantCultureIgnoreCase) >= 0); if (filteredItems2.Count() == 0) throw new Exception(); //if #suppliers < 1 then no supplier has selected correctly and then thow error c.Article.CodSupplierBuy = filteredItems2.First().CodCustomerSupplier; articleRepository.Edit(c.Article); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("IndexRigidPrintableArticle") }); } 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 = "EditRigidPrintableArticle"; return PartialView("_EditAndCreateRigidPrintableArticle", c); }
public ActionResult CreateRigidPrintableArticle(RigidPrintableArticleViewModel 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("IndexRigidPrintableArticle") }); } 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 = "CreateRigidPrintableArticle"; return PartialView("_EditAndCreateRigidPrintableArticle", c); }