Beispiel #1
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 #2
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 #3
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);
        }