/** * This method checks if the animals that are selected by the user are following the rules * It first checks if the animals are from a specific type or have a specific name * After this it checks several combinations to see if it violates any rules. * If it does not violate any rules this method returns null */ public string CheckIfSelectedBeestjesAreValid(BoekingVM boeking) { bool isFarmAnimal = false; bool isLionorPolar = false; bool isPinguin = false; bool isDesert = false; bool isSnow = false; foreach (Beestje b in boeking.SelectedBeestjes) { if (b.Type == "Boerderij") { isFarmAnimal = true; } if (b.Name == "Leeuw" || b.Name == "Ijsbeer") { isLionorPolar = true; } if (b.Name == "Pinguïn") { isPinguin = true; } if (b.Type == "Woestijn") { isDesert = true; } if (b.Type == "Sneeuw") { isSnow = true; } } if (isFarmAnimal && isLionorPolar) { return("Je mag geen leeuw of Ijsbeer bij boerderijdieren."); } DayOfWeek day = boeking.Date.DayOfWeek; if (isPinguin && ((day == DayOfWeek.Saturday) || (day == DayOfWeek.Sunday))) { return("Je mag helaas geen pinguïns reserveren in het weekend."); } if (isDesert && (boeking.Date.Month > 9 || boeking.Date.Month < 3)) { return("Je mag helaas geen woestijn dieren reserveren in de maanden oktober t/m februari."); } if (isSnow && (boeking.Date.Month > 5 && boeking.Date.Month < 9)) { return("Je mag helaas geen sneeuw dieren reserveren in de maanden juni t/m augustus."); } return(null); }
private decimal CalculateTotalPrice(BoekingVM boekingVM) { decimal totalprice = 0; List <string> kortinglijst = new List <string>(); foreach (Beestje b in boekingVM.SelectedBeestjes) { if (b.Name == "Eend") { Random r = new Random(); int korting = r.Next(0, 7); if (korting == 1) { totalprice = b.Price / 2; kortinglijst.Add("Eend 50%"); } } DayOfWeek day = boekingVM.Date.DayOfWeek; if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday) { totalprice = b.Price - ((b.Price / 100) * 15); } } foreach (Accessoires a in boekingVM.SelectedAccessoires) { totalprice += a.Price; } return(totalprice); }
/** * Fourth step of the process, checks if tempdata is not empty to handle validation * User can see and confirm his booking * Also calculates the total price with discounts by using the CalculateDiscount class */ public ActionResult Stap4([Bind(Include = "Date,FirstName, Prefix, LastName, Adres, Email, Number, BeestjesIds, AccessoiresIds")] BoekingVM boekingVM) { if (boekingVM.Date < DateTime.Now) { TempData["nodateselected"] = "Selecteer een valide datum."; return(RedirectToAction("Index", "Home")); } calculateDiscount = new CalculateDiscount(); foreach (int i in boekingVM.BeestjesIds) { boekingVM.SelectedBeestjes.Add(boekingRepository.GetBeestjeById(i)); } foreach (int i in boekingVM.AccessoiresIds) { boekingVM.SelectedAccessoires.Add(boekingRepository.GetAccessoireById(i)); } boekingVM.FullName = boekingVM.FirstName + " " + boekingVM.Prefix + " " + boekingVM.LastName; boekingVM.TotalPrice = calculateDiscount.CalculateTotalPrice(boekingVM); boekingVM.DiscountList = calculateDiscount.DiscountList; return(View(boekingVM)); }
//pagina die bevestiging van boeking toont public IActionResult Bevestiging(BoekingVM b) { if (b == null) { return NotFound(); } return View(b); }
/** * Check if the animal has a booking on the same date as the current booking. */ public bool BeestjeHasNoBoeking(Beestje b, BoekingVM currentBoeking, IBoekingRepository boekingsRepository) { foreach (Boeking boeking in boekingsRepository.GetAllBoeking()) { if (boeking.Beestjes != null && boeking.Beestjes.FirstOrDefault(beest => beest.Id == b.Id) != null && boeking.Date == currentBoeking.Date) { return(false); } } return(true); }
// Shows the details of a booking public ActionResult Details(int?id) { if (id == null) { return(RedirectToAction("Index", "Error")); } Boeking boeking = boekingRepository.GetBoekingById(id); if (boeking == null) { return(HttpNotFound()); } BoekingVM boekingVM = new BoekingVM(); boekingVM.BoekingModel = boeking; boekingVM.FullName = boekingVM.FirstName + " " + boekingVM.Prefix + " " + boekingVM.LastName; return(View(boekingVM)); }
/** * Second step of the process, checks if tempdata is not empty to handle validation * Sets a list of all the accessoires that are from one of the selected animals */ public ActionResult Stap2(BoekingVM boekingVM) { if (boekingVM.Date < DateTime.Now) { TempData["nodateselected"] = "Selecteer een valide datum."; return(RedirectToAction("Index", "Home")); } foreach (BeestjeVM b in boekingVM.Beestjes) { if (b.IsSelected) { boekingVM.SelectedBeestjes.Add(boekingRepository.GetBeestjeById(b.Id)); boekingVM.BeestjesIds.Add(b.Id); } } if (boekingVM.SelectedBeestjes.Count == 0) { TempData["nobeestselected"] = "Selecteer minimaal een beest."; return(RedirectToAction("Stap1", "Home", new { boekingVM.Date })); } string check = beestValidation.CheckIfSelectedBeestjesAreValid(boekingVM); if (check != null) { TempData["wrongcollection"] = check; return(RedirectToAction("Stap1", "Home", new { boekingVM.Date })); } foreach (Beestje beest in boekingVM.SelectedBeestjes) { foreach (Accessoires a in boekingRepository.GetAccessoires()) { if (a.Beest == beest) { boekingVM.Accessoires.Add(a); } } } return(View(boekingVM)); }
public ActionResult Contactgegevens(DateTime startdate, int amountguest, int kamerid) { List <DateTime> boekingdatums = new List <DateTime>(); foreach (Boeking b in db.GetAllBoekingen()) { if (b.BoekingStart.Equals(startdate) && b.KamerID.Equals(kamerid)) { return(RedirectToAction("ReserveerDatum", "Reserveer", new { id = kamerid, valid = false })); } } Boeking huidigeBoeking = new Boeking(); huidigeBoeking.BoekingStart = startdate; huidigeBoeking.Kamer = db.GetKamerForId(kamerid); BoekingVM boekingVM = new BoekingVM(huidigeBoeking, amountguest); return(View(boekingVM)); }
public void AddBoeking(BoekingVM boekingVM) { Boeking boeking; boeking = new Boeking(); db.Boekings.Add(boeking); boeking.FirstName = boekingVM.FirstName; boeking.LastName = boekingVM.LastName; boeking.Prefix = boekingVM.Prefix; boeking.Email = boekingVM.Email; boeking.Date = boekingVM.Date; boeking.Adres = boekingVM.Adres; boeking.Number = boekingVM.Number; boeking.Price = boekingVM.TotalPrice; boeking.Accessoires = boekingVM.AccessoiresIds.Select(ai => db.Accessoires.Find(ai)).ToList(); boeking.Beestjes = boekingVM.BeestjesIds.Select(bi => db.Beestjes.Find(bi)).ToList();; db.SaveChanges(); }
/** * First step of the process, checks if tempdata is not empty to handle validation * Sets a list of all the animals in the database, if they are already in a booking on that date * they will become unable to select. */ public ActionResult Stap1(BoekingVM boekingVM) { if (boekingVM.Date < DateTime.Now) { TempData["nodateselected"] = "Selecteer een valide datum."; return(RedirectToAction("Index", "Home")); } if (TempData["nobeestselected"] != null) { ViewBag.Error = TempData["nobeestselected"].ToString(); } if (TempData["wrongcollection"] != null) { ViewBag.Error = TempData["wrongcollection"].ToString(); } var beestjes = boekingRepository.GetBeestjes(); List <BeestjeVM> beestlijst = new List <BeestjeVM>(); foreach (var b in beestjes) { if (beestValidation.BeestjeHasNoBoeking(b, boekingVM, boekingRepository)) { boekingVM.Beestjes.Add(new BeestjeVM { Beest = b, HasBoeking = false }); } else { boekingVM.Beestjes.Add(new BeestjeVM { Beest = b, HasBoeking = true }); } } return(View(boekingVM)); }
public void AllValuesMatch() { DateTime boekingStart = new DateTime(2000, 10, 9); List <Gast> gasten = new List <Gast> { new Gast() { Naam = "Pietje" } }; int id = 10; Kamer kamer = new Kamer() { Id = 1 }; int kamerId = 1; int kortinspercentage = 20; Boeking boeking = new Boeking() { BoekingStart = boekingStart, Gasten = gasten, Id = id, Kamer = kamer, KamerID = kamerId, Kortingspercentage = kortinspercentage }; int aantalMensen = 3; BoekingVM boekingVM = new BoekingVM(boeking, aantalMensen); Assert.AreEqual(boeking.BoekingStart, boekingStart); Assert.AreEqual(boeking.Gasten, gasten); Assert.AreEqual(boeking.Id, id); Assert.AreEqual(boeking.Kamer, kamer); Assert.AreEqual(boeking.KamerID, kamerId); Assert.AreEqual(boeking.Kortingspercentage, kortinspercentage); }
/** * Third step of the process, checks if tempdata is not empty to handle validation * User can input his data here for the booking */ public ActionResult Stap3(BoekingVM boekingVM) { if (boekingVM.Date < DateTime.Now) { TempData["nodateselected"] = "Selecteer een valide datum."; return(RedirectToAction("Index", "Home")); } foreach (int i in boekingVM.BeestjesIds) { boekingVM.SelectedBeestjes.Add(boekingRepository.GetBeestjeById(i)); } foreach (Accessoires a in boekingVM.Accessoires) { if (a.IsSelected) { boekingVM.SelectedAccessoires.Add(boekingRepository.GetAccessoireById(a.Id)); boekingVM.AccessoiresIds.Add(a.Id); } } return(View(boekingVM)); }
/** * This method checks if the selected animals are from specific types or have specific names * If this is true the user gets a discount on the total price of the booking. * After it checked all the animals the total price gets calculated by taking the discount price from the total price */ public decimal CalculateTotalPrice(BoekingVM boekingVM) { DiscountList.Clear(); decimal totalPrice = 0; List <string> kortinglijst = new List <string>(); int discountAmount = 0; bool hasDogOrCat = false; foreach (Beestje b in boekingVM.SelectedBeestjes) { decimal beestprice = b.Price; if (b.Name == "Eend") { Random r = new Random(); int oneInSix = r.Next(0, 7); HasDuck = true; if (oneInSix == 1) { //beestprice =- b.Price / 2; DiscountList.Add("Eend 50%"); discountAmount += 50; } } DayOfWeek day = boekingVM.Date.DayOfWeek; if (day == DayOfWeek.Monday || day == DayOfWeek.Tuesday) { //totalprice = b.Price - ((b.Price / 100) * 15); DiscountList.Add("Maandag en Dinsdag korting 15%"); discountAmount += 15; } for (char c = 'a'; c <= 'z'; c++) { if (b.Name.ToLower().Contains(c)) { DiscountList.Add("Bevat letter " + c + " 2%"); discountAmount += 2; } else { break; } } if (b.Name.Equals("Hond") || b.Name.Equals("Kat")) { if (hasDogOrCat) { discountAmount += 10; DiscountList.Add("2x hond of kat 25%"); } else { hasDogOrCat = true; } } totalPrice += b.Price; } if (boekingVM.SelectedBeestjes.Count > 2) { int counterWoestijnType = boekingVM.SelectedBeestjes.FindAll(b => b.Type == "Woestijn").Count(); int counterSneeuwType = boekingVM.SelectedBeestjes.FindAll(b => b.Type == "Sneeuw").Count(); int counterBoerderijType = boekingVM.SelectedBeestjes.FindAll(b => b.Type == "Boerderij").Count(); int counterJungleType = boekingVM.SelectedBeestjes.FindAll(b => b.Type == "Jungle").Count(); if (counterBoerderijType > 2 || counterJungleType > 2 || counterSneeuwType > 2 || counterWoestijnType > 2) { DiscountList.Add("3 Types: 10%"); discountAmount += 10; } } foreach (Accessoires a in boekingVM.SelectedAccessoires) { totalPrice += a.Price; } if (discountAmount > 60) { discountAmount = 60; } decimal discountPrice = (totalPrice / 100) * discountAmount; return(totalPrice - discountPrice); }
public ActionResult Finish([Bind(Include = "Date,FirstName, Prefix, LastName, Adres, Email, Number, TotalPrice, BeestjesIds, AccessoiresIds")] BoekingVM boekingVM) { boekingRepository.AddBoeking(boekingVM); return(View()); }