Example #1
0
        public static void GenerateMemberData(IServiceProvider serviceProvider)
        {
            using (var context = new Garage3Context(serviceProvider.GetRequiredService <DbContextOptions <Garage3Context> >()))
            {
                if (!context.Member.Any())
                {
                    var standard = context.MembershipType.FirstOrDefault(x => x.Type == "Standard");
                    var pro      = context.MembershipType.FirstOrDefault(x => x.Type == "Pro");

                    context.Member.AddRange(
                        new Member {
                        PersonalIdentityNumber = "198002149876", FirstName = "Conny", LastName = "Andersson", Joined = DateTime.Parse("2020-03-01"), ExtendedMemberShipEndDate = DateTime.Parse("2021-02-01"), MembershipType = standard
                    },
                        new Member {
                        PersonalIdentityNumber = "198102149876", FirstName = "Berta", LastName = "Svennson", Joined = DateTime.Parse("2021-01-01"), ExtendedMemberShipEndDate = DateTime.Parse("2021-05-06"), MembershipType = pro
                    },
                        new Member {
                        PersonalIdentityNumber = "198202149876", FirstName = "David", LastName = "Nokto", Joined = DateTime.Parse("2018-11-01"), ExtendedMemberShipEndDate = DateTime.Parse("2021-03-12"), MembershipType = standard
                    },
                        new Member {
                        PersonalIdentityNumber = "198302149876", FirstName = "Anita", LastName = "Berg", Joined = DateTime.Parse("2019-06-01"), ExtendedMemberShipEndDate = DateTime.Parse("2021-03-24"), MembershipType = standard
                    },
                        new Member {
                        PersonalIdentityNumber = "193002149876", FirstName = "Stefan", LastName = "Karlsson", Joined = DateTime.Parse("2021-03-01"), ExtendedMemberShipEndDate = DateTime.Parse("2021-04-01"), MembershipType = pro
                    }
                        );
                    context.SaveChanges();
                }
            }
        }
Example #2
0
        public static void GenerateTypes(IServiceProvider serviceProvider)
        {
            using (var context = new Garage3Context(serviceProvider.GetRequiredService <DbContextOptions <Garage3Context> >()))
            {
                if (context.MembershipType.Any())
                {
                    goto vehicleTypeGen;
                }
                context.MembershipType.AddRange(
                    new MembershipType {
                    Type = "Pro", Discount = 10
                },
                    new MembershipType {
                    Type = "Standard", Discount = 0
                }
                    );

vehicleTypeGen:

                if (context.VehicleType.Any())
                {
                    goto parkingSpaceGen;
                }

                context.VehicleType.AddRange(
                    new VehicleType {
                    Type = "Car", Size = 1, imgSrc = "/images/VehicleTypeIcons/car icon.png"
                },
                    new VehicleType {
                    Type = "Motorcycle", Size = 0.33F, imgSrc = "/images/VehicleTypeIcons/motorcycle icon.png"
                },
                    new VehicleType {
                    Type = "Pickup", Size = 2, imgSrc = "/images/VehicleTypeIcons/pickup icon.png"
                },
                    new VehicleType {
                    Type = "Truck", Size = 3, imgSrc = "/images/VehicleTypeIcons/truck icon.png"
                }
                    );

parkingSpaceGen:

                if (context.ParkingSpace.Any())
                {
                    goto savechanges;
                }

                for (int i = 1; i < 10; i++)
                {
                    context.ParkingSpace.AddRange(
                        new ParkingSpace {
                        Number = i, Name = "Ruta" + i, Size = 1
                    });
                }

savechanges:
                context.SaveChanges();
            }
        }
Example #3
0
        public static void GenerateVehicleData(IServiceProvider serviceProvider)
        {
            using (var context = new Garage3Context(serviceProvider.GetRequiredService <DbContextOptions <Garage3Context> >()))
            {
                if (!context.Vehicle.Any())
                {
                    var car        = context.VehicleType.FirstOrDefault(x => x.Type == "Car");
                    var motorcycle = context.VehicleType.FirstOrDefault(x => x.Type == "Motorcycle");
                    var pickup     = context.VehicleType.FirstOrDefault(x => x.Type == "Pickup");
                    var truck      = context.VehicleType.FirstOrDefault(x => x.Type == "Truck");

                    var owner1 = context.Member.Where(m => m.MemberID == 1).FirstOrDefault();
                    var owner2 = context.Member.Where(m => m.MemberID == 2).FirstOrDefault();
                    var owner3 = context.Member.Where(m => m.MemberID == 3).FirstOrDefault();
                    var owner4 = context.Member.Where(m => m.MemberID == 4).FirstOrDefault();
                    var owner5 = context.Member.Where(m => m.MemberID == 5).FirstOrDefault();

                    context.Vehicle.AddRange(
                        new Vehicle {
                        Owner = owner1, Brand = "Volvo", NumberOfWheels = 4, LicenseNumber = "ABC123", Color = "Black", Model = "E4", VehicleType = car
                    },
                        new Vehicle {
                        Owner = owner2, Brand = "Yamaha", NumberOfWheels = 2, LicenseNumber = "VBA234", Color = "Brown", Model = "E5", VehicleType = motorcycle
                    },
                        new Vehicle {
                        Owner = owner3, Brand = "Toyota", NumberOfWheels = 4, LicenseNumber = "DHI137", Color = "Orangie", Model = "E0", VehicleType = pickup
                    },
                        new Vehicle {
                        Owner = owner4, Brand = "Mercedes", NumberOfWheels = 6, LicenseNumber = "BCA354", Color = "DowerBlue", Model = "E9", VehicleType = truck
                    },
                        new Vehicle {
                        Owner = owner5, Brand = "Harley", NumberOfWheels = 2, LicenseNumber = "DCI298", Color = "MaybeYw", Model = "EU", VehicleType = motorcycle
                    }
                        );

                    context.SaveChanges();
                }
            }
        }
Example #4
0
        private string ParkVehicle(string licenseNumber)
        {
            var vehicle = db.Vehicle.Include(v => v.VehicleType).Include(v => v.ParkedAt).Where(v => v.LicenseNumber == licenseNumber).FirstOrDefault();

            // if vehicle is already parked inform user
            if (vehicle.ParkedAt.Count() > 0)
            {
                return("VehicleAlreadyParked");
            }
            // if no space for vehicle
            var spaceCheck = new Garage3.Utilites.ParkingSpaceCalculations(db);

            if (spaceCheck.vehicleTypeStatistics().Where(v => v.Type == vehicle.VehicleType.Type).Select(v => v.AmountAbleToPark).First() <= 0)
            {
                return("NoSpaceForVehicle");
            }
            var parkingSpaces = db.ParkingSpace.Include(v => v.Vehicle);
            // Get vehicle size
            var vehicleSize = vehicle.VehicleType.Size;

            if (vehicleSize < 1)
            {
                // Check each parkingspace
                foreach (var parkingSpace in parkingSpaces)
                {
                    // calculate space left
                    float totalVehicleSize = 0;
                    foreach (var vehicleInParkingSpace in parkingSpace.Vehicle)
                    {
                        totalVehicleSize += vehicleInParkingSpace.VehicleType.Size;
                    }

                    // if vehicle fits park
                    if ((parkingSpace.Size - totalVehicleSize) > vehicleSize)
                    {
                        vehicle.ParkedAt.Add(parkingSpace);
                        parkingSpace.Vehicle.Add(vehicle);
                        break;
                    }
                }
            }
            if (vehicleSize >= 1)
            {
                List <ParkingSpace> emptySpaces = new List <ParkingSpace>();
                foreach (var parkingspace in parkingSpaces)
                {
                    // find empty space
                    if (parkingspace.Vehicle.Count() == 0)
                    {
                        emptySpaces.Add(parkingspace);
                        // if empty spaces >= vehicle size park vehicle
                        if (emptySpaces.Count >= vehicleSize)
                        {
                            foreach (var emptySpace in emptySpaces)
                            {
                                vehicle.ParkedAt.Add(emptySpace);
                                emptySpace.Vehicle.Add(vehicle);
                            }
                            break;
                        }
                    }
                    else
                    {
                        // reset emptySpots
                        emptySpaces.Clear();
                    }
                }
            }
            vehicle.ArrivalTime = DateTime.Now;
            db.SaveChanges();
            return(nameof(Garage3.Controllers.HomeController.Index));
        }