Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.59 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using WebApplication4.Models;
  4.  
  5. namespace WebApplication4
  6. {
  7.     internal static class Program
  8.     {
  9.         private static void Main(string[] args)
  10.         {
  11.            
  12.             using var context = new ApplicationContext();
  13.             if (!context.Products.Any())
  14.             {
  15.                 context.Products.AddRange(
  16.  
  17.                     new Product
  18.                     {
  19.                         Id = 0,
  20.                         Category = "T-shirt",
  21.                         Brand = "Emporio Armani",
  22.                         Collection = "Summer 2019",
  23.                         ProductColor = "purple",
  24.                         Amount = 10
  25.  
  26.                     },
  27.  
  28.                     new Product
  29.                     {
  30.                         Id = 1,
  31.                         Category = "Jacket",
  32.                         Brand = "Tommy Hilfiger",
  33.                         Collection = "Spring 2018",
  34.                         ProductColor = "black",
  35.                         Amount = 5
  36.                     },
  37.  
  38.                     new Product
  39.                     {
  40.                         Id = 2,
  41.                         Category = "Pants",
  42.                         Brand = "Hugo Boss",
  43.                         Collection = "Hugo Boss pants 2019",
  44.                         ProductColor = "black",
  45.                         Amount = 5
  46.                     },
  47.  
  48.                     new Product
  49.                     {
  50.                         Id = 3,
  51.                         Category = "Shoes",
  52.                         Brand = "Nike",
  53.                         Collection = "Airforce 1 2017",
  54.                         ProductColor = "black",
  55.                         Amount = 1
  56.                     }
  57.                 );
  58.  
  59.             context.Brands.AddRange(
  60.  
  61.                     new Brand
  62.                     {
  63.                         BrandId = 3,
  64.                         BrandName = "Emporio Armani"
  65.                     },
  66.  
  67.                     new Brand
  68.                     {
  69.                         BrandId = 2,
  70.                         BrandName = "Tommy Hilfiger"
  71.                     },
  72.  
  73.                     new Brand
  74.                     {
  75.                         BrandId = 1,
  76.                         BrandName = "Hugo Boss"
  77.                     },
  78.  
  79.                     new Brand
  80.                     {
  81.                         BrandId = 0,
  82.                         BrandName = "Nike"
  83.                     }
  84.                     );
  85.            
  86.             context.Categories.AddRange(
  87.  
  88.                     new Category
  89.                     {
  90.                         CategoryId = 0,
  91.                         CategoryName = "T-shirt"
  92.  
  93.                     },
  94.  
  95.                     new Category
  96.                     {
  97.                         CategoryId = 1,
  98.                         CategoryName = "Jacket"
  99.                     },
  100.  
  101.                     new Category
  102.                     {
  103.                         CategoryId = 2,
  104.                         CategoryName = "Pants"
  105.                     },
  106.  
  107.                     new Category
  108.                     {
  109.                         CategoryId = 3,
  110.                         CategoryName = "Shoes"
  111.                     }
  112.                     );
  113.  
  114.                 context.Collections.AddRange(
  115.  
  116.                     new Collection
  117.                     {
  118.                         CollectionId = 0,
  119.                         CollectionName = "Summer 2019"
  120.                     },
  121.  
  122.                     new Collection
  123.                     {
  124.                         CollectionId = 1,
  125.                         CollectionName = "Spring 2018"
  126.                     },
  127.  
  128.                     new Collection
  129.                     {
  130.                         CollectionId = 2,
  131.                         CollectionName = "Hugo Boss pants 2019"
  132.                     },
  133.  
  134.                     new Collection
  135.                     {
  136.                         CollectionId = 3,
  137.                         CollectionName = "Airforce 1 2017"
  138.                     }
  139.                     );
  140.  
  141.                 //context.SaveChanges();
  142.             }
  143.  
  144.             context.SaveChanges();
  145.             /*var pr1 = new Product
  146.  
  147.  
  148.                 // получаем объекты из бд и выводим на консоль
  149.             /*var users = db.Products.ToList();
  150.                 Console.WriteLine("Users list:");
  151.                 foreach (Product u in users)
  152.                 {
  153.                     Console.WriteLine($"{u.Id} {u.Category} {u.Brand} {u.Collection} {u.ProductColor} {u.Amount}");
  154.                 }
  155.                 */
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement