public void ValidateOnlyOneHouse(RentingLot rentingLot) { var building = this.GetBuildingById(rentingLot.BuildingId); //est-ce une maison? if (rentingLot.RentingLotType == RentingLotType.FamilyHome || rentingLot.RentingLotType == RentingLotType.Townhouse) { //Est-ce que j'ai un autre LOT? var alreadyHaveElements = building.Rentinglots.Any(x => x.Id != rentingLot.Id); if (alreadyHaveElements) { throw new BuildingRepoException("Vous ne pouvez avoir deux maisons sur le même immeuble"); } } }
public void ValidateTermChange() { //Arrange var oldRentingLot = new RentingLot() { Id = 2, BuildingId = 1, LeaseLength = 3, LotNumber = null, NumberOfRooms = 5, Price = 100, RentingLotType = RentingLotType.Commercial, Terms = RentTerm.Yearly }; var newRentingLot = new RentingLot() { Id = 2, BuildingId = 1, LeaseLength = 3, LotNumber = null, NumberOfRooms = 5, Price = 100, RentingLotType = RentingLotType.Commercial, Terms = RentTerm.Monthly }; //Act this._repo.ValidateTermChange(oldRentingLot, newRentingLot); //Assert Assert.Equal(oldRentingLot.LeaseLength != newRentingLot.LeaseLength, true); }
public IActionResult Edit(int id, [Bind("Id,LotNumber,Price,Terms,LeaseLength,NumberOfRooms,RentingLotType,BuildingId")] RentingLot rentingLot) { if (ModelState.IsValid) { try{ var r = _repo.Edit(rentingLot); return(RedirectToAction(nameof(Details), new { Id = r.Id })); } catch (NotFoundException) { //log me! return(NotFound()); } catch (BuildingRepoException e) { this.ModelState.AddModelError(e.Property, e.Message); } } ViewData["BuildingId"] = new SelectList(_repo.GetAllBuildings(), "Id", "Name", rentingLot.BuildingId); return(View(rentingLot)); }
public void ValidateLeaseLength(RentingLot rentingLot) { if (rentingLot.LeaseLength <= 0) { throw new PropertyException(nameof(rentingLot.LeaseLength), "Un immeuble doit avoir un bail d'au moins 1 unité."); } if (rentingLot.RentingLotType == RentingLotType.Commercial) { if (rentingLot.Terms == RentTerm.Monthly && rentingLot.LeaseLength >= 18) { return; //ok } if (rentingLot.Terms == RentTerm.Yearly && rentingLot.LeaseLength >= 3) { return; //ok } throw new PropertyException(nameof(rentingLot.LeaseLength), "Un immeuble commercial doit avoir un bail d'au moins 3 ans ou 18 mois."); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { //seed var buildings = new List <Building>(); for (int i = 1; i < 200; i++) { var name = "Le Super " + SampleData.GenerateName(i); buildings.Add(new Building(i, name, SampleData.GenerateAddress(i), SampleData.GeneratePhoneNumber(i), SampleData.GenerateName(i + 1), SampleData.GenerateLastName(i + 1), $"{name} est un immeuble extra, où il fait bon vivre!")); } modelBuilder.Entity <Building>().HasData(buildings); //seed var rentingLots = new List <RentingLot>(); for (int i = 1; i < 200; i++) { var rand = new Random(i); var numberOfLots = rand.Next(0, 10); var RentingLotToAdd = new List <RentingLot>(); for (int j = 1; j <= numberOfLots; j++) { var uniqueNumber = i * 1000 + j * 100; var rentingLot = new RentingLot(); int?lotNumber = j; var price = SampleData.GenerateDecimal(uniqueNumber, 100, 1000); var rentTerm = (RentTerm)SampleData.GenerateInteger(uniqueNumber + 1, 0, 3); var LeaseLength = SampleData.GenerateInteger(uniqueNumber + 2, 1, 50); var numberOfRooms = SampleData.GenerateInteger(uniqueNumber + 3, 1, 10); var RentingLotType = (RentingLotType)SampleData.GenerateInteger(uniqueNumber + 4, 0, 5); //business rules if (RentingLotType == RentingLotType.Townhouse || RentingLotType == RentingLotType.FamilyHome) { if (RentingLotToAdd.Any()) { RentingLotType = RentingLotType.Appartment; } else { lotNumber = null; RentingLotToAdd.Clear(); numberOfLots = 1; } } if (RentingLotType == RentingLotType.Commercial) { if (rentTerm != RentTerm.Monthly && rentTerm != RentTerm.Yearly) { rentTerm = RentTerm.Monthly; } if (rentTerm == RentTerm.Monthly) { LeaseLength = Math.Max(18, LeaseLength); } if (rentTerm == RentTerm.Yearly) { LeaseLength = Math.Max(3, LeaseLength); } } var newRentingLot = new RentingLot() { Id = rentingLots.Count + RentingLotToAdd.Count + 1, BuildingId = i, LeaseLength = LeaseLength, LotNumber = lotNumber?.ToString(), NumberOfRooms = numberOfRooms, RentingLotType = RentingLotType, Terms = rentTerm, Price = price }; RentingLotToAdd.Add(newRentingLot); } rentingLots.AddRange(RentingLotToAdd); } modelBuilder.Entity <RentingLot>().HasData(rentingLots); }