public ActionResult AddPromo(Promotion NewPromo) { PromotionRepoADO repoP = new PromotionRepoADO(); PromotionsVM model = new PromotionsVM(); if (string.IsNullOrWhiteSpace(NewPromo.PromotionName) || string.IsNullOrWhiteSpace(NewPromo.Description)) { ModelState.AddModelError("", "Promotion name and description must contain text"); } if (ModelState.IsValid) { repoP.AddPromotion(NewPromo); model.Allpromotions = repoP.GetALLpromotions(); model.ValidPromotions = repoP.GetValidPromotions(); return(RedirectToAction("Promotions")); } else { model.Allpromotions = repoP.GetALLpromotions(); model.ValidPromotions = repoP.GetValidPromotions(); model.NewPromo = NewPromo; return(View("Special", model)); } }
public ActionResult Promotions() { PromotionsVM model = new PromotionsVM(); PromotionRepoADO repoP = new PromotionRepoADO(); model.Allpromotions = repoP.GetALLpromotions(); model.ValidPromotions = repoP.GetValidPromotions(); return(View("Special", model)); }
public void CanGetAllPromotions() { PromotionRepoADO repo = new PromotionRepoADO(); Promotion promo = new Promotion { PromotionName = "Test Promo", Description = "This is a test Promotion", IsForNew = true, IsForUsed = true, FlatDiscount = 0, PercentDiscount = 10 }; List <Promotion> ps1 = repo.GetValidPromotions(); Assert.AreEqual(1, ps1.Count); repo.AddPromotion(promo); List <Promotion> ps2 = repo.GetALLpromotions(); Assert.AreEqual(5, ps2.Count); List <Promotion> ps3 = repo.GetValidPromotions(); Assert.AreEqual(2, ps3.Count); }