示例#1
0
        public void Seed()
        {
            if (_context.Department.Any() || _context.Seller.Any() || _context.SalesRecord.Any())
            {
                return;
            }

            Department d1 = new Department(1, "Computers");
            Department d2 = new Department(2, "Cellphones");
            Department d3 = new Department(3, "Eletronics");


            Seller s1 = new Seller(1, "Bob", "*****@*****.**", new DateTime(1998, 4, 12), 1000.60, d1);
            Seller s2 = new Seller(2, "Kingsman", "*****@*****.**", new DateTime(1995, 4, 11), 3000.60, d1);
            Seller s3 = new Seller(3, "Lucy", "*****@*****.**", new DateTime(1994, 4, 10), 6000.60, d1);

            SalesRecord sr1 = new SalesRecord(1, new DateTime(2018, 9, 25), 11000, SaleStatus.Billed, s1);
            SalesRecord sr2 = new SalesRecord(2, new DateTime(2020, 8, 25), 5000, SaleStatus.Billed, s2);

            _context.Department.AddRange(d1, d2, d3);
            _context.Seller.AddRange(s1, s2, s3);
            _context.SalesRecord.AddRange(sr1, sr2);

            _context.SaveChanges();
        }
示例#2
0
 internal static void Initialize(WebAppContext context)
 {
     context.Database.EnsureCreated();
     if (context.DbConfig.Any())
     {
         return;
     }
     else
     {
         context.DbConfig.Add(new DbConfig {
             ServerIP = "192.168.3.31"
         });
         context.SaveChanges();
     }
 }
        public void AddOrUpdateEvent(Event anEvent)
        {
            if (anEvent.EventID == default(int))
            {
                _dbc.Entry(anEvent).State = EntityState.Added;
            }
            else
            {
                _dbc.Entry(anEvent).State = EntityState.Modified;
            }

            _dbc.SaveChanges();
        }
示例#4
0
        private static void SeedUsers(WebAppContext context)
        {
            if (context.Users.Any())
            {
                return;
            }
            var fishers = new Fisher[]
            {
                new Fisher()
                {
                    Username = "******", Password = "******", Email = "*****@*****.**", Gender = 'M', SexPref = 'F', PicRef = "rasr2", Age = 12, IsActive = true
                },
            };

            foreach (Fisher fisher in fishers)
            {
                context.Add(fisher);
            }
            context.SaveChanges();
        }
示例#5
0
文件: SeedData.cs 项目: mmizab/WebApp
        public static void Populate(WebAppContext context)
        {
            if (context.User.Any())
            {
                return;   // DB has been seeded
            }

            List <User> users = new List <User>();

            users.Add(new User {
                Email = "admin", Password = "******", Role = "admin", Name = "admin"
            });
            users.Add(new User {
                Email = "test", Password = "******", Role = "client", Name = "test"
            });

            context.AddRange(users);
            context.SaveChanges();

            // load test user to create test store
            Store store = null;
            User  test  = users.FirstOrDefault(o => o.Email == "admin");

            if (test != null && test.Id != 0)
            {
                store = new Store {
                    Name = "test store", User = test
                };
                context.Add(store);
                context.SaveChanges();
            }


            List <Category> category = new List <Category>
            {
                new Category {
                    Name = "Alimentació"
                },
                new Category {
                    Name = "Llar"
                },
                new Category {
                    Name = "Floristeria"
                },
                new Category {
                    Name = "Cine"
                },
                new Category {
                    Name = "Informàtica"
                },
                new Category {
                    Name = "Immobiliaria"
                },
                new Category {
                    Name = "Electrodomestic"
                },
                new Category {
                    Name = "Tenda de regals"
                },
                new Category {
                    Name = "Joieria"
                },
                new Category {
                    Name = "Panaderia"
                },
                new Category {
                    Name = "Llibreria"
                },
                new Category {
                    Name = "Roba"
                },
                new Category {
                    Name = "Gelateria"
                },
                new Category {
                    Name = "Adm de loteria"
                },
                new Category {
                    Name = "Estancs"
                },
                new Category {
                    Name = "Farmàcia"
                },
                new Category {
                    Name = "test"
                }
            };

            context.AddRange(category);
            context.SaveChanges();
        }
示例#6
0
 public bool SaveChanges()
 {
     return(_context.SaveChanges() >= 0);
 }
示例#7
0
        // Lisa 3 üritust ja kõigile üritustele lisa 3 osalejat.
        //
        // 1. Aenan Commodo:
        //   Mati Nurk
        //   Supersam OÜ
        //   Uku OÜ
        //
        // 2. Nunc lobortis
        // Lelle Mari
        // Mullam OÜ
        // Supersale OÜ
        //
        // 3. Integer nec null viate
        //  Tubli Malle
        //  Vegman klubi
        //  Supersale OÜ

        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new WebAppContext(
                       serviceProvider.GetRequiredService <DbContextOptions <WebAppContext> >()))
            {
                // look for any events
                if (context.Events.Any())
                {
                    return;
                }

                var events = new Event[]
                {
                    new Event
                    {
                        EventName        = "Integer nec nulla vitae",
                        EventStartDate   = new DateTime(2019, 6, 14),
                        EventLocation    = "Regione equidem usu",
                        EventInformation = "Ad sit regione malorum, vel mucius eloquentiam an. Vix utinam animal appareat at. Cum eros mazim tibique et, intellegam assueverit duo no, mei ne velit incorrupte. Eum noster verear eu, ius diceret accommodare ea. Sed accusam nominavi id.",
                    },
                    new Event
                    {
                        EventName        = "Aenean commodo",
                        EventStartDate   = new DateTime(2018, 3, 18),
                        EventLocation    = "Animal equidem usu",
                        EventInformation = "Ad sit regione malorum, vel mucius eloquentiam an. Vix utinam animal appareat at. Cum eros mazim tibique et, intellegam assueverit duo no, mei ne velit incorrupte. Eum noster verear eu, ius diceret accommodare ea. Sed accusam nominavi id.",
                    },
                    new Event
                    {
                        EventName        = "Nunc lobortis metus eu massa viverra ultri iplacerat nibh",
                        EventStartDate   = new DateTime(2016, 3, 3),
                        EventLocation    = "Regione equidem usu",
                        EventInformation = "Ad sit regione malorum, vel mucius eloquentiam an. Vix utinam animal appareat at. Cum eros mazim tibique et, intellegam assueverit duo no, mei ne velit incorrupte. Eum noster verear eu, ius diceret accommodare ea. Sed accusam nominavi id.",
                    },
                };



                var people = new Person[]
                {
                    new Person {
                        FirstName = "Mati", LastName = "Nurk", PersonalCode = Convert.ToInt32(3345432), PersonPaymentMethod = PaymentMethod.CreditCard, PersonRequests = "Exerci graeco necessitatibus te has, debet copiosae qualisque in vix, docendi nominavi pro ei. Id dictas euismod detraxit est, doming labore meliore per id. Ex meis audire ius, in quot."
                    },
                    new Person {
                        FirstName = "Lelle", LastName = "Mari", PersonalCode = Convert.ToInt32(275443), PersonPaymentMethod = PaymentMethod.Cash, PersonRequests = "Corpora probatus consequat in pro, mea tantas quodsi mollis ut. Ponderum intellegebat voluptatibus"
                    },
                    new Person {
                        FirstName = "Tubli", LastName = "Kalle", PersonalCode = Convert.ToInt32(3875434), PersonPaymentMethod = PaymentMethod.CreditCard, PersonRequests = "Corpora probatus consequat in pro, mea tantas quodsi mollis ut. Ponderum intellegebat voluptatibus"
                    }
                };



                var companies = new Company[]
                {
                    new Company {
                        CompanyName = "Supersam OÜ", NumberOfParticipants = 5, CompanyPaymentMehtod = PaymentMethod.CreditCard, CompanyRegistrationNr = Convert.ToInt32(335432), CompanyRequests = "Loren Ipsur Lorem Ipur Lorem Ipsur"
                    },
                    new Company {
                        CompanyName = "Uku OÜ", NumberOfParticipants = 8, CompanyPaymentMehtod = PaymentMethod.CreditCard, CompanyRegistrationNr = Convert.ToInt32(334432), CompanyRequests = "Loren Ipsur Lorem Ipur Lorem Ipsur"
                    },
                    new Company {
                        CompanyName = "Nullam OÜ", NumberOfParticipants = 5, CompanyPaymentMehtod = PaymentMethod.CreditCard, CompanyRegistrationNr = Convert.ToInt32(35432), CompanyRequests = "Loren Ipsur Lorem Ipur Lorem Ipsur"
                    },
                    new Company {
                        CompanyName = "Supersale OÜ", NumberOfParticipants = 5, CompanyPaymentMehtod = PaymentMethod.CreditCard, CompanyRegistrationNr = Convert.ToInt32(3432432), CompanyRequests = "Loren Ipsur Lorem Ipur Lorem Ipsur"
                    },
                    new Company {
                        CompanyName = "Vegman klubi", NumberOfParticipants = 2, CompanyPaymentMehtod = PaymentMethod.CreditCard, CompanyRegistrationNr = Convert.ToInt32(3134432), CompanyRequests = "Loren Ipsur Lorem Ipur Lorem Ipsur"
                    },
                    new Company {
                        CompanyName = "DoubleCash AS", NumberOfParticipants = 6, CompanyPaymentMehtod = PaymentMethod.CreditCard, CompanyRegistrationNr = Convert.ToInt32(3321432), CompanyRequests = "Loren Ipsur Lorem Ipur Lorem Ipsur"
                    }
                };



                var participants = new Participant[]
                {
                    new Participant {
                        EventId = 1, PersonId = 1, CompanyId = null, Type = ParticipantType.Person
                    },
                    new Participant {
                        EventId = 1, PersonId = null, CompanyId = 1, Type = ParticipantType.Company
                    },
                    new Participant {
                        EventId = 1, PersonId = null, CompanyId = 2, Type = ParticipantType.Company
                    },
                    new Participant {
                        EventId = 2, PersonId = 2, CompanyId = null, Type = ParticipantType.Person
                    },
                    new Participant {
                        EventId = 2, PersonId = null, CompanyId = 3, Type = ParticipantType.Company
                    },
                    new Participant {
                        EventId = 2, PersonId = null, CompanyId = 4, Type = ParticipantType.Company
                    },
                    new Participant {
                        EventId = 3, PersonId = 3, CompanyId = null, Type = ParticipantType.Person
                    },
                    new Participant {
                        EventId = 3, PersonId = null, CompanyId = 5, Type = ParticipantType.Company
                    },
                    new Participant {
                        EventId = 3, PersonId = null, CompanyId = 6, Type = ParticipantType.Company
                    }
                };



                foreach (Event e in events)
                {
                    context.Events.Add(e);
                }

                context.SaveChanges();

                foreach (Person p in people)
                {
                    context.People.Add(p);
                }

                context.SaveChanges();

                foreach (Participant p in participants)
                {
                    context.Participants.Add(p);
                }
                //context.SaveChanges();

                foreach (Company c in companies)
                {
                    context.Companies.Add(c);
                }

                context.SaveChanges();
            }
        }