Beispiel #1
0
        protected virtual async Task ProvideTestData(ParkSharkDbContext context)
        {
            await context.Divisions.AddAsync(new Division("First", "First", "Mr Test"));

            await context.SaveChangesAsync();

            await context.Divisions.AddAsync(new Division("Second", "Second", "Mr Test2"));

            await context.SaveChangesAsync();

            await context.Set <BuildingType>().AddAsync(new BuildingType(nameof(BuildingTypes.Underground)));

            await context.SaveChangesAsync();

            await context.Set <BuildingType>().AddAsync(new BuildingType(nameof(BuildingTypes.Aboveground)));

            await context.SaveChangesAsync();

            await context.Set <MemberShipLevel>().AddAsync(new MemberShipLevel(MemberShipLevel.Level.Bronze, 0, 0, 240));

            await context.Set <MemberShipLevel>().AddAsync(new MemberShipLevel(MemberShipLevel.Level.Silver, 10, 20, 360));

            await context.Set <MemberShipLevel>().AddAsync(new MemberShipLevel(MemberShipLevel.Level.Gold, 40, 30, 1440));

            await context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task <Division> CreateDivision(Division division)
        {
            await context.Divisions.AddAsync(division);

            if (await context.SaveChangesAsync() == 0)
            {
                throw new PersistenceException("Division was not created");
            }

            return(division);
        }
Beispiel #3
0
        protected override async Task ProvideTestData(ParkSharkDbContext context)
        {
            await base.ProvideTestData(context);

            await context.Members.AddAsync(new Member(
                                               new Contact("Maarten Merken", "+3255511144", String.Empty, "*****@*****.**",
                                                           new Address("Test", "15A", "1000", "Brussel")), new LicensePlate("VXK014", "BE"),
                                               DateTime.Now.AddYears(-15)));

            await context.SaveChangesAsync();

            await context.Members.AddAsync(new Member(
                                               new Contact("John Doe", "+3255511144", String.Empty, "*****@*****.**",
                                                           new Address("Streety", "55", "3500", "Hasselt")), new LicensePlate("155542D4", "US"),
                                               DateTime.Now.AddYears(-1)));

            await context.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task <Allocation> CreateAllocation(Allocation allocation)
        {
            var member = await memberService.GetMember(allocation.MemberId);

            if (member == null)
            {
                throw new ValidationException <Allocation>($"Member with id {allocation.MemberId} does not exist");
            }

            var parkingLot = await parkingLotService.GetParkingLot(allocation.ParkingLotId);

            if (parkingLot == null)
            {
                throw new ValidationException <Allocation>($"Parking Lot with id {allocation.ParkingLotId} does not exist");
            }

            if (!member.LicensePlate.Equals(allocation.LicensePlate))
            {
                throw new ValidationException <Allocation>("The provided licensePlate most be equal to the members' license plate");
            }

            var allocations = await GetAllocationsForParkingLot(allocation.ParkingLotId);

            if (allocations.Count() >= parkingLot.Capacity)
            {
                throw new AllocationException($"Allocation failed, parking lot {allocation.ParkingLotId} is full");
            }

            await context.Allocations.AddAsync(allocation);

            if (await context.SaveChangesAsync() == 0)
            {
                throw new PersistenceException("Allocation was not created");
            }

            await context.Entry(allocation).Reference(a => a.Member).LoadAsync();

            await context.Entry(allocation).Reference(a => a.ParkingLot).LoadAsync();

            return(allocation);
        }
Beispiel #5
0
        public async Task <Member> CreateNewMember(Member member)
        {
            await context.Members.AddAsync(member);

            if (await context.SaveChangesAsync() == 0)
            {
                throw new PersistenceException("Member was not created");
            }

            await context.Entry(member).Reference(p => p.Contact).LoadAsync();

            return(member);
        }
Beispiel #6
0
        public async Task <ParkingLot> CreateNewParkingLot(ParkingLot parkingLot)
        {
            await context.ParkingLots.AddAsync(parkingLot);

            if (await context.SaveChangesAsync() == 0)
            {
                throw new PersistenceException("ParkingLot was not created");
            }

            await context.Entry(parkingLot).Reference(p => p.Division).LoadAsync();

            await context.Entry(parkingLot).Reference(p => p.Contact).LoadAsync();

            await context.Entry(parkingLot).Reference(p => p.BuildingType).LoadAsync();

            return(parkingLot);
        }
Beispiel #7
0
        protected override async Task ProvideTestData(ParkSharkDbContext context)
        {
            await base.ProvideTestData(context);

            var parkinglot = new ParkingLot("One spot", 1,
                                            new Contact("Pl1", "124", "555", "*****@*****.**", new Address("street", "45", "555", "Test")), 1,
                                            50m, 2);
            await context.ParkingLots.AddAsync(parkinglot);

            var member1 = new Member(new Contact("Pl1", "124", "555", "*****@*****.**", new Address("street", "45", "555", "Test")), new LicensePlate("VXK014", "BE"), DateTime.Now, MemberShipLevel.Level.Bronze);
            var member2 = new Member(new Contact("Pl1", "124", "555", "*****@*****.**", new Address("street", "45", "555", "Test")), new LicensePlate("VXK019", "BE"), DateTime.Now, MemberShipLevel.Level.Bronze);

            await context.Members.AddAsync(member1);

            await context.Members.AddAsync(member2);

            await context.SaveChangesAsync();
        }
Beispiel #8
0
        private async Task AllocationTestData(ParkSharkDbContext context)
        {
            await context.Allocations.AddAsync(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), DateTime.Now.AddDays(-5)));

            await context.Allocations.AddAsync(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), DateTime.Now.AddDays(-4)));

            await context.Allocations.AddAsync(new Allocation(2, 1, new LicensePlate("VXK019", "BE"), DateTime.Now.AddDays(-3)));

            var stopped1 = new Allocation(2, 1, new LicensePlate("VXK019", "BE"), DateTime.Now.AddDays(-2));

            stopped1.EndDateTime = DateTime.Now.AddDays(-2);
            var stopped2 = new Allocation(2, 1, new LicensePlate("VXK019", "BE"), DateTime.Now.AddDays(-1));

            stopped2.EndDateTime = DateTime.Now.AddDays(-1);
            await context.Allocations.AddAsync(stopped1);

            await context.Allocations.AddAsync(stopped2);

            await context.Allocations.AddAsync(new Allocation(1, 1, new LicensePlate("VXK014", "BE"), DateTime.Now));

            await context.SaveChangesAsync();
        }