// GET: Verlanglijst public ActionResult Index(ApplicationUser user, VerlanglijstViewModel m = null) { if (user.Verlanglijst.AantalItems == 0) { return(View("LegeVerlanglijst")); } //Dictionary<Product,int> map = new Dictionary<Product, int>(); VerlanglijstViewModel model = (VerlanglijstViewModel)viewModelFactory.CreateViewModel("verlanglijst"); if (m != null) { model = m; } //user.Verlanglijst.Producten.ForEach(p => model.ProductenMap.Add(p, 0)); model.Producten = user.Verlanglijst.Producten; Dictionary <int, bool[]> d = new Dictionary <int, bool[]>(); foreach (var item in model.Producten) { d.Add(item.ProductId, new bool[5]); } ViewBag.ProductenLector = d; return(View(model)); }
public void DetailsZalViewMetVerlanglijstDetailViewModelReturnen() { Dictionary <Product, int> p = new Dictionary <Product, int>(); ICollection <Product> list = new List <Product>(); list.Add(dummyContext.Schatkist); p.Add(dummyContext.Schatkist, 1); dummyContext.CurrentGebruiker.Verlanglijst.Producten.Add(dummyContext.Schatkist); int[] aantal = { 1 }; DateTime van = DateTime.Now.StartOfWeek(DayOfWeek.Monday); DateTime tot = van.AddDays(7); Email[] email = { dummyContext.Email }; dummyContext.CurrentGebruiker.VoegReservatieToe(p, van, tot, email); dummyContext.CurrentGebruiker.VoegReservatieToe(p, van.AddDays(14), tot.AddDays(14), email); VerlanglijstViewModel model = new VerlanglijstViewModel() { StartDatum = van, Producten = list, Aantallen = aantal, EindDate = tot }; verlanglijstController.Reserveer(model, van, tot, dummyContext.CurrentGebruiker); ViewResult result = verlanglijstController.Details(2, dummyContext.CurrentGebruiker, van, tot) as ViewResult; Assert.IsNotNull(result); Assert.IsInstanceOfType(result.Model, typeof(VerlanglijstDetailViewModel)); }
public ActionResult PlusDatum(VerlanglijstViewModel m, DateTime van, DateTime tot) { var vanDatum = van; var eindDatum = tot; vanDatum = vanDatum.AddDays(7.0); eindDatum = eindDatum.AddDays(7.0); VerlanglijstViewModel model = new VerlanglijstViewModel() { StartDatum = vanDatum, EindDate = eindDatum }; return(RedirectToAction("Index", "Verlanglijst", model)); }
public void MinDatumZalRedirectenNaarIndex() { VerlanglijstViewModel model = new VerlanglijstViewModel(); DateTime van = DateTime.Now.AddDays(14).StartOfWeek(DayOfWeek.Monday); DateTime tot = van.AddDays(-7); model.StartDatum = van; model.EindDate = tot; RedirectToRouteResult result = verlanglijstController.MinDatum(model, van, tot) as RedirectToRouteResult; Assert.IsNotNull(result, "Should have redirected"); Assert.AreEqual("Index", result.RouteValues["action"]); Assert.AreEqual("Verlanglijst", result.RouteValues["controller"]); }
public void MinDatumZalModelNietAanpassenIndienErNietTerugKanGegaanWorden() { VerlanglijstViewModel model = new VerlanglijstViewModel(); DateTime eersteStartDatum = DateTime.Now.StartOfWeek(DayOfWeek.Monday); model.StartDatum = eersteStartDatum; model.EindDate = eersteStartDatum.AddDays(7); DateTime van = eersteStartDatum; DateTime tot = van.AddDays(-7); RedirectToRouteResult result = verlanglijstController.MinDatum(model, van, tot) as RedirectToRouteResult; Assert.AreEqual(eersteStartDatum, model.StartDatum); Assert.AreEqual(eersteStartDatum.AddDays(7), model.EindDate); }
public ActionResult MinDatum(VerlanglijstViewModel m, DateTime van, DateTime tot) { DateTime hulp = van.AddDays(-7); DateTime dateNu = DateTime.Now.StartOfWeek(DayOfWeek.Monday); VerlanglijstViewModel model = new VerlanglijstViewModel(); if (hulp > dateNu && van >= hulp) { van = van.AddDays(-7); tot = tot.AddDays(-7); model = new VerlanglijstViewModel() { StartDatum = van, EindDate = tot }; } return(RedirectToAction("Index", "Verlanglijst", model)); }
public ActionResult Reserveer(VerlanglijstViewModel viewModel, DateTime van, DateTime tot, ApplicationUser user, bool[] dagenLector = null) { try { Product[] producten = user.Verlanglijst.Producten.ToArray(); if (ModelState.IsValid) { Dictionary <Product, int> productAantalMap = new Dictionary <Product, int>(); for (int i = 0; i < viewModel.Aantallen.Length; i++) { productAantalMap.Add(producten[i], viewModel.Aantallen[i]); } if (user is Student) { Email[] emails = new Email[1]; emails[0] = emailRepository.FindByReservatieStatus(ReservatieStatus.Gereserveerd); user.VoegReservatieToe(productAantalMap, van, tot, emails); } if (user is Personeel) { Email[] emails = new Email[3]; Email email = emailRepository.FindByReservatieStatus(ReservatieStatus.Geblokkeerd); Email email2 = emailRepository.FindByReservatieStatus(ReservatieStatus.Geannuleerd); Email email3 = emailRepository.FindByReservatieStatus(ReservatieStatus.Gewijzigd); emails[0] = email; emails[1] = email2; emails[2] = email3; user.VoegReservatieToe(productAantalMap, van, tot, emails, dagenLector); } gebruikerRepository.SaveChanges(); TempData["Info"] = "Uw reservatie is succesvol toegevoegd."; return(RedirectToAction("Index", "Product")); } }catch (ArgumentNullException ex) { ModelState.AddModelError("key", ex.Message); }catch (ArgumentOutOfRangeException ex) { ModelState.AddModelError("key", ex.Message); } viewModel.Producten = user.Verlanglijst.Producten; return(View("Index", viewModel)); }
public void ReserveerZalIndexViewEnVerlangLijstViewModelReturnenBijEenOngeldigAantal() { ICollection <Product> p = new List <Product>(); p.Add(dummyContext.Schatkist); dummyContext.CurrentGebruiker.Verlanglijst.Producten.Add(dummyContext.Schatkist); int[] aantal = { -1 }; DateTime van = DateTime.Now.StartOfWeek(DayOfWeek.Monday); DateTime tot = van.AddDays(7); dummyContext.CurrentGebruiker.Reservaties.Add(new Reservatie()); VerlanglijstViewModel model = new VerlanglijstViewModel() { StartDatum = van, Producten = p, Aantallen = aantal, EindDate = tot }; ViewResult result = verlanglijstController.Reserveer(model, van, tot, dummyContext.CurrentGebruiker) as ViewResult; Assert.IsInstanceOfType(result.Model, typeof(VerlanglijstViewModel)); Assert.AreEqual("Index", result.ViewName); }
public void ReserveerZalRedirectenNaarIndexMethodeenBijEenGeldigAantal() { ICollection <Product> p = new List <Product>(); p.Add(dummyContext.Schatkist); dummyContext.CurrentGebruiker.Verlanglijst.Producten.Add(dummyContext.Schatkist); int[] aantal = { 1 }; DateTime van = DateTime.Now.StartOfWeek(DayOfWeek.Monday); DateTime tot = van.AddDays(7); dummyContext.CurrentGebruiker.Reservaties.Add(new Reservatie()); VerlanglijstViewModel model = new VerlanglijstViewModel() { StartDatum = van, Producten = p, Aantallen = aantal, EindDate = tot }; RedirectToRouteResult result = verlanglijstController.Reserveer(model, van, tot, dummyContext.CurrentGebruiker) as RedirectToRouteResult; Assert.IsNotNull(result, "Should have redirected"); Assert.AreEqual("Index", result.RouteValues["action"]); Assert.AreEqual("Product", result.RouteValues["controller"]); }