예제 #1
0
        public static void Main(string[] args)
        {
            using var db = new CarDbContext();
            db.Database.Migrate();

            //db.Makes.Add(new Make
            //{
            //    Name = "Audi"
            //});

            //db.Makes.Add(new Make
            //{
            //    Name = "Opel"
            //});

            //db.Makes.Add(new Make
            //{
            //    Name = "Mazda"
            //});

            //db.Makes.Add(new Make
            //{
            //    Name = "Mercedes"
            //});

            //db.Makes.Add(new Make
            //{
            //    Name = "BMW"
            //});

            //db.Makes.Add(new Make
            //{
            //    Name = "Renaugh"
            //});

            //var opelMake = db.Makes.FirstOrDefault(m => m.Name== "Opel");

            //opelMake.Models.Add(new Model
            //{
            //    Name = "Astra",
            //    Year=2017,
            //    Modification="2.2 TDI"
            //});

            //opelMake.Models.Add(new Model
            //{
            //    Name = "Kadet",
            //    Year = 1986,
            //    Modification = "1.3i"
            //});

            //opelMake.Models.Add(new Model
            //{
            //    Name = "Insingnia",
            //    Year = 2015,
            //    Modification = "OPC"
            //});

            //var kadetModels = db.Models.FirstOrDefault(m => m.Name =="Kadet");


            //kadetModels.Cars.Add(new Car {
            //Color="Pink",
            //Price=1500,
            //ProductionDate=DateTime.Now.AddYears( 1986),
            //VIN="12335496"
            //});

            //kadetModels.Cars.Add(new Car
            //{
            //    Color = "Red",
            //    Price = 100,
            //    ProductionDate = DateTime.Now.AddYears(1980),
            //    VIN = "1233ss5496"
            //});
            //kadetModels.Cars.Add(new Car
            //{
            //    Color = "Black",
            //    Price = 2500,
            //    ProductionDate = DateTime.Now.AddYears(1991),
            //    VIN = "12335496"
            //});



            //var carId = db.Cars.FirstOrDefault(c => c.CarId == 1);

            //var newCustomer = new Customer
            //{
            //    FirstName = "Ivan",
            //    LastName = "Ivanov",
            //    Age = 21

            //};

            //newCustomer.Purcheses.Add(new CarPurchase
            //{
            //    Car = carId,
            //    PurchaseDate = DateTime.Now.AddDays(-10),
            //    Price = carId.Price * (decimal)0.8
            //});

            //db.Customers.Add(newCustomer);

            var customer = db.Customers.FirstOrDefault(c => c.Id == 1);

            customer.Address = new Address
            {
                Text = "3-A-7",
                Town = "Sofia"
            };

            db.SaveChanges();
        }
예제 #2
0
        private static async Task FillVignettes(CarDbContext context)
        {
            List <Vignette> vignettes = new List <Vignette>()
            {
                //Old time Expired Vignette with asign
                new Vignette
                {
                    Id        = 18,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays) + (int)TimesPeriod.YearDays),
                    EndDate   = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays),
                    Expired   = true,
                    VehicleId = 1
                },
                //Expired Vignette with asign
                new Vignette
                {
                    Id        = 1,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays),
                    Expired   = true,
                    VehicleId = 1
                },
                //Active Vignette
                new Vignette
                {
                    Id        = 2,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays * 2 + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(((int)TimesPeriod.MonthlyDays * 2)),
                    Expired   = false,
                    VehicleId = 1
                },
                //Expired Vignette with asign
                new Vignette
                {
                    Id        = 3,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays),
                    Expired   = true,
                    VehicleId = 2
                },
                //Active Vignette
                new Vignette
                {
                    Id        = 4,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays * 3 + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(((int)TimesPeriod.MonthlyDays * 3)),
                    Expired   = false,
                    VehicleId = 2
                },
                //Active Vignette
                new Vignette {
                    Id        = 5,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(((int)TimesPeriod.MonthlyDays)),
                    Expired   = false,
                    VehicleId = 3
                },
                //Active Vignette
                new Vignette
                {
                    Id        = 6,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.WeeklyDays * 3)),
                    EndDate   = DateTime.UtcNow.AddDays(((int)TimesPeriod.WeeklyDays * 3 + (int)TimesPeriod.YearDays)),
                    Expired   = false,
                    VehicleId = 4
                },
                //Active Start today Vignette
                new Vignette
                {
                    Id        = 7,
                    StartDate = DateTime.UtcNow,
                    EndDate   = DateTime.UtcNow.AddDays((int)TimesPeriod.YearDays),
                    Expired   = false,
                    VehicleId = 5
                },
                //Active Start Vignette
                new Vignette
                {
                    Id        = 8,
                    StartDate = DateTime.UtcNow,
                    EndDate   = DateTime.UtcNow.AddDays((int)TimesPeriod.YearDays),
                    Expired   = false,
                    VehicleId = 6
                },
                //Expiring Today Vignette
                new Vignette
                {
                    Id        = 9,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow,
                    Expired   = false,
                    VehicleId = 7
                },
                //Expiring Today Vignette
                new Vignette
                {
                    Id        = 10,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow,
                    Expired   = false,
                    VehicleId = 8
                },
                //Expire but not asign
                new Vignette
                {
                    Id        = 11,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays),
                    Expired   = false,
                    VehicleId = 9
                },
                //Expired with asign
                new Vignette
                {
                    Id        = 12,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays),
                    Expired   = true,
                    VehicleId = 10
                },
                //Expired but not asign
                new Vignette
                {
                    Id        = 13,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays),
                    Expired   = false,
                    VehicleId = 10
                },
                //Expired after 30 days
                new Vignette
                {
                    Id        = 14,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays((((int)TimesPeriod.MonthlyDays) - 1)),
                    Expired   = false,
                    VehicleId = 12
                },
                //Expired after 20 days
                new Vignette
                {
                    Id        = 15,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays + 11)),
                    EndDate   = DateTime.UtcNow.AddDays((((int)TimesPeriod.MonthlyDays) - 11)),
                    Expired   = false,
                    VehicleId = 13
                },
                //Expired after 7 days
                new Vignette
                {
                    Id        = 16,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.WeeklyDays + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(((int)TimesPeriod.WeeklyDays)),
                    Expired   = false,
                    VehicleId = 14
                },
                //Expired after 1 day
                new Vignette
                {
                    Id        = 17,
                    StartDate = DateTime.UtcNow.AddDays(-((int)TimesPeriod.Dayly + (int)TimesPeriod.YearDays)),
                    EndDate   = DateTime.UtcNow.AddDays(((int)TimesPeriod.Dayly)),
                    Expired   = false,
                    VehicleId = 15
                }
            };

            await context.Vignettes.AddRangeAsync(vignettes);

            await context.SaveChangesAsync();
        }
예제 #3
0
 public CarsController(CarDbContext context)
 {
     _context = context;
 }
예제 #4
0
 public FeaturesController(CarDbContext context, IMapper mapper)
 {
     this.mapper  = mapper;
     this.context = context;
 }
예제 #5
0
 public static async Task ReinitializeDbForTests(CarDbContext db)
 {
     //db.Messages.RemoveRange(db.Messages);
     await InitializeDbForTests(db);
 }
 public ImporteController(CarDbContext context)
 {
     db = context;
 }
예제 #7
0
 public CarService(CarDbContext context)
 {
     this.db = new UnitOfWork(context);
 }
예제 #8
0
 public CarCategoryRepository(CarDbContext dbContext) : base(dbContext)
 {
 }
예제 #9
0
 public TransmitionRepository(CarDbContext context) : base(context)
 {
 }
예제 #10
0
 public CarRepository(CarDbContext dbContext) : base(dbContext)
 {
 }
예제 #11
0
 public CarService(CarDbContext carDbContext)
 {
     _carDbcontext = carDbContext;
 }
예제 #12
0
 public CarRepository(CarDbContext db)
 {
     _dbContext = db;
 }
예제 #13
0
 public AreaRepository(CarDbContext dbContext) : base(dbContext)
 {
 }
예제 #14
0
 public CarPhotosController(CarDbContext carDbContext)
 {
     _context = carDbContext;
 }
예제 #15
0
 public EngineRepository(CarDbContext context) : base(context)
 {
 }
예제 #16
0
 public CarRepository(CarDbContext db)
 {
     this.db = db;
 }
예제 #17
0
 public ApiCarController(ICar car, CarDbContext Db)
 {
     _car      = car;
     _database = Db;
 }
예제 #18
0
 public ManufacturersController(CarDbContext context)
 {
     this.context = context;
 }
예제 #19
0
 public ColorTypeRepository(CarDbContext context) : base(context)
 {
 }
예제 #20
0
 public CarPhotoRepository(CarDbContext context) : base(context)
 {
 }
예제 #21
0
 public JSONController(CarDbContext DataBase)
 {
     _database = DataBase;
 }
예제 #22
0
 public SeriesController(CarDbContext context)
 {
     _context = context;
 }
예제 #23
0
        private static async Task FillVehicles(CarDbContext context)
        {
            List <Vehicle> vehicles = new List <Vehicle>()
            {
                //Active
                //Vignette
                //Insurance expire
                //Inspection
                //OilChange after 1000 km
                new Vehicle
                {
                    Id                    = 1,
                    Model                 = "Up",
                    PlateNumber           = "CT1234BM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 112000,
                    EndOilChange          = 113000,
                    Vin                   = "VWVZZZ1KZ1P324444",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.HalfYearDays),
                    BranchId              = 1,
                    BrandId               = 1,
                    OwnerId               = 1,
                },
                //Active
                //Vignette
                //Insurance expire
                //Inspection
                //OilChange expire 999
                new Vehicle
                {
                    Id                    = 2,
                    Model                 = "Up",
                    PlateNumber           = "CTTTTTBM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(6),
                    TravelledDistance     = 180000,
                    EndOilChange          = 180999,
                    Vin                   = "VWVZZZ1KZ1P111222",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.QuarterOfYearDays),
                    BranchId              = 2,
                    BrandId               = 1,
                    OwnerId               = 1,
                },
                //Vignette
                //Insurance expire
                //Inspection expire monthly
                //OilChange
                new Vehicle
                {
                    Id                    = 3,
                    Model                 = "Up",
                    PlateNumber           = "CT7777AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(3),
                    TravelledDistance     = 18000,
                    EndOilChange          = 28000,
                    Vin                   = "VWVZZZ1KZ1P999888",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.MonthlyDays - 1),
                    BranchId              = 3,
                    BrandId               = 1,
                    OwnerId               = 1,
                    //List<InsurancePolicy>
                    //List<Vignette>
                },
                //Vignette
                //InspectionSafetyCheck expire today
                //Insurance
                //OilChange
                new Vehicle
                {
                    Id                    = 4,
                    Model                 = "Up",
                    PlateNumber           = "CT9876AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(8),
                    TravelledDistance     = 198000,
                    EndOilChange          = 208000,
                    Vin                   = "VWVZZZ1KZ1P333333",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow,
                    BranchId              = 1,
                    BrandId               = 1,
                    OwnerId               = 1,
                },
                //Vignette
                //InspectionSafetyCheck expired
                //Insurance expire
                //OilChange
                new Vehicle
                {
                    Id                    = 5,
                    Model                 = "Up",
                    PlateNumber           = "CT9876AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(8),
                    TravelledDistance     = 198000,
                    EndOilChange          = 200000,
                    Vin                   = "VWVZZZ1KZ1P333333",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays(-(int)TimesPeriod.Dayly),
                    BranchId              = 1,
                    BrandId               = 1,
                    OwnerId               = 1
                },
                //Vignette
                //InspectionSafetyCheck expired
                //Insurance
                //OilChange 100 km to oil change
                new Vehicle
                {
                    Id                    = 6,
                    Model                 = "TT",
                    PlateNumber           = "CT9876AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 198000,
                    EndOilChange          = 198100,
                    Vin                   = "VWVZZZ1KZ1P98744",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays(-(int)TimesPeriod.Dayly),
                    BranchId              = 4,
                    BrandId               = 2,
                    OwnerId               = 2,
                },
                //Vignette expire
                //InspectionSafetyCheck expiring
                //Insurance
                //OilChange expire
                new Vehicle
                {
                    Id                    = 7,
                    Model                 = "Up",
                    PlateNumber           = "CT1111AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(7),
                    TravelledDistance     = 198000,
                    EndOilChange          = 198000,
                    Vin                   = "VWVZZZ1KZ1P447788",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.WeeklyDays),
                    BranchId              = 1,
                    BrandId               = 1,
                    OwnerId               = 1,
                },
                //Vignette expire
                //InspectionSafetyCheck
                //Insurance expire
                //OilChange expire 10 km to oil change
                new Vehicle
                {
                    Id                    = 8,
                    Model                 = "Up",
                    PlateNumber           = "CT5555AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(2),
                    TravelledDistance     = 198000,
                    EndOilChange          = 198010,
                    Vin                   = "VWVZZZ1KZ1P357159",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.HalfYearDays),
                    BranchId              = 1,
                    BrandId               = 1,
                    OwnerId               = 1,
                },
                //Vignette expire
                //InspectionSafetyCheck
                //Insurance
                //OilChange exceed expire TravelledDistance
                new Vehicle
                {
                    Id                    = 9,
                    Model                 = "Up",
                    PlateNumber           = "CT75665AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 198000,
                    EndOilChange          = 197000,
                    Vin                   = "VWVZZZ1KZ1P357159",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.HalfYearDays),
                    BranchId              = 3,
                    BrandId               = 1,
                    OwnerId               = 1,
                },
                //Vignette expire
                //InspectionSafetyCheck expiring
                //Insurance expire
                //OilChange expire
                new Vehicle
                {
                    Id                    = 10,
                    Model                 = "Up",
                    PlateNumber           = "CT75665AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 198000,
                    EndOilChange          = 198000,
                    Vin                   = "VWVZZZ1KZ1P357159",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.MonthlyDays - 1),
                    BranchId              = 3,
                    BrandId               = 1,
                    OwnerId               = 1,
                },
                //Vignette  never use vignette
                //InspectionSafetyCheck  never use inspection
                //Insurance never use insurance
                //OilChange never use
                new Vehicle
                {
                    Id                    = 11,
                    Model                 = "Passat",
                    PlateNumber           = "CT72235AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 0,
                    EndOilChange          = 999999,
                    Vin                   = "WVZWWWAAAAAWASDAS22",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.MaxValue,
                    BranchId              = 5,
                    BrandId               = 1,
                    OwnerId               = 2,
                },
                //vignette expire after 30 days
                //Insurance
                //Inspection
                //OilChange
                new Vehicle
                {
                    Id                    = 12,
                    Model                 = "TT",
                    PlateNumber           = "CT0987AM",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 198000,
                    EndOilChange          = 208000,
                    Vin                   = "WZWZASAAASDASDASDASDA",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.Dayly),
                    BranchId              = 5,
                    BrandId               = 2,
                    OwnerId               = 2,
                },
                //Vignette expire after 20 days
                //Insurance
                //Inspection
                //OilChange
                new Vehicle
                {
                    Id                    = 13,
                    Model                 = "expire 20 days",
                    PlateNumber           = "expire 20 days",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 198000,
                    EndOilChange          = 208000,
                    Vin                   = "expire 20 days",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.HalfYearDays),
                    BranchId              = 5,
                    BrandId               = 2,
                    OwnerId               = 2,
                },
                //Vignette expire after 7 days
                //Insurance
                //Inspection
                //OilChange
                new Vehicle
                {
                    Id                    = 14,
                    Model                 = "expire 7 days",
                    PlateNumber           = "expire 7 days",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 198000,
                    EndOilChange          = 208000,
                    Vin                   = "expire 7 days",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.HalfYearDays),
                    BranchId              = 5,
                    BrandId               = 2,
                    OwnerId               = 2,
                },
                //Vignette expire after 1 days
                //Insurance
                //Inspection
                //OilChange
                new Vehicle
                {
                    Id                    = 15,
                    Model                 = "expire 1 day",
                    PlateNumber           = "expire 1 day",
                    YearОfМanufacture     = DateTime.UtcNow.AddYears(5),
                    TravelledDistance     = 198000,
                    EndOilChange          = 208000,
                    Vin                   = "expire 1 day",
                    Status                = VehicleStatus.OnMotion,
                    InspectionSafetyCheck = DateTime.UtcNow.AddDays((int)TimesPeriod.HalfYearDays),
                    BranchId              = 5,
                    BrandId               = 2,
                    OwnerId               = 2,
                },
            };

            await context.Vehicles.AddRangeAsync(vehicles);

            await context.SaveChangesAsync();
        }
예제 #24
0
 public MakesController(CarDbContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
예제 #25
0
        private static async Task FillInsurancePolicies(CarDbContext context)
        {
            List <InsurancePolicy> insurancePolicies = new List <InsurancePolicy>()
            {
                //ExpiredFullCascoInsurance
                new InsurancePolicy {
                    Id                 = 1,
                    TypeInsurance      = TypeInsurance.FullCasco,
                    StartDate          = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays)),
                    EndDate            = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays),
                    Expired            = true,
                    InsuranceCompanyId = 1,
                    VehicleId          = 1
                },
                //Active FullCasco insurance
                new InsurancePolicy {
                    Id                 = 2,
                    TypeInsurance      = TypeInsurance.FullCasco,
                    StartDate          = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays * 2 + (int)TimesPeriod.YearDays)),
                    EndDate            = DateTime.UtcNow.AddDays(((int)TimesPeriod.MonthlyDays * 2)),
                    Expired            = false,
                    InsuranceCompanyId = 1,
                    VehicleId          = 1
                },
                //Expired ThirdPartyLiability Insurance but not asign
                new InsurancePolicy {
                    Id                 = 3,
                    TypeInsurance      = TypeInsurance.ThirdPartyLiability,
                    StartDate          = DateTime.UtcNow.AddDays(-((int)TimesPeriod.YearDays + (int)TimesPeriod.YearDays)),
                    EndDate            = DateTime.UtcNow.AddDays(-(int)TimesPeriod.YearDays),
                    Expired            = false,
                    InsuranceCompanyId = 2,
                    VehicleId          = 1
                },
                //Active ThirdPartyLiability insurance
                new InsurancePolicy {
                    Id                 = 4,
                    TypeInsurance      = TypeInsurance.ThirdPartyLiability,
                    StartDate          = DateTime.UtcNow,
                    EndDate            = DateTime.UtcNow.AddDays((int)TimesPeriod.YearDays),
                    Expired            = false,
                    InsuranceCompanyId = 2,
                    VehicleId          = 1
                },
                //Active FullCasco insurance
                new InsurancePolicy {
                    Id                 = 5,
                    TypeInsurance      = TypeInsurance.FullCasco,
                    StartDate          = DateTime.UtcNow,
                    EndDate            = DateTime.UtcNow.AddDays((int)TimesPeriod.YearDays),
                    Expired            = false,
                    InsuranceCompanyId = 3,
                    VehicleId          = 2
                },
                //Start now FullCasco insurance
                new InsurancePolicy {
                    Id                 = 6,
                    TypeInsurance      = TypeInsurance.FullCasco,
                    StartDate          = DateTime.UtcNow,
                    EndDate            = DateTime.UtcNow.AddYears((int)TimesPeriod.YearDays),
                    Expired            = false,
                    InsuranceCompanyId = 3,
                    VehicleId          = 3
                },
                //Start now ThirdPartyLiability insurance
                new InsurancePolicy {
                    Id                 = 7,
                    TypeInsurance      = TypeInsurance.ThirdPartyLiability,
                    StartDate          = DateTime.UtcNow,
                    EndDate            = DateTime.UtcNow.AddYears((int)TimesPeriod.YearDays),
                    Expired            = false,
                    InsuranceCompanyId = 2,
                    VehicleId          = 3
                },
                //Expiring today
                new InsurancePolicy {
                    Id                 = 8,
                    TypeInsurance      = TypeInsurance.FullCasco,
                    StartDate          = DateTime.UtcNow.AddYears(-((int)TimesPeriod.YearDays)),
                    EndDate            = DateTime.UtcNow,
                    Expired            = false,
                    InsuranceCompanyId = 3,
                    VehicleId          = 5
                },
                //Expired after 30 days
                new InsurancePolicy {
                    Id                 = 9,
                    TypeInsurance      = TypeInsurance.ThirdPartyLiability,
                    StartDate          = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays + (int)TimesPeriod.YearDays)),
                    EndDate            = DateTime.UtcNow.AddDays((((int)TimesPeriod.MonthlyDays) - 1)),
                    Expired            = false,
                    InsuranceCompanyId = 2,
                    VehicleId          = 2
                },
                //Expired after 20 days
                new InsurancePolicy {
                    Id                 = 10,
                    TypeInsurance      = TypeInsurance.ThirdPartyLiability,
                    StartDate          = DateTime.UtcNow.AddDays(-((int)TimesPeriod.MonthlyDays + 11)),
                    EndDate            = DateTime.UtcNow.AddDays((((int)TimesPeriod.MonthlyDays) - 11)),
                    Expired            = false,
                    InsuranceCompanyId = 2,
                    VehicleId          = 5
                },
                //Expired after 7 days
                new InsurancePolicy {
                    Id                 = 11,
                    TypeInsurance      = TypeInsurance.ThirdPartyLiability,
                    StartDate          = DateTime.UtcNow.AddDays(-((int)TimesPeriod.WeeklyDays + (int)TimesPeriod.YearDays)),
                    EndDate            = DateTime.UtcNow.AddDays(((int)TimesPeriod.WeeklyDays)),
                    Expired            = false,
                    InsuranceCompanyId = 2,
                    VehicleId          = 3
                },
                //Expired after 1 days
                new InsurancePolicy {
                    Id                 = 12,
                    TypeInsurance      = TypeInsurance.ThirdPartyLiability,
                    StartDate          = DateTime.UtcNow.AddDays(-((int)TimesPeriod.Dayly + (int)TimesPeriod.YearDays)),
                    EndDate            = DateTime.UtcNow.AddDays(((int)TimesPeriod.Dayly)),
                    Expired            = false,
                    InsuranceCompanyId = 2,
                    VehicleId          = 8
                }
            };

            await context.InsurancePolicies.AddRangeAsync(insurancePolicies);

            await context.SaveChangesAsync();
        }
예제 #26
0
 public UsersService(CarDbContext db, IMapper mapper, UserManager <User> userManager)
 {
     this.db     = db;
     this.mapper = mapper;
 }
예제 #27
0
 public CategoryRepository(CarDbContext carContext)
 {
     this.carContext = carContext;
 }
예제 #28
0
 public CarBrandsController(CarDbContext carDbContext)
 {
     _context = carDbContext;
 }
        public static void Main(string[] args)
        {
            using var db = new CarDbContext();

            db.Database.Migrate();

            using var data = new CarDbContext();

            var car = data.Cars
                      .FirstOrDefault(x => x.Id == 1);

            data.Entry(car)
            .Collection(x => x.Owners)
            .Load();

            Console.WriteLine(car.Owners.FirstOrDefault().PurchaseDate);

            ;

            //var cars = data.Cars
            //    .Where(x => x.Price < 20000)
            //    .Update(x => new Car { Price = x.Price * 1.2m });

            //data.Cars
            //    .Where(x => x.Price < 200000)
            //    .ToList()
            //    .ForEach(x => x.Price *= 1.2m);

            //data.SaveChanges();



            //var price = 5000;
            //
            //var stopwatch = Stopwatch.StartNew();
            //
            //db.Cars
            //    .Where(x => x.Price > price)
            //    .Where(x => x.Owners.Any(x => x.Customer.LastName == null))
            //    .Select(x => new ResultModel
            //    {
            //        Count = x.Owners.Count(x => x.Customer.Purchases.Count > 1)
            //    })
            //    .ToList();
            //
            //Console.WriteLine(stopwatch.Elapsed + " Cold");
            //
            //stopwatch = Stopwatch.StartNew();
            //
            //db.Cars
            //    .Where(x => x.Price > price)
            //    .Where(x => x.Owners.Any(x => x.Customer.LastName == null))
            //    .Select(x => new ResultModel
            //    {
            //        Count = x.Owners.Count(x => x.Customer.Purchases.Count > 1)
            //    })
            //    .ToList();
            //
            //Console.WriteLine(stopwatch.Elapsed + " Warm");
            //
            //stopwatch = Stopwatch.StartNew();
            //
            //CarQueries.ToResult(db, price);
            //
            //Console.WriteLine(stopwatch.Elapsed + " Compiled Query With Compilation");
            //
            //stopwatch = Stopwatch.StartNew();
            //
            //CarQueries.ToResult(db, price);
            //
            //Console.WriteLine(stopwatch.Elapsed + " Compiled Query");

            //var result = db.Purchases.Select(x => new PuchaseResultModel
            //{
            //    Price = x.Price,
            //    PurchaseDate = x.PurchaseDate,
            //    Customer = new CustomerResultModel
            //    {
            //        Name = x.Customer.FirstName + " " + x.Customer.LastName,
            //        Town = x.Customer.Address.Town
            //    },
            //    Car = new CarResultModel
            //    {
            //        Vin = x.Car.Vin,
            //        Make = x.Car.Model.Make.Name,
            //        Model = x.Car.Model.Name
            //    }
            //}).ToList();

            //var make = db.Makes.FirstOrDefault(x => x.Name == "Mercedes");
            //
            //var model = new Model
            //{
            //    Modification = "500",
            //    Name = "CL",
            //    Year = 3000
            //};
            //
            //make.Models.Add(model);
        }
 public HomeController(ILogger <HomeController> logger, ICarRepository carRepository, CarDbContext db)
 {
     _logger            = logger;
     this.carRepository = carRepository;
     this.db            = db;
 }