Пример #1
0
        public void SeedData(VehiclesPriceListAppContext context)
        {
            var ownersList = new[] {
                new { fname = "Avi", lname = "Pro", address = "Jabotinski 14 Givatime" },
                new { fname = "Guy", lname = "Bochveld", address = "Tzahal 32 Hod Hasharon" },
                new { fname = "Yosi", lname = "Mizrahi", address = "Hovevei Zion 2 Petach Tikva" },
                new { fname = "David", lname = "Hamelech", address = "Waizman 4 Ramat Gan" },
                new { fname = "Moshe", lname = "Rabeno", address = "Rakefet 87 Tel Aviv" },
                new { fname = "Gil", lname = "Cohen", address = "Almog 7 Oranit" },
                new { fname = "Ziv", lname = "Barsheshet", address = "Shoshan 18 Ramat Efal" },
                new { fname = "Nati", lname = "Simantov", address = "Haroee 23 Herzlia" },
                new { fname = "Ofer", lname = "Wiess", address = "Nirit 31 Kfar Saba" },
            }.ToList();

            for (var i = 0; i < 100; i++)
            {
                context.VehicleOwner.Add(new VehicleOwner()
                {
                    FirstName    = ownersList[i % 9].fname,
                    LastName     = ownersList[i % 9].lname,
                    Telephone    = string.Format("05{0}-{1}{2}{3}{4}{5}{6}{7}", i % 4, i % 10, i % 6, i % 9, i % 10, i % 5, i % 7, i % 8),
                    Address      = ownersList[i % 9].address,
                    EmailAddress = string.Format("{0}.{1}.{2}@CarSales.com", ownersList[i % 9].fname, ownersList[i % 9].lname, i),
                });
            }
        }
Пример #2
0
        public void SeedData(VehiclesPriceListAppContext context)
        {
            context.VehicleMenufacturer.Add(new VehicleMenufacturer()
            {
                Name = "Honda"
            });

            context.VehicleMenufacturer.Add(new VehicleMenufacturer()
            {
                Name = "Ford"
            });

            context.VehicleMenufacturer.Add(new VehicleMenufacturer()
            {
                Name = "Jeep"
            });
            context.VehicleMenufacturer.Add(new VehicleMenufacturer()
            {
                Name = "Kia"
            });
            context.VehicleMenufacturer.Add(new VehicleMenufacturer()
            {
                Name = "Alpha Romeo"
            });
        }
Пример #3
0
        public void SeedData(VehiclesPriceListAppContext context)
        {
            context.VehicleStatus.Add(new VehicleStatus()
            {
                Name = "יד ראשונה"
            });

            context.VehicleStatus.Add(new VehicleStatus()
            {
                Name = "יד שנייה"
            });
        }
Пример #4
0
        public void SeedData(VehiclesPriceListAppContext context)
        {
            context.VehicleType.Add(new VehicleType()
            {
                Name = "פרטי"
            });

            context.VehicleType.Add(new VehicleType()
            {
                Name = "מסחרי"
            });

            context.VehicleType.Add(new VehicleType()
            {
                Name = "גיפים"
            });
        }
Пример #5
0
        public void SeedData(VehiclesPriceListAppContext context)
        {
            context.VehicleMenufacturingOrigin.Add(new VehicleMenufacturingOrigin()
            {
                Name = "Asia"
            });

            context.VehicleMenufacturingOrigin.Add(new VehicleMenufacturingOrigin()
            {
                Name = "USA"
            });

            context.VehicleMenufacturingOrigin.Add(new VehicleMenufacturingOrigin()
            {
                Name = "China"
            });

            context.VehicleMenufacturingOrigin.Add(new VehicleMenufacturingOrigin()
            {
                Name = "Germany"
            });
        }
Пример #6
0
        public void SeedDatabase(VehiclesPriceListAppContext context)
        {
            //Get all the "ISeed" implementations in this assembly
            var seedTypes = typeof(GlobalSeeder).Assembly.GetTypes().Where(t => typeof(ISeed).IsAssignableFrom(t) && t.IsClass);

            //Little bit of Linq to object to get all the types in a suitable format.
            var seeds =
                seedTypes.Select(st => new
            {
                SeedType       = st,
                DependingSeeds = st.GetCustomAttributes(typeof(DependsOnAttribute), true).OfType <DependsOnAttribute>().Select(dst => dst.DependingType).ToList()
            }).ToList();

            //While there is still some seeds to process
            while (seeds.Count > 0)
            {
                //Find all the seeds without anymore depending seeds to process
                var oprhenSeeds = seeds.Where(s => s.DependingSeeds.Count == 0).ToList();
                foreach (var orphenSeed in oprhenSeeds)
                {
                    //Instanciate the current seed
                    ISeed seedInstance = (ISeed)Activator.CreateInstance(orphenSeed.SeedType);
                    //Execute seed process
                    seedInstance.SeedData(context);

                    //Remove the processed seed from all the dependant seeds
                    var relatedSeeds = seeds.Where(s => s.DependingSeeds.Any(ds => ds == orphenSeed.SeedType));
                    foreach (var relatedSeed in relatedSeeds)
                    {
                        relatedSeed.DependingSeeds.Remove(orphenSeed.SeedType);
                    }
                    //Remove the processed seed from the "to be processed list".
                    seeds.Remove(orphenSeed);
                }
            }
            //Finally save all changes to the Entity framework context.
            context.SaveChanges();
        }
Пример #7
0
        public void SeedData(VehiclesPriceListAppContext context)
        {
            var randomNumber = new Random();

            KnownColor[] names = (KnownColor[])Enum.GetValues(typeof(KnownColor));

            for (int i = 0; i < 100; i++)
            {
                context.VehiclePriceListItem.Add(new VehiclePriceListItem()
                {
                    AskingPrice                = (randomNumber.Next(40, 100) * 1000).ToString(),
                    DateReceived               = DateTime.Now.ToLocalTime(),
                    EquippingDetails           = "Comfrontline",
                    Color                      = names[randomNumber.Next(names.Length)].ToString(),
                    EngineType                 = "regular",
                    TestValidExpiration        = DateTime.Now.ToLocalTime().AddMonths(1),
                    VehicleMenufacturer        = context.VehicleMenufacturer.Local.Skip(randomNumber.Next(context.VehicleMenufacturer.Local.Count())).Take(1).FirstOrDefault(),
                    VehicleMenufacturingOrigin = context.VehicleMenufacturingOrigin.Local.Skip(randomNumber.Next(context.VehicleMenufacturingOrigin.Local.Count())).Take(1).FirstOrDefault(),
                    VehicleType                = context.VehicleType.Local.Skip(randomNumber.Next(context.VehicleType.Local.Count())).Take(1).FirstOrDefault(),
                    VehicleOwner               = context.VehicleOwner.Local.Skip(randomNumber.Next(context.VehicleOwner.Local.Count())).Take(1).FirstOrDefault(),
                    VehicleStatus              = context.VehicleStatus.Local.Skip(randomNumber.Next(context.VehicleStatus.Local.Count())).Take(1).FirstOrDefault(),
                });
            }
        }
Пример #8
0
 public OwnersRepository(VehiclesPriceListAppContext ctx) : base(ctx)
 {
 }
 public MenufactureringOriginRepository(VehiclesPriceListAppContext ctx) : base(ctx)
 {
 }
Пример #10
0
 public StatusRepository(VehiclesPriceListAppContext ctx) : base(ctx)
 {
 }
Пример #11
0
 public TypeRepository(VehiclesPriceListAppContext ctx) : base(ctx)
 {
 }
Пример #12
0
 public UserRepository(VehiclesPriceListAppContext ctx)
 {
     _ctx = ctx;
 }