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 void CanCreatePromotion() { PromotionRepoADO repo = new PromotionRepoADO(); Promotion promo = new Promotion { PromotionName = "Test Promo", Description = "This is a test Promotion", StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(1), IsForNew = true, IsForUsed = true, FlatDiscount = 0, PercentDiscount = 10 }; repo.AddPromotion(promo); Promotion p2 = repo.GetPromotionByDate(DateTime.Parse("2/03/2018").Date); Assert.AreEqual(p2.Description.ToLower(), "this is a test promotion"); }
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); }