private static DbContext InitializeDatabase()
        {
            var context = new AuctionPortalDbContext();

            context.Products.RemoveRange(context.Products);
            context.Categories.RemoveRange(context.Categories);
            context.SaveChanges();

            var vehicles = new Category
            {
                Id       = Guid.Parse("aa01dc64-5c07-40fe-a916-175165b9b90f"),
                Name     = "Vehicles",
                Parent   = null,
                ParentId = null
            };

            var skoda = new Category
            {
                Id       = Guid.Parse("aa02dc64-5c07-40fe-a916-175165b9b90f"),
                Name     = "Skoda",
                Parent   = vehicles,
                ParentId = vehicles.Id
            };

            var audi = new Category
            {
                Id       = Guid.Parse("aa04dc64-5c07-40fe-a916-175165b9b90f"),
                Name     = "Audi",
                Parent   = vehicles,
                ParentId = vehicles.Id
            };

            context.Categories.AddOrUpdate(category => category.Id, vehicles, skoda, audi);


            var kodiaqAuction = new Auction
            {
                Id          = Guid.Parse("aa05dc64-5c07-40fe-a916-175165b9b90f"),
                Category    = skoda,
                CategoryId  = skoda.Id,
                Description = "The ŠKODA KODIAQ, a large 4.70 metre long SUV boasting up to seven seats and one of the largest luggage compartments in its class, provides oodles of space even for the most demanding families.",
                Name        = "Skoda Kodiaq Auction",
                ActualPrice = 800_000,
                ClosingTime = new DateTime(2020, 1, 1),
                IsOpened    = true,
            };

            var a6Auction = new Auction
            {
                Id          = Guid.Parse("aa06dc64-5c07-40fe-a916-175165b9b90f"),
                Category    = audi,
                CategoryId  = audi.Id,
                Description = "The Audi A6 is an executive car made by the German automaker Audi, now in its fifth generation. ... All generations of the A6 have offered either front-wheel drive or Torsen-based four-wheel drive, marketed by Audi as their quattro system.",
                Name        = "Audi A6 Auction",
                ActualPrice = 1_200_000,
                ClosingTime = new DateTime(2020, 2, 1),
                IsOpened    = true,
            };

            context.Auctions.AddOrUpdate(kodiaqAuction);
            context.Auctions.AddOrUpdate(a6Auction);

            context.SaveChanges();

            return(context);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            using (var context = new AuctionPortalDbContext())
            {
                List <Account> accs = new List <Account>(context.Accounts);
                List <AccountAuctionRelation> relations = new List <AccountAuctionRelation>(context.AccountAuctionRelations);
                foreach (var VARIABLE in relations)
                {
                    Console.WriteLine(VARIABLE.Id + ";" + VARIABLE.AccountId.ToString() + "; " + VARIABLE.AuctionId);
                }
                foreach (var VARIABLE in accs)
                {
                    Console.WriteLine(VARIABLE.Id + ";" + VARIABLE.IsAdministrator.ToString());
                }

                List <Product> asd = new List <Product>(context.Products);
                foreach (var VARIABLE in asd)
                {
                    Console.WriteLine(VARIABLE.ToString());
                }
                List <Category> cat = new List <Category>(context.Categories);
                foreach (var VARIABLE in cat)
                {
                    Console.WriteLine(VARIABLE.Name);
                }

                Console.ReadKey();

                Category parent = new Category
                {
                    Id       = Guid.Parse("835b8aee-6883-4a4c-9e75-950fc90c3f03"),
                    Name     = "Parent",
                    Parent   = null,
                    ParentId = null
                };

                Category child = new Category
                {
                    Id       = Guid.Parse("d527ffa7-0b6c-48f2-8e42-90c6b18f7b81"),
                    Name     = "NoCategory",
                    Parent   = null,
                    ParentId = null
                };

                Auction auction = new Auction
                {
                    Id          = Guid.Parse("7ad0b015-5651-441c-9879-44b322d03986"),
                    ActualPrice = 100,
                    Category    = child,
                    CategoryId  = child.Id,
                    ClosingTime = new DateTime(2020, 1, 1),
                    Description = "asd0",
                    IsOpened    = true,
                    Name        = "MyAuction"
                };

                Product product = new Product
                {
                    Id            = Guid.Parse("0cf65f4d-a568-481d-b73f-fdc026a75cce"),
                    Auction       = auction,
                    AuctionId     = auction.Id,
                    Name          = "MyProduct",
                    ProductImgUrl = "asdsd"
                };

                Account acctoun = new Account
                {
                    Address           = "asd",
                    BirthDate         = DateTime.Today,
                    Email             = "asd@asd",
                    FirstName         = "admin",
                    LastName          = "admin",
                    Id                = new Guid("0cf65f4d-a568-481d-b73f-fdc026a75cce"),
                    IsAdministrator   = true,
                    MobilePhoneNumber = "123",
                    Password          = "******"
                };

                //context.Categories.Add(parent);
                //context.Categories.Add(child);
                //context.Auctions.Add(auction);
                //context.Products.Add(product);
                //context.Accounts.Add(acctoun);
                //context.SaveChanges();
            }
            Console.ReadKey();
        }