Advertisement
Guest User

Untitled

a guest
Jan 9th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.89 KB | None | 0 0
  1. using Kundbolaget.EntityFramework.Context;
  2. using Kundbolaget.Models.EntityModels;
  3. using System;
  4. using System.Data.Entity.Migrations;
  5. using System.Linq;
  6.  
  7. namespace Kundbolaget.Migrations
  8. {
  9.     internal sealed class Configuration : DbMigrationsConfiguration<StoreContext>
  10.     {
  11.         public Configuration()
  12.         {
  13.             AutomaticMigrationsEnabled = false;
  14.         }
  15.  
  16.         protected override void Seed(StoreContext context)
  17.         {
  18.             var volumes = new[]
  19.             {
  20.                 new Volume {Milliliter = 250},
  21.                 new Volume {Milliliter = 330},
  22.                 new Volume {Milliliter = 350},
  23.                 new Volume {Milliliter = 355},
  24.                 new Volume {Milliliter = 500},
  25.                 new Volume {Milliliter = 700},
  26.                 new Volume {Milliliter = 750},
  27.                 new Volume {Milliliter = 1000},
  28.                 new Volume {Milliliter = 3000},
  29.             };
  30.             var containers = new[]
  31.             {
  32.                 new Container {Name = "Burk"},
  33.                 new Container {Name = "Flaska"},
  34.                 new Container {Name = "Box"}
  35.             };
  36.  
  37.             var categories = new[]
  38.             {
  39.                 new Category {Name = "Öl"},
  40.                 new Category {Name = "Sprit"},
  41.                 new Category {Name = "Vin"},
  42.             };
  43.  
  44.             var productGroups = new[]
  45.             {
  46.                 new ProductGroup {Name = "Vitt vin", Category = categories[2]},
  47.                 new ProductGroup {Name = "Rött vin", Category = categories[2]},
  48.                 new ProductGroup {Name = "Rosé vin", Category = categories[2]},
  49.                 new ProductGroup {Name = "Mouserande vin", Category = categories[2]},
  50.                 new ProductGroup {Name = "Portvin", Category = categories[2]},
  51.                 new ProductGroup {Name = "IPA", Category = categories[0]},
  52.                 new ProductGroup {Name = "ALE", Category = categories[0]},
  53.                 new ProductGroup {Name = "Lager", Category = categories[0]},
  54.                 new ProductGroup {Name = "APA", Category = categories[0]},
  55.                 new ProductGroup {Name = "Stout", Category = categories[0]},
  56.                 new ProductGroup {Name = "Rom", Category = categories[1]},
  57.                 new ProductGroup {Name = "Vodka", Category = categories[1]},
  58.                 new ProductGroup {Name = "Whiskey", Category = categories[1]},
  59.                 new ProductGroup {Name = "Konjak", Category = categories[1]},
  60.                 new ProductGroup {Name = "Likör", Category = categories[1]},
  61.                 new ProductGroup {Name = "Punch", Category = categories[1]},
  62.                 new ProductGroup {Name = "Calvados", Category = categories[1]},
  63.             };
  64.  
  65.             var countries = new[]
  66.             {
  67.                 new Country {Name = "Sweden", CountryCode = "+46", Region = "EMEA"},
  68.                 new Country {Name = "Norway", CountryCode = "+47", Region = "EMEA"},
  69.                 new Country {Name = "Finland", CountryCode = "+358", Region = "EMEA"},
  70.                 new Country {Name = "Denmark", CountryCode = "+45", Region = "EMEA"},
  71.             };
  72.  
  73.             var contactPersons = new[]
  74.             {
  75.                 new ContactPerson
  76.                 {
  77.                     FirstName = "Viktor",
  78.                     LastName = "Gustafsson",
  79.                     Email = "Viktor@randomcompany.com",
  80.                     PhoneNumber = "+46899 99 99"
  81.                 },
  82.                 new ContactPerson
  83.                 {
  84.                     FirstName = "Robert",
  85.                     LastName = "Andersson",
  86.                     Email = "Robert@randomcompany.com",
  87.                     PhoneNumber = "+46899 88 88"
  88.                 },
  89.                 new ContactPerson
  90.                 {
  91.                     FirstName = "Willy",
  92.                     LastName = "Kind",
  93.                     Email = "Willy@randomcompany.com",
  94.                     PhoneNumber = "+46899 77 77"
  95.                 },
  96.                 new ContactPerson
  97.                 {
  98.                     FirstName = "Michel",
  99.                     LastName = "Miladinovic",
  100.                     Email = "Johan@randomcompany.com",
  101.                     PhoneNumber = "+46899 66 66"
  102.                 },
  103.                 new ContactPerson
  104.                 {
  105.                     FirstName = "Johan",
  106.                     LastName = "Wänström",
  107.                     Email = "Johan@randomcompany.com",
  108.                     PhoneNumber = "+46899 55 55"
  109.                 }
  110.             };
  111.  
  112.             var addresses = new[]
  113.             {
  114.                 new Address {Street = "Besöksvägen", Number = "1A", ZipCode = "111 11"},
  115.                 new Address {Street = "Lagervägen", Number = "1A", ZipCode = "000 00"},
  116.                 new Address {Street = "Leveransvägen", Number = "2B", ZipCode = "111 12"},
  117.                 new Address {Street = "Glimmervägen", Number = "1A", ZipCode = "111 11"},
  118.                 new Address {Street = "Leveransvägen", Number = "1A", ZipCode = "111 11"},
  119.                 new Address {Street = "Stadsvägen", Number = "1C", ZipCode = "112 11"}
  120.             };
  121.  
  122.  
  123.             var warehouse = new Warehouse
  124.             {
  125.                 Name = "Kundbolagets Lager",
  126.                 AmmountOfStorageSpace = 500,
  127.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Viktor"),
  128.                 Email = "lager@kundbolaget.se",
  129.                 PhoneNumber = "+46899 00 00",
  130.                 Address = addresses.First(a => a.Street == "Lagervägen")
  131.             };
  132.  
  133.             var wareHouse2 = new Warehouse
  134.             {
  135.                 Name = "Kundbolagets mindre lager",
  136.                 AmmountOfStorageSpace = 200,
  137.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Willy"),
  138.                 Email = "mindreLager@kundbolaget.se",
  139.                 PhoneNumber = "+46899 00 01",
  140.                 Address = addresses.First(a => a.Street == "Stadsvägen")
  141.             };
  142.  
  143.             var icaGruppen = new Company
  144.             {
  145.                 Address = addresses.First(a => a.Street == "Besöksvägen"),
  146.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Johan"),
  147.                 Country = countries.First(c => c.Name == "Sweden"),
  148.                 DeliveryAddress = addresses.First(a => a.Street == "Besöksvägen"),
  149.                 Email = "icagruppen@ica.com",
  150.                 Name = "IcaGruppen",
  151.                 PhoneNumber = "+56899 22 22"
  152.             };
  153.  
  154.             var icaVarberg = new Company
  155.             {
  156.                 Address = addresses.First(a => a.Street == "Glimmervägen"),
  157.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Willy"),
  158.                 Country = countries.First(c => c.Name == "Sweden"),
  159.                 DeliveryAddress = addresses.First(a => a.Street == "Leveransvägen" && a.Number == "2B"),
  160.                 Email = "icavarberg@ica.com",
  161.                 PhoneNumber = "+46899 11 11",
  162.                 ParentCompany = icaGruppen,
  163.                 Name = "Ica Vårberg"
  164.             };
  165.  
  166.             var coop = new Company
  167.             {
  168.                 Address = addresses.First(a => a.Street == "Besöksvägen"),
  169.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Michel"),
  170.                 Country = countries.First(c => c.Name == "Sweden"),
  171.                 DeliveryAddress = addresses.First(a => a.Street == "Besöksvägen"),
  172.                 Email = "Coop@medmera.com",
  173.                 Name = "Coop",
  174.                 PhoneNumber = "+56899 22 11"
  175.             };
  176.  
  177.             var coopHaggvik = new Company
  178.             {
  179.                 Address = addresses.First(a => a.Street == "Stadsvägen"),
  180.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Robert"),
  181.                 Country = countries.First(c => c.Name == "Sweden"),
  182.                 DeliveryAddress = addresses.First(a => a.Street == "Stadsvägen" && a.Number == "1C"),
  183.                 Email = "Coophaggvik@coop.com",
  184.                 PhoneNumber = "+46899 11 33",
  185.                 ParentCompany = coop,
  186.                 Name = "Coop Häggvik"
  187.             };
  188.             var coopLiljeholmen = new Company
  189.             {
  190.                 Address = addresses.First(a => a.Street == "Besöksvägen"),
  191.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Robert"),
  192.                 Country = countries.First(c => c.Name == "Sweden"),
  193.                 DeliveryAddress = addresses.First(a => a.Street == "Lagervägen" && a.Number == "1A"),
  194.                 Email = "coopliljeholmen@coop.com",
  195.                 PhoneNumber = "+46899 33 33",
  196.                 ParentCompany = coop,
  197.                 Name = "Coop Liljeholmen"
  198.             };
  199.             var icaLiljeholmen = new Company
  200.             {
  201.                 Address = addresses.First(a => a.Street == "Besöksvägen"),
  202.                 ContactPerson = contactPersons.First(cp => cp.FirstName == "Willy"),
  203.                 Country = countries.First(c => c.Name == "Sweden"),
  204.                 DeliveryAddress = addresses.First(a => a.Street == "Lagervägen" && a.Number == "1A"),
  205.                 Email = "icaliljeholmen@ica.com",
  206.                 PhoneNumber = "+46899 11 54",
  207.                 ParentCompany = icaGruppen,
  208.                 Name = "Ica Liljeholmen"
  209.             };
  210.  
  211.             var companies = new[]
  212.             {
  213.                 icaGruppen, icaVarberg, coop, coopLiljeholmen,coopHaggvik, icaLiljeholmen
  214.             };
  215.  
  216.             var productInfoes = new[]
  217.             {
  218.                 new ProductInfo
  219.                 {
  220.                     Name = "Norrlandsguld",
  221.                     Abv = 5.3m,
  222.                     Container = containers.First(c => c.Name == "Burk"),
  223.                     Volume = volumes.First(v => v.Milliliter == 330),
  224.                     Description = "Öl",
  225.                     ProductGroup = productGroups.First(pg => pg.Name == "Lager"),
  226.                     PurchasePrice = 5.3m,
  227.                     TradingMargin = 10,
  228.                     Price = 250,
  229.                     NewPrice = 1337,
  230.                     PriceStart = DateTime.Now.AddMinutes(1)
  231.                 },
  232.                 new ProductInfo
  233.                 {
  234.                     Name = "Norrlandsguld",
  235.                     Abv = 5.3m,
  236.                     Container = containers.First(c => c.Name == "Burk"),
  237.                     Volume = volumes.First(v => v.Milliliter == 500),
  238.                     Description = "Öl",
  239.                     ProductGroup = productGroups.First(pg => pg.Name == "Lager"),
  240.                     PurchasePrice = 8.3m,
  241.                     TradingMargin = 8,
  242.                     Price = 325
  243.                 },
  244.                 new ProductInfo
  245.                 {
  246.                     Name = "Nääs APA",
  247.                     Abv = 5.8m,
  248.                     Container = containers.First(c => c.Name == "Flaska"),
  249.                     Volume = volumes.First(v => v.Milliliter == 330),
  250.                     Description = "APA",
  251.                     ProductGroup = productGroups.First(pg => pg.Name == "APA"),
  252.                     PurchasePrice = 8.3m,
  253.                     TradingMargin = 8,
  254.                     Price = 325
  255.                 },
  256.                 new ProductInfo
  257.                 {
  258.                     Name = "Lagunitas IPA",
  259.                     Abv = 6.2m,
  260.                     Container = containers.First(c => c.Name == "Flaska"),
  261.                     Volume = volumes.First(v => v.Milliliter == 350),
  262.                     Description = "IPA",
  263.                     ProductGroup = productGroups.First(pg => pg.Name == "IPA"),
  264.                     PurchasePrice = 8.3m,
  265.                     TradingMargin = 8,
  266.                     Price = 400
  267.                 },
  268.                 new ProductInfo
  269.                 {
  270.                     Name = "Koskenkorva",
  271.                     Abv = 40,
  272.                     Container = containers.First(c => c.Name == "Flaska"),
  273.                     Volume = volumes.First(v => v.Milliliter == 700),
  274.                     Description = "Vodka",
  275.                     ProductGroup = productGroups.First(pg => pg.Name == "Vodka"),
  276.                     PurchasePrice = 35,
  277.                     TradingMargin = 50,
  278.                     Price = 900
  279.                 },
  280.                 new ProductInfo
  281.                 {
  282.                     Name = "Absolut Vodka",
  283.                     Abv = 40,
  284.                     Container = containers.First(c => c.Name == "Flaska"),
  285.                     Volume = volumes.First(v => v.Milliliter == 700),
  286.                     Description = "Vodka",
  287.                     ProductGroup = productGroups.First(pg => pg.Name == "Vodka"),
  288.                     PurchasePrice = 35,
  289.                     TradingMargin = 50,
  290.                     Price = 1200
  291.                 },
  292.                 new ProductInfo
  293.                 {
  294.                     Name = "Smirnoff Vodka",
  295.                     Abv = 40,
  296.                     Container = containers.First(c => c.Name == "Flaska"),
  297.                     Volume = volumes.First(v => v.Milliliter == 700),
  298.                     Description = "Vodka",
  299.                     ProductGroup = productGroups.First(pg => pg.Name == "Vodka"),
  300.                     PurchasePrice = 35,
  301.                     TradingMargin = 50,
  302.                     Price = 1250
  303.                 },
  304.                 new ProductInfo
  305.                 {
  306.                     Name = " Dreissigacker",
  307.                     Abv = 12,
  308.                     Container = containers.First(c => c.Name == "Flaska"),
  309.                     Volume = volumes.First(v => v.Milliliter == 700),
  310.                     Description = "Riesling",
  311.                     ProductGroup = productGroups.First(pg => pg.Name == "Vitt vin"),
  312.                     PurchasePrice = 35,
  313.                     TradingMargin = 50,
  314.                     Price = 1250
  315.                 },
  316.                 new ProductInfo
  317.                 {
  318.                     Name = " Vino Nobile di Montepulciano",
  319.                     Abv = 13.5m,
  320.                     Container = containers.First(c => c.Name == "Flaska"),
  321.                     Volume = volumes.First(v => v.Milliliter == 700),
  322.                     Description = "Sangiovese",
  323.                     ProductGroup = productGroups.First(pg => pg.Name == "Rött vin"),
  324.                     PurchasePrice = 35,
  325.                     TradingMargin = 50,
  326.                     Price = 1250
  327.                 },
  328.             };
  329.  
  330.             var stock = new[]
  331.             {
  332.                 new ProductStock
  333.                 {
  334.                     Amount = 500,
  335.                     ProductInfo = productInfoes.First(pi => pi.Name == "Norrlandsguld"),
  336.                     Warehouse = warehouse
  337.                 },
  338.                 new ProductStock
  339.                 {
  340.                     Amount = 200,
  341.                     ProductInfo = productInfoes.First(pi => pi.Name == "Koskenkorva"),
  342.                     Warehouse = warehouse
  343.                 }
  344.             };
  345.  
  346.             var dummyOrder = new Order
  347.             {
  348.                 Company = companies.First(c => c.Name == "Ica Vårberg"),
  349.                 CreatedDate = DateTime.Now,
  350.                 WishedDeliveryDate = DateTime.Parse("2016-12-12"),
  351.             };
  352.  
  353.             var orderDetails = new[]
  354.             {
  355.                 new OrderDetails
  356.                 {
  357.                     ProductInfo = productInfoes.First(pi => pi.Name == "Koskenkorva"),
  358.                     Amount = 10,
  359.                     Order = dummyOrder,
  360.                     UnitPrice = productInfoes.First(pi => pi.Name == "Koskenkorva").Price,
  361.                     TotalPrice = productInfoes.First(pi => pi.Name == "Koskenkorva").Price*10
  362.                 },
  363.                 new OrderDetails
  364.                 {
  365.                     ProductInfo = productInfoes.First(pi => pi.Name == "Norrlandsguld"),
  366.                     Amount = 25,
  367.                     UnitPrice = productInfoes.First(pi => pi.Name == "Norrlandsguld").Price,
  368.                     TotalPrice = productInfoes.First(pi => pi.Name == "Norrlandsguld").Price*25,
  369.                     Order = dummyOrder
  370.                 }
  371.             };
  372.             dummyOrder.Price += orderDetails.Sum(p => p.ProductInfo.Price*p.Amount);
  373.  
  374.  
  375.             context.Countries.AddOrUpdate(countries);
  376.             context.ContactPersons.AddOrUpdate(contactPersons);
  377.             context.Categories.AddOrUpdate(categories);
  378.             context.ProductGroups.AddOrUpdate(productGroups);
  379.             context.Containers.AddOrUpdate(containers);
  380.             context.Warehouses.AddOrUpdate(warehouse, wareHouse2);
  381.             context.Companies.AddOrUpdate(companies);
  382.             context.ProductsInfoes.AddOrUpdate(productInfoes);
  383.             context.ProductStocks.AddOrUpdate(stock);
  384.             context.Addresses.AddOrUpdate(addresses);
  385.             context.OrderDetails.AddOrUpdate(orderDetails);
  386.             context.Volumes.AddOrUpdate(volumes);
  387.             context.SaveChanges();
  388.         }
  389.     }
  390. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement