Exemplo n.º 1
0
        public ActionResult CreateRollPrintableArticle(RollPrintableArticleViewModel 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("IndexRollPrintableArticle") });
                }
                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 = "CreateRollPrintableArticle";
            return PartialView("_EditAndCreateRollPrintableArticle", c);

        }
Exemplo n.º 2
0
        public ActionResult EditRollPrintableArticle(RollPrintableArticleViewModel 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("IndexRollPrintableArticle") });
                }
                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 = "EditRollPrintableArticle";
            return PartialView("_EditAndCreateRollPrintableArticle", c);
        }
Exemplo n.º 3
0
 public ActionResult CreateRollPrintableArticle(string tags)
 {
     //used to understand default actionmethod  when there are more then one submit button
     ViewBag.ActionMethod = "CreateRollPrintableArticle";
     var vm = new RollPrintableArticleViewModel();
     vm.Article.Tags = tags;
     return View(vm);
 }
Exemplo n.º 4
0
        public ActionResult EditRollPrintableArticle(string id)
        {
            RollPrintableArticleViewModel viewModel = new RollPrintableArticleViewModel();
            viewModel.Article = (RollPrintableArticle)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 = "EditRollPrintableArticle";
            return View("EditRollPrintableArticle", viewModel);
        }