public ActionResult EditSheetPrintableArticle(SheetPrintableArticleViewModel 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("IndexSheetPrintableArticle") }); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Something went wrong. Message: " + ex.Message); } } //If we come here, something went wrong. Return it back. ViewBag.ActionMethod = "EditSheetPrintableArticle"; return PartialView("_EditAndCreateSheetPrintableArticle", c); }
public ActionResult CreateSheetPrintableArticle(SheetPrintableArticleViewModel c) { if (ModelState.IsValid) { try { c.Article.CodArticle = articleRepository.GetNewCode(c.Article, customerSupplierRepository, c.SupplierMaker, c.SupplyerBuy); articleRepository.Add(c.Article); //rigeneration name of article c.Article.ArticleName = c.Article.ToString(); articleRepository.Save(); return Json(new { redirectUrl = Url.Action("Index") }); } catch (NoSupplierException) { ModelState.AddModelError("PersError", "NoSupplierError"); } 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 = "CreateSheetPrintableArticle"; return PartialView("_EditAndCreateSheetPrintableArticle", c); }
public ActionResult EditSheetPrintableArticle(string id) { SheetPrintableArticleViewModel viewModel = new SheetPrintableArticleViewModel(); viewModel.Article = (SheetPrintableArticle)articleRepository.GetSingle(id); //get producer and maker if (viewModel.Article.CodArticle == "") return HttpNotFound(); ViewBag.ActionMethod = "EditSheetPrintableArticle"; return View("EditSheetPrintableArticle", viewModel); }