示例#1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var activity = await _context.Activities.FindAsync(request.Id);

                if (activity == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, new { activity = "NotFound" });
                }

                activity.Title       = request.Title ?? activity.Title;
                activity.Description = request.Description ?? activity.Description;
                activity.Category    = request.Category ?? activity.Category;
                activity.Date        = request.Date ?? activity.Date;
                activity.City        = request.City ?? activity.City;
                activity.Venue       = request.Venue ?? activity.Venue;

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem Saving Changes");
            }
示例#2
0
        public static async Task SeedData(DataContext context)
        {
            if (context.Activities.Any( ))
            {
                return;
            }

            var activities = new List <Activity>
            {
                new Activity
                {
                    Title       = "Past Activity 1",
                    Date        = DateTime.Now.AddMonths(-2),
                    Description = "Activity 2 months ago",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Pub",
                },
                new Activity
                {
                    Title       = "Past Activity 2",
                    Date        = DateTime.Now.AddMonths(-1),
                    Description = "Activity 1 month ago",
                    Category    = "culture",
                    City        = "Paris",
                    Venue       = "Louvre",
                },
                new Activity
                {
                    Title       = "Future Activity 1",
                    Date        = DateTime.Now.AddMonths(1),
                    Description = "Activity 1 month in future",
                    Category    = "culture",
                    City        = "London",
                    Venue       = "Natural History Museum",
                },
                new Activity
                {
                    Title       = "Future Activity 2",
                    Date        = DateTime.Now.AddMonths(2),
                    Description = "Activity 2 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "O2 Arena",
                },
                new Activity
                {
                    Title       = "Future Activity 3",
                    Date        = DateTime.Now.AddMonths(3),
                    Description = "Activity 3 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 4",
                    Date        = DateTime.Now.AddMonths(4),
                    Description = "Activity 4 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Yet another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 5",
                    Date        = DateTime.Now.AddMonths(5),
                    Description = "Activity 5 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Just another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 6",
                    Date        = DateTime.Now.AddMonths(6),
                    Description = "Activity 6 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "Roundhouse Camden",
                },
                new Activity
                {
                    Title       = "Future Activity 7",
                    Date        = DateTime.Now.AddMonths(7),
                    Description = "Activity 2 months ago",
                    Category    = "travel",
                    City        = "London",
                    Venue       = "Somewhere on the Thames",
                },
                new Activity
                {
                    Title       = "Future Activity 8",
                    Date        = DateTime.Now.AddMonths(8),
                    Description = "Activity 8 months in future",
                    Category    = "film",
                    City        = "London",
                    Venue       = "Cinema",
                }
            };

            await context.Activities.AddRangeAsync(activities);

            await context.SaveChangesAsync( );
        }
示例#3
0
        public static async Task SeedData(DataContext context)
        {
            //if there are any activities in our database then return
            if (context.Activities.Any())
            {
                return;
            }

            //otherwise generate seed data
            var activities = new List <Activity>
            {
                new Activity
                {
                    Title       = "Past Activity 1",
                    Date        = DateTime.Now.AddMonths(-2),
                    Description = "Activity 2 months ago",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Pub",
                },
                new Activity
                {
                    Title       = "Past Activity 2",
                    Date        = DateTime.Now.AddMonths(-1),
                    Description = "Activity 1 month ago",
                    Category    = "culture",
                    City        = "Paris",
                    Venue       = "Louvre",
                },
                new Activity
                {
                    Title       = "Future Activity 1",
                    Date        = DateTime.Now.AddMonths(1),
                    Description = "Activity 1 month in future",
                    Category    = "culture",
                    City        = "London",
                    Venue       = "Natural History Museum",
                },
                new Activity
                {
                    Title       = "Future Activity 2",
                    Date        = DateTime.Now.AddMonths(2),
                    Description = "Activity 2 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "O2 Arena",
                },
                new Activity
                {
                    Title       = "Future Activity 3",
                    Date        = DateTime.Now.AddMonths(3),
                    Description = "Activity 3 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 4",
                    Date        = DateTime.Now.AddMonths(4),
                    Description = "Activity 4 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Yet another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 5",
                    Date        = DateTime.Now.AddMonths(5),
                    Description = "Activity 5 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Just another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 6",
                    Date        = DateTime.Now.AddMonths(6),
                    Description = "Activity 6 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "Roundhouse Camden",
                },
                new Activity
                {
                    Title       = "Future Activity 7",
                    Date        = DateTime.Now.AddMonths(7),
                    Description = "Activity 2 months ago",
                    Category    = "travel",
                    City        = "London",
                    Venue       = "Somewhere on the Thames",
                },
                new Activity
                {
                    Title       = "Future Activity 8",
                    Date        = DateTime.Now.AddMonths(8),
                    Description = "Activity 8 months in future",
                    Category    = "film",
                    City        = "London",
                    Venue       = "Cinema",
                },
                new Activity
                {
                    Title       = "Future Activity 9",
                    Date        = DateTime.Now.AddMonths(9),
                    Description = "Activity 9 months in future",
                    Category    = "Programming",
                    City        = "Tampa",
                    Venue       = "Amelie Arena",
                }
            };

            //add the data to the database and save
            await context.Activities.AddRangeAsync(activities);

            await context.SaveChangesAsync();
        }
示例#4
0
        public static async Task SeedData(DataContext context)
        {
            /*if Activities tables contains data - exit and don't run
             * any more code below - guard clause to check against empty
             * table*/
            if (context.Activities.Any())
            {
                return;
            }

            var activities = new List <Activity>
            {
                new Activity
                {
                    Title       = "Past Activity 1",
                    Date        = DateTime.Now.AddMonths(-2),
                    Description = "Activity 2 months ago",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Pub",
                },
                new Activity
                {
                    Title       = "Past Activity 2",
                    Date        = DateTime.Now.AddMonths(-1),
                    Description = "Activity 1 month ago",
                    Category    = "culture",
                    City        = "Paris",
                    Venue       = "Louvre",
                },
                new Activity
                {
                    Title       = "Future Activity 1",
                    Date        = DateTime.Now.AddMonths(1),
                    Description = "Activity 1 month in future",
                    Category    = "culture",
                    City        = "London",
                    Venue       = "Natural History Museum",
                },
                new Activity
                {
                    Title       = "Future Activity 2",
                    Date        = DateTime.Now.AddMonths(2),
                    Description = "Activity 2 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "O2 Arena",
                },
                new Activity
                {
                    Title       = "Future Activity 3",
                    Date        = DateTime.Now.AddMonths(3),
                    Description = "Activity 3 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 4",
                    Date        = DateTime.Now.AddMonths(4),
                    Description = "Activity 4 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Yet another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 5",
                    Date        = DateTime.Now.AddMonths(5),
                    Description = "Activity 5 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Just another pub",
                },
                new Activity
                {
                    Title       = "Future Activity 6",
                    Date        = DateTime.Now.AddMonths(6),
                    Description = "Activity 6 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "Roundhouse Camden",
                },
                new Activity
                {
                    Title       = "Future Activity 7",
                    Date        = DateTime.Now.AddMonths(7),
                    Description = "Activity 2 months ago",
                    Category    = "travel",
                    City        = "London",
                    Venue       = "Somewhere on the Thames",
                },
                new Activity
                {
                    Title       = "Future Activity 8",
                    Date        = DateTime.Now.AddMonths(8),
                    Description = "Activity 8 months in future",
                    Category    = "film",
                    City        = "London",
                    Venue       = "Cinema",
                }
            };

            //Add to the database
            await context.Activities.AddRangeAsync(activities);

            //Save when complete - separate function - single responsibility
            //As per S in SOLID
            await context.SaveChangesAsync();
        }
示例#5
0
        public static async Task SeedData(DataContext context, UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <AppUser>
                {
                    new AppUser
                    {
                        Id       = "a",
                        Name     = "Bob",
                        UserName = "******",
                        Email    = "*****@*****.**"
                    },
                    new AppUser
                    {
                        Id       = "b",
                        Name     = "Jane",
                        UserName = "******",
                        Email    = "*****@*****.**"
                    },
                    new AppUser
                    {
                        Id       = "c",
                        Name     = "Tom",
                        UserName = "******",
                        Email    = "*****@*****.**"
                    },
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }

            if (!context.Items.Any())
            {
                var items = new List <Item>
                {
                    new Item
                    {
                        Name        = "Earth",
                        Description = "Planet1",
                        Possession  = "Bob",
                        Bids        = new List <Bid>
                        {
                            new Bid
                            {
                                AppUserId = "a",
                                Price     = 200,
                                Timestamp = DateTime.Now
                            }
                        }
                    },
                    new Item
                    {
                        Name        = "Pluto",
                        Description = "Planet2",
                        Possession  = "Bill",
                        Bids        = new List <Bid>
                        {
                            new Bid
                            {
                                AppUserId = "a",
                                Price     = 200,
                                Timestamp = DateTime.Now
                            },
                            new Bid
                            {
                                AppUserId = "c",
                                Price     = 200,
                                Timestamp = DateTime.Now
                            }
                        }
                    },
                };

                await context.Items.AddRangeAsync(items);

                await context.SaveChangesAsync();
            }
        }
示例#6
0
        public static async Task SeedData(DataContext context, UserManager <AppUser> userManager, RoleManager <AppRole> roleManager)
        {
            if (!await userManager.Users.AnyAsync() && !await context.Activities.AnyAsync())
            {
                var roles = new List <AppRole>
                {
                    new() { Name = RoleNames.ROLE_ADMIN },
                    new() { Name = RoleNames.ROLE_MEMBER },
                    new() { Name = RoleNames.ROLE_MODERATOR }
                };

                foreach (var role in roles)
                {
                    await roleManager.CreateAsync(role);
                }

                var users = new List <AppUser>
                {
                    new() { DisplayName = "Bob", UserName = "******", Email = "*****@*****.**" },
                    new() { DisplayName = "Tom", UserName = "******", Email = "*****@*****.**" },
                    new() { DisplayName = "Jane", UserName = "******", Email = "*****@*****.**" }
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");

                    await userManager.AddToRoleAsync(user, RoleNames.ROLE_MEMBER);
                }

                var admin = new AppUser {
                    DisplayName = "AdminDaro", UserName = "******", Email = "*****@*****.**"
                };

                await userManager.CreateAsync(admin, "Pa$$w0rd");

                await userManager.AddToRoleAsync(admin, RoleNames.ROLE_ADMIN);

                var activities = new List <Activity>
                {
                    new()
                    {
                        Title       = "Past Activity 1",
                        Date        = DateTime.Now.AddMonths(-2),
                        Description = "Activity 2 months ago",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Pub",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[0], IsHost = true }
                        }
                    },
                    new()
                    {
                        Title       = "Past Activity 2",
                        Date        = DateTime.Now.AddMonths(-1),
                        Description = "Activity 1 month ago",
                        Category    = "culture",
                        City        = "Paris",
                        Venue       = "The Louvre",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[0], IsHost = true },
                            new() { AppUser = users[1], IsHost = false }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 1",
                        Date        = DateTime.Now.AddMonths(1),
                        Description = "Activity 1 month in future",
                        Category    = "music",
                        City        = "London",
                        Venue       = "Wembly Stadium",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[2], IsHost = true },
                            new() { AppUser = users[1], IsHost = false }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 2",
                        Date        = DateTime.Now.AddMonths(2),
                        Description = "Activity 2 months in future",
                        Category    = "food",
                        City        = "London",
                        Venue       = "Jamies Italian",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[0], IsHost = true },
                            new() { AppUser = users[2], IsHost = false }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 3",
                        Date        = DateTime.Now.AddMonths(3),
                        Description = "Activity 3 months in future",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Pub",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[1], IsHost = true },
                            new() { AppUser = users[0], IsHost = false }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 4",
                        Date        = DateTime.Now.AddMonths(4),
                        Description = "Activity 4 months in future",
                        Category    = "culture",
                        City        = "London",
                        Venue       = "British Museum",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[1], IsHost = true }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 5",
                        Date        = DateTime.Now.AddMonths(5),
                        Description = "Activity 5 months in future",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Punch and Judy",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[0], IsHost = true },
                            new() { AppUser = users[1], IsHost = false }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 6",
                        Date        = DateTime.Now.AddMonths(6),
                        Description = "Activity 6 months in future",
                        Category    = "music",
                        City        = "London",
                        Venue       = "O2 Arena",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[2], IsHost = true },
                            new() { AppUser = users[1], IsHost = false }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 7",
                        Date        = DateTime.Now.AddMonths(7),
                        Description = "Activity 7 months in future",
                        Category    = "travel",
                        City        = "Berlin",
                        Venue       = "All",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[0], IsHost = true },
                            new() { AppUser = users[2], IsHost = false }
                        }
                    },
                    new()
                    {
                        Title       = "Future Activity 8",
                        Date        = DateTime.Now.AddMonths(8),
                        Description = "Activity 8 months in future",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Pub",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new() { AppUser = users[2], IsHost = true },
                            new() { AppUser = users[1], IsHost = false }
                        }
                    }
                };

                await context.Activities.AddRangeAsync(activities);

                await context.SaveChangesAsync();
            }
        }
    }
}
示例#7
0
        public static async Task SeedActivities(DataContext context, UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <AppUser> {
                    new AppUser {
                        DisplayName = "Edwin",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser {
                        DisplayName = "jane",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser {
                        DisplayName = "kim",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                };

                foreach (var user in users)
                {
                    // this create the users and adds them to the store
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }

            if (!context.Activities.Any())
            {
                var activities = new List <Activity> {
                    new Activity {
                        Title       = "Future activity 1",
                        Date        = DateTime.Now.AddMonths(5),
                        Description = "Activity Number 1",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    },
                    new Activity {
                        Title       = "Future activity 2",
                        Date        = DateTime.Now.AddMonths(2),
                        Description = "Activity Number 2",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Freedom hall"
                    }, new Activity {
                        Title       = "Future activity 3",
                        Date        = DateTime.Now.AddMonths(3),
                        Description = "Activity Number 3",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    }, new Activity {
                        Title       = "Future activity 4",
                        Date        = DateTime.Now.AddMonths(4),
                        Description = "Activity Number 4",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    }, new Activity {
                        Title       = "Future activity 5",
                        Date        = DateTime.Now.AddMonths(5),
                        Description = "Activity Number 5",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    }, new Activity {
                        Title       = "Future activity 6",
                        Date        = DateTime.Now.AddMonths(6),
                        Description = "Activity Number 6",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    }, new Activity {
                        Title       = "Future activity 7",
                        Date        = DateTime.Now.AddMonths(7),
                        Description = "Activity Number 7",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    }, new Activity {
                        Title       = "Future activity 8",
                        Date        = DateTime.Now.AddMonths(8),
                        Description = "Activity Number 8",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    }, new Activity {
                        Title       = "Future activity 9",
                        Date        = DateTime.Now.AddMonths(9),
                        Description = "Activity Number 9",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    }, new Activity {
                        Title       = "Future activity 9",
                        Date        = DateTime.Now.AddMonths(9),
                        Description = "Activity Number 9",
                        Category    = "Drinks",
                        City        = "Nyeri",
                        Venue       = "Just another pub"
                    },
                };
                context.Activities.AddRange(activities);
                await context.SaveChangesAsync();
            }
        }
示例#8
0
        public static async Task SeedData(DataContext context,
                                          UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <AppUser> {
                    new AppUser {
                        Id          = "a",
                        DisplayName = "Bob",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser {
                        Id          = "b",
                        DisplayName = "Jane",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser {
                        Id          = "c",
                        DisplayName = "Tom",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }

            if (!context.Activities.Any())
            {
                var activities = new List <Activity> {
                    new Activity {
                        Title          = "Painting the City",
                        Date           = DateTime.Now.AddMonths(2),
                        Description    = "Learn all about the city through painting activities.",
                        Category       = "artsandcrafts",
                        Venue          = "2915 NE Jarrett St",
                        UserActivities = new List <UserActivity> {
                            new UserActivity {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-2)
                            }
                        }
                    },
                    new Activity {
                        Title          = "Soccer with Friends",
                        Date           = DateTime.Now.AddMonths(-1),
                        Description    = "Learn the principles of soccer and play games.",
                        Category       = "Sports",
                        Venue          = "7251 NE Killingsworth St.",
                        UserActivities = new List <UserActivity> {
                            new UserActivity {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                            new UserActivity {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                        }
                    },
                    new Activity {
                        Title          = "Walk in the Woods",
                        Date           = DateTime.Now.AddMonths(1),
                        Description    = "Go on hikes to learn about nature",
                        Category       = "nature",
                        Venue          = "3333 SE 39th St.",
                        UserActivities = new List <UserActivity> {
                            new UserActivity {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(1)
                            },
                            new UserActivity {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(1)
                            },
                        }
                    },
                    new Activity {
                        Title          = "Spanish Cooking",
                        Date           = DateTime.Now.AddMonths(2),
                        Description    = "Learn Spanish while making new foods.",
                        Category       = "languageandlogic",
                        Venue          = "8420 NE Thompson St.",
                        UserActivities = new List <UserActivity> {
                            new UserActivity {
                                AppUserId  = "c",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                            new UserActivity {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                        }
                    }
                    // new Activity {
                    // Title = "Future Activity 3",
                    // Date = DateTime.Now.AddMonths (3),
                    // Description = "Activity 3 months in future",
                    // Category = "Drinks",
                    // City = "London",
                    // Venue = "Pub",
                    // UserActivities = new List<UserActivity> {
                    // new UserActivity {
                    // AppUserId = "b",
                    // IsHost = true,
                    // DateJoined = DateTime.Now.AddMonths (3)
                    // },
                    // new UserActivity {
                    // AppUserId = "c",
                    // IsHost = false,
                    // DateJoined = DateTime.Now.AddMonths (3)
                    // },
                    // }
                    // },
                    // new Activity {
                    // Title = "Future Activity 4",
                    // Date = DateTime.Now.AddMonths (4),
                    // Description = "Activity 4 months in future",
                    // Category = "Culture",
                    // City = "London",
                    // Venue = "British Museum",
                    // UserActivities = new List<UserActivity> {
                    // new UserActivity {
                    // AppUserId = "a",
                    // IsHost = true,
                    // DateJoined = DateTime.Now.AddMonths (4)
                    // }
                    // }
                    // }
                    // new Activity {
                    // Title = "Future Activity 5",
                    // Date = DateTime.Now.AddMonths (5),
                    // Description = "Activity 5 months in future",
                    // Category = "Drinks",
                    // City = "London",
                    // Venue = "Punch and Judy",
                    // UserActivities = new List<UserActivity> {
                    // new UserActivity {
                    // AppUserId = "c",
                    // IsHost = true,
                    // DateJoined = DateTime.Now.AddMonths (5)
                    // },
                    // new UserActivity {
                    // AppUserId = "b",
                    // IsHost = false,
                    // DateJoined = DateTime.Now.AddMonths (5)
                    // },
                    // }
                    // },
                    // new Activity {
                    // Title = "Future Activity 6",
                    // Date = DateTime.Now.AddMonths (6),
                    // Description = "Activity 6 months in future",
                    // Category = "Music",
                    // City = "London",
                    // Venue = "O2 Arena",
                    // UserActivities = new List<UserActivity> {
                    // new UserActivity {
                    // AppUserId = "a",
                    // IsHost = true,
                    // DateJoined = DateTime.Now.AddMonths (6)
                    // },
                    // new UserActivity {
                    // AppUserId = "b",
                    // IsHost = false,
                    // DateJoined = DateTime.Now.AddMonths (6)
                    // },
                    // }
                    // },
                    // new Activity {
                    // Title = "Future Activity 7",
                    // Date = DateTime.Now.AddMonths (7),
                    // Description = "Activity 7 months in future",
                    // Category = "Travel",
                    // City = "Berlin",
                    // Venue = "All",
                    // UserActivities = new List<UserActivity> {
                    // new UserActivity {
                    // AppUserId = "a",
                    // IsHost = true,
                    // DateJoined = DateTime.Now.AddMonths (7)
                    // },
                    // new UserActivity {
                    // AppUserId = "c",
                    // IsHost = false,
                    // DateJoined = DateTime.Now.AddMonths (7)
                    // },
                    // }
                    // },
                    // new Activity {
                    // Title = "Future Activity 8",
                    // Date = DateTime.Now.AddMonths (8),
                    // Description = "Activity 8 months in future",
                    // Category = "Drinks",
                    // City = "London",
                    // Venue = "Pub",
                    // UserActivities = new List<UserActivity> {
                    // new UserActivity {
                    // AppUserId = "b",
                    // IsHost = true,
                    // DateJoined = DateTime.Now.AddMonths (8)
                    // },
                    // new UserActivity {
                    // AppUserId = "a",
                    // IsHost = false,
                    // DateJoined = DateTime.Now.AddMonths (8)
                    // },
                    // }
                    // }
                };

                await context.Activities.AddRangeAsync(activities);

                await context.SaveChangesAsync();
            }
        }
示例#9
0
        public static async Task SeedData(DataContext context, UserManager <User> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <User>
                {
                    new User
                    {
                        Id          = "a",
                        DisplayName = "Bob",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new User {
                        Id          = "b",
                        DisplayName = "Jack",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    }
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }
            if (!context.Questions.Any())
            {
                var categories = new List <Category>
                {
                    new Category
                    {
                        Id = "Biology",
                    },
                    new Category
                    {
                        Id = "Theology"
                    },
                    new Category
                    {
                        Id = "Computer-Science"
                    },
                    new Category
                    {
                        Id = "Hardware"
                    },
                    new Category
                    {
                        Id = "English"
                    },
                    new Category
                    {
                        Id = "History"
                    },
                    new Category
                    {
                        Id = "Economics"
                    },
                };
                await context.Categories.AddRangeAsync(categories);

                var questions = new List <Question>
                {
                    new Question
                    {
                        Id                 = "A",
                        Title              = "Lorem ipsum",
                        Date               = DateTime.Now.AddMonths(-1),
                        Description        = "dolor sit amet, consectetur adipiscing elit. Nunc auctor leo nec convallis vestibulum. Suspendisse ac lorem lectus. Nunc nec sodales odio. Sed sed rhoncus ipsum, ut aliquam sapien. Curabitur ac libero velit. Phasellus eu consectetur neque. Mauris tempor euismod enim nec sagittis. Aliquam convallis ultricies ex ac gravida. Ut aliquet euismod maximus. Donec luctus dictum suscipit. Nunc a erat a turpis blandit pharetra eget in purus. Vivamus porta et odio ut lobortis. Nulla tempor gravida lorem ut fringilla.",
                        Author             = await userManager.FindByIdAsync("a"),
                        QuestionCategories = new List <QuestionCategory>
                        {
                            new QuestionCategory
                            {
                                CategoryId = "Biology",
                                QuestionId = "A",
                            }
                        }
                    },
                    new Question
                    {
                        Id                 = "B",
                        Title              = "Mauris semper",
                        Date               = DateTime.Now.AddMonths(-2),
                        Description        = "Pellentesque congue, odio vel dictum maximus, massa leo fermentum nisl, quis sollicitudin neque tellus eu augue. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec leo velit, semper viverra dictum nec, ornare in magna. In hac habitasse platea dictumst. Cras congue nisl sit amet quam pharetra, ut vestibulum odio pharetra. Praesent eleifend eros ullamcorper libero faucibus, sagittis varius tellus iaculis.",
                        Author             = await userManager.FindByIdAsync("a"),
                        QuestionCategories = new List <QuestionCategory>
                        {
                            new QuestionCategory
                            {
                                CategoryId = "History",
                                QuestionId = "B",
                            },
                            new QuestionCategory
                            {
                                CategoryId = "Computer-Science",
                                QuestionId = "B",
                            }
                        }
                    },
                    new Question
                    {
                        Id                 = "C",
                        Title              = "Vestibulum porta",
                        Date               = DateTime.Now.AddMonths(-3),
                        Description        = "Aliquam placerat, diam a accumsan placerat, ante arcu convallis sapien, quis cursus mauris urna non nunc. In quis ullamcorper nisl. Proin quam urna, faucibus eu mattis non, dignissim in nunc. Aliquam consectetur purus at nisi lobortis, eu tincidunt nibh maximus. Donec orci ipsum, viverra id eros in, mattis egestas nibh. Proin gravida nisl eu ipsum tristique semper.",
                        Author             = await userManager.FindByIdAsync("b"),
                        QuestionCategories = new List <QuestionCategory>
                        {
                            new QuestionCategory
                            {
                                CategoryId = "English",
                                QuestionId = "C",
                            },
                            new QuestionCategory
                            {
                                CategoryId = "Theology",
                                QuestionId = "C",
                            }
                        }
                    }
                };
                await context.Questions.AddRangeAsync(questions);

                await context.SaveChangesAsync();
            }
        }
示例#10
0
        public static async Task SeedData(DataContext context, UserManager <AppUser> userManager)
        {
            if (!context.Products.Any())
            {
                var products = new List <Product>
                {
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "i7 7700k Techno",
                        Category    = "Computers",
                        Images      = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            }
                        },
                        Name      = "SONY Computer",
                        Price     = "50000",
                        Title     = "Sony computer high level class",
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                    },
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "Good gadget for work and games",
                        Category    = "Smartphones",
                        Images      = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737760.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            }
                        },
                        Name      = "Nokia 1.3",
                        Price     = "28500",
                        Title     = "Смартфон Nokia 1.3",
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                    },
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "Good gadget for home",
                        Category    = "Vacuums",
                        Images      = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737760.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            }
                        },
                        Name      = "LG 104-32 Model B",
                        Price     = "25000",
                        Title     = "Xiaomi Redmi 4x",
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                    },
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "Пылесос LG VC5316BNSAF снабжен эллиптическим циклонным фильтром, сохраняющим высокую силу всасывания при длительной работе. Он собирает мусор в практичный пластиковый контейнер, позволяя обходиться без одноразовых мешков. К нему прилагается микрофильтр, который задерживает более 90% мелкой пыли и других аллергенов. Благодаря этому в доме создается комфортная здоровая обстановка.Большие колеса с прорезиненным покрытием делают пылесос LG VC5316BNSAF маневренным, устойчивым и безопасным для чувствительных материалов. Широкая ручка позволяет быстро переносить его между комнатами. Он укомплектован тремя насадками — универсальной щеткой для пола и ковров, инструментом для чистки мебели и щелевой трубкой для уборки в труднодоступных местах.",
                        Category    = "Vacuums",
                        Images      = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737760.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            }
                        },
                        Name      = "LG VC5316BNSAF",
                        Price     = "5199",
                        Title     = "Пылесос LG VC5316BNSAF",
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                    },
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "Good gadget for work and games",
                        Category    = "Smartphones",
                        Images      = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737760.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737760.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737760.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/685/98/new_71568598_l_1604737797.jpeg"
                            }
                        },
                        Name      = "Nokia 8.3",
                        Price     = "43000",
                        Title     = "Смартфон Nokia 8.3",
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                    },
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "Ноутбук для серфинга в интернете.Быстрый благодаря ssd,стильный и имеющий на борту 4 гб озу и процессор Pentium silver N5030,а также разрешение экрана 1920*1080 точек.",
                        Category    = "Notebooks",
                        Images      = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/723/13/new_71572313_l_1605697031.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/723/13/new_71572313_l_1605697285.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/723/13/new_71572313_l_1605697031.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/723/13/new_71572313_l_1605697285.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/723/13/new_71572313_l_1605697031.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/723/13/new_71572313_l_1605697285.jpeg"
                            },
                        },
                        Name      = "Acer Swift 1 SF114-33-P06A",
                        Price     = "33999",
                        Title     = "Ультрабук Acer Swift 1 SF114-33-P06A",
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                    },
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "Смартфон Redmi Note 9 Pro 128GB Grey оснащен фотомодулем из четырех камер с 64-мегапиксельной матрицей основного объектива." +
                                      "Такая система позволяет создавать детализированные изображения, снимать великолепные панорамы и портреты с эффектом боке, получать качественные макроснимки и записывать видео в разрешении 4K." +
                                      "С легкостью делать селфи, в том числе с эффектом слоу-мо, помогает 16-мегапиксельная фронтальная камера, при работе которой применяются алгоритмы искусственного интеллекта.Высокое быстродействие смартфона Redmi Note 9 Pro 128GB Grey обеспечивает производительный восьмиядерный процессор Qualcomm Snapdragon 720G и оперативная память на 6 ГБ. Внутренний накопитель располагает емкостью 128 ГБ. К нему можно добавить microSD карту вместимостью до 512 ГБ.Смартфон Redmi Note 9 Pro 128GB Grey отличается безупречным симметричным дизайном как задней стороны, так и 6,67-дюймового дисплея. Аккумулятор на 5020 мА*ч позволяет непрерывно слушать музыку на протяжении более чем 6 суток, до 33 часов общаться по голосовой связи или до 16 часов пользоваться гаджетом как навигатором.",
                        Category = "Smartphones",
                        Images   = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            }
                        },
                        Name      = "Xiaomi Redmi Note 9 Pro",
                        Price     = "20000",
                        Title     = "Смартфон Xiaomi Redmi Note 9 Pro",
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg",
                    },
                    new Product
                    {
                        ProductId   = Guid.NewGuid(),
                        Description = "Телевизор Hi 32HT101X — хороший выбор для небольшой гостиной. " +
                                      "Его 31,5-дюймовый экран с разрешением 1366х768 пикселей воспроизводит четкую, яркую, детализированную картинку. " +
                                      "Тонкая рамка не отвлекает вас от просмотра и помогает этой модели выглядеть особенно элегантно. " +
                                      "Экран создан на основе матрицы IPS, произведенной компанией Panasonic. " +
                                      "Она обеспечивает реалистичную цветопередачу, а углы обзора достигают 176°, и изображение не искажается, если вы смотрите на него со стороны." +
                                      "Модель Hi 32HT101X оборудована тюнером DVB-T2 и слотом CI+." +
                                      "Это значит, что он принимает передачи цифрового ТВ, а при установке CAM-модуля вам будут доступны закрытые (платные) пакеты цифровых каналов." +
                                      "Разъемы HDMI и USB позволяют подключать флешки и внешние жесткие диски, игровую приставку и DVD-плеер. " +
                                      "Встроенный медиаплеер поддерживает множество кодеков, поэтому он легко прочитает файлы практически любого формата и воспроизведет фотографию или видеоролик." +
                                      "Телевизор Hi 32HT101X предлагает владельцу множество дополнительных возможностей." +
                                      " С помощью функции TimeShift вы поставите фильм, шоу или спортивную передачу на «паузу», а потом досмотрите их в удобное время." +
                                      " Поддержка технологии MHL обеспечивает простое взаимодействие с совместимыми смартфонами и планшетами: подсоединяйте мобильные устройства," +
                                      " чтобы выводить с них мультимедийный контент на большой яркий экран.",
                        Category = "TV",
                        Images   = new List <Image> {
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://static.eldorado.ru/photos/71/715/110/97/new_71511097_l_1564664868.jpeg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            },
                            new Image {
                                ImageId = Guid.NewGuid(), imageUrl = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg"
                            },
                        },
                        MainImage = "https://images.ru.prom.st/562280743_w440_h440_smartfon-nokia-3.jpg",
                        Name      = "Hi 32HT101X",
                        Price     = "30000",
                        Title     = "LED телевизор 31.5 Hi 32HT101X"
                    }
                };
                context.Products.AddRange(products);
                if (!userManager.Users.Any())
                {
                    var users = new List <AppUser>
                    {
                        new AppUser
                        {
                            DisplayName = "Admin",
                            Email       = "*****@*****.**",
                            UserName    = "******",
                            Role        = "admin"
                        },
                        new AppUser
                        {
                            DisplayName = "Vurdalak",
                            Email       = "*****@*****.**",
                            UserName    = "******"
                        }
                    };
                    foreach (var user in users)
                    {
                        await userManager.CreateAsync(user, "Pa$$w0rd");
                    }
                }
                var result = await context.SaveChangesAsync() > 0;

                if (!result)
                {
                    throw new Exception("Database save changes Error");
                }
            }
        }
示例#11
0
        public static async Task SeedData(DataContext context, UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any() && !context.Activities.Any())
            {
                var users = new List <AppUser>
                {
                    new AppUser {
                        DisplayName = "John", UserName = "******", Email = "*****@*****.**"
                    },
                    new AppUser {
                        DisplayName = "Bob", UserName = "******", Email = "*****@*****.**"
                    },
                    new AppUser {
                        DisplayName = "Tom", UserName = "******", Email = "*****@*****.**"
                    }
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }

                var activities = new List <Activity>
                {
                    new Activity
                    {
                        Title       = "Past Activity 1",
                        Date        = DateTime.Now.AddMonths(-2),
                        Description = "Activity 2 months ago",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Pub",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[0],
                                IsHost  = true
                            }
                        }
                    },
                    new Activity
                    {
                        Title       = "Past Activity 2",
                        Date        = DateTime.Now.AddMonths(-1),
                        Description = "Activity 1 month ago",
                        Category    = "culture",
                        City        = "Paris",
                        Venue       = "The Louvre",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[0],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[1],
                                IsHost  = false
                            },
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 1",
                        Date        = DateTime.Now.AddMonths(1),
                        Description = "Activity 1 month in future",
                        Category    = "music",
                        City        = "London",
                        Venue       = "Wembly Stadium",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[2],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[1],
                                IsHost  = false
                            },
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 2",
                        Date        = DateTime.Now.AddMonths(2),
                        Description = "Activity 2 months in future",
                        Category    = "food",
                        City        = "London",
                        Venue       = "Jamies Italian",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[0],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[2],
                                IsHost  = false
                            },
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 3",
                        Date        = DateTime.Now.AddMonths(3),
                        Description = "Activity 3 months in future",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Pub",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[1],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[0],
                                IsHost  = false
                            },
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 4",
                        Date        = DateTime.Now.AddMonths(4),
                        Description = "Activity 4 months in future",
                        Category    = "culture",
                        City        = "London",
                        Venue       = "British Museum",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[1],
                                IsHost  = true
                            }
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 5",
                        Date        = DateTime.Now.AddMonths(5),
                        Description = "Activity 5 months in future",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Punch and Judy",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[0],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[1],
                                IsHost  = false
                            },
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 6",
                        Date        = DateTime.Now.AddMonths(6),
                        Description = "Activity 6 months in future",
                        Category    = "music",
                        City        = "London",
                        Venue       = "O2 Arena",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[2],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[1],
                                IsHost  = false
                            },
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 7",
                        Date        = DateTime.Now.AddMonths(7),
                        Description = "Activity 7 months in future",
                        Category    = "travel",
                        City        = "Berlin",
                        Venue       = "All",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[0],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[2],
                                IsHost  = false
                            },
                        }
                    },
                    new Activity
                    {
                        Title       = "Future Activity 8",
                        Date        = DateTime.Now.AddMonths(8),
                        Description = "Activity 8 months in future",
                        Category    = "drinks",
                        City        = "London",
                        Venue       = "Pub",
                        Attendees   = new List <ActivityAttendee>
                        {
                            new ActivityAttendee
                            {
                                AppUser = users[2],
                                IsHost  = true
                            },
                            new ActivityAttendee
                            {
                                AppUser = users[1],
                                IsHost  = false
                            },
                        }
                    }
                };

                await context.Activities.AddRangeAsync(activities);

                await context.SaveChangesAsync();
            }

            #region Seeding with Bogus Faker Data

            // var fakeActivity = new Faker<Activity>()
            //     .RuleFor(p => p.Title, f => f.Random.Words(3))
            //     .RuleFor(p => p.Date, f => f.Date.Between(DateTime.Now, DateTime.Now).AddMonths(10))
            //     .RuleFor(p => p.Description, f => f.Random.Words(5))
            //     .RuleFor(p => p.Category, f => f.Random.Word())
            //     .RuleFor(p => p.City, f => f.Address.City())
            //     .RuleFor(p => p.Venue, f => f.Random.Words(2));
            //
            // for (int i = 0; i < 10; i++)
            // {
            //     await context.Activities.AddRangeAsync(fakeActivity);
            //     await context.SaveChangesAsync();
            // }

            #endregion
        }
示例#12
0
        public static async Task SeedAsync(DataContext dbContext, UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <AppUser>
                {
                    new AppUser
                    {
                        Id          = "a",
                        DisplayName = "Bob",
                        UserName    = "******",
                        Email       = "*****@*****.**",
                        Photos      = new [] { new Photo {
                                                   Id = "1", IsMain = true, Url = "https://res.cloudinary.com/stankansas/image/upload/v1609119885/pcykcdlnyjbckrobnzwb.jpg"
                                               } }
                    },
                    new AppUser
                    {
                        Id          = "b",
                        DisplayName = "Jane",
                        UserName    = "******",
                        Email       = "*****@*****.**",
                        Photos      = new [] { new Photo {
                                                   Id = "2", IsMain = true, Url = "https://res.cloudinary.com/stankansas/image/upload/v1609119965/yglovzkycojx7f0zafgh.jpg"
                                               } }
                    },
                    new AppUser
                    {
                        Id          = "c",
                        DisplayName = "Tom",
                        UserName    = "******",
                        Email       = "*****@*****.**",
                        Photos      = new [] { new Photo {
                                                   Id = "3", IsMain = true, Url = "https://res.cloudinary.com/stankansas/image/upload/v1609120019/wdxbk5qjkettlxnvzmy5.jpg"
                                               } }
                    },
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }

            if (!dbContext.Activities.Any())
            {
                var activities = new List <Activity>
                {
                    new Activity
                    {
                        Title          = "Past Activity 1",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 2 months ago",
                        Category       = "drinks",
                        City           = "London",
                        Venue          = "Pub",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-2)
                            }
                        }
                    },
                    new Activity
                    {
                        Title          = "Past Activity 2",
                        Date           = DateTime.Now.AddMonths(-1),
                        Description    = "Activity 1 month ago",
                        Category       = "coding",
                        City           = "Paris",
                        Venue          = "The Louvre",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Lets Dance",
                        Date           = DateTime.Now.AddMonths(-3),
                        Description    = "Lets dance like nobody is watching us!",
                        Category       = "music",
                        City           = "Montreal",
                        Venue          = "Cresent",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-3)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(-3).AddDays(1)
                            },
                        },
                        Comments = new List <Comment>
                        {
                            new Comment
                            {
                                Id        = Guid.NewGuid(),
                                Body      = "How artistic!",
                                AuthorId  = "a",
                                CreatedAt = DateTime.Now.AddMonths(-3).AddDays(2)
                            },
                            new Comment
                            {
                                Id        = Guid.NewGuid(),
                                Body      = "Awesome, lets do it",
                                AuthorId  = "c",
                                CreatedAt = DateTime.Now.AddMonths(-3).AddDays(4)
                            },
                            new Comment
                            {
                                Id        = Guid.NewGuid(),
                                Body      = "Very tempting, going",
                                AuthorId  = "b",
                                CreatedAt = DateTime.Now.AddMonths(-3).AddDays(3)
                            }
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 2",
                        Date           = DateTime.Now.AddMonths(2),
                        Description    = "Activity 2 months in future",
                        Category       = "food",
                        City           = "London",
                        Venue          = "Jamies Italian",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 3",
                        Date           = DateTime.Now.AddMonths(3),
                        Description    = "Activity 3 months in future",
                        Category       = "drinks",
                        City           = "NY",
                        Venue          = "Pub",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(3)
                            },
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(3)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 4",
                        Date           = DateTime.Now.AddMonths(4),
                        Description    = "Activity 4 months in future",
                        Category       = "culture",
                        City           = "Toronto",
                        Venue          = "Canada Museum",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(4)
                            }
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 5",
                        Date           = DateTime.Now.AddMonths(5),
                        Description    = "Activity 5 months in future",
                        Category       = "drinks",
                        City           = "London",
                        Venue          = "Punch and Judy",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(5)
                            },
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(5)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 6",
                        Date           = DateTime.Now.AddMonths(6),
                        Description    = "Activity 6 months in future",
                        Category       = "music",
                        City           = "London",
                        Venue          = "O2 Arena",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(6)
                            },
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(6)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 7",
                        Date           = DateTime.Now.AddMonths(7),
                        Description    = "Activity 7 months in future",
                        Category       = "travel",
                        City           = "Berlin",
                        Venue          = "All",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(7)
                            },
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(7)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 8",
                        Date           = DateTime.Now.AddMonths(8),
                        Description    = "Activity 8 months in future",
                        Category       = "fun",
                        City           = "Montreal",
                        Venue          = "Pub",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(8)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(8)
                            },
                        }
                    }
                };

                await dbContext.Activities.AddRangeAsync(activities);

                await dbContext.SaveChangesAsync();
            }
        }
示例#13
0
        public static async Task SeedData(DataContext context, UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <AppUser>
                {
                    new AppUser
                    {
                        DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**"
                    },
                    new AppUser
                    {
                        DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**"
                    },
                    new AppUser
                    {
                        DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**"
                    },
                    new AppUser
                    {
                        DisplayName = "Niko", UserName = "******", Email = "*****@*****.**"
                    },
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }

            //If the database Is not empty then return the list with activities, else return seed data
            if (context.Activities.Any())
            {
                return;
            }

            var activities = new List <Activity>
            {
                new Activity
                {
                    Title       = "Past Activity 1",
                    Date        = DateTime.Now.AddMonths(-2),
                    Description = "Activity 2 months ago",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Pub",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Past Activity 2",
                    Date        = DateTime.Now.AddMonths(-1),
                    Description = "Activity 1 month ago",
                    Category    = "culture",
                    City        = "Paris",
                    Venue       = "Louvre",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 1",
                    Date        = DateTime.Now.AddMonths(1),
                    Description = "Activity 1 month in future",
                    Category    = "culture",
                    City        = "London",
                    Venue       = "Natural History Museum",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 2",
                    Date        = DateTime.Now.AddMonths(2),
                    Description = "Activity 2 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "O2 Arena",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 3",
                    Date        = DateTime.Now.AddMonths(3),
                    Description = "Activity 3 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Another pub",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 4",
                    Date        = DateTime.Now.AddMonths(4),
                    Description = "Activity 4 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Yet another pub",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 5",
                    Date        = DateTime.Now.AddMonths(5),
                    Description = "Activity 5 months in future",
                    Category    = "drinks",
                    City        = "London",
                    Venue       = "Just another pub",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 6",
                    Date        = DateTime.Now.AddMonths(6),
                    Description = "Activity 6 months in future",
                    Category    = "music",
                    City        = "London",
                    Venue       = "Roundhouse Camden",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 7",
                    Date        = DateTime.Now.AddMonths(7),
                    Description = "Activity 2 months ago",
                    Category    = "travel",
                    City        = "London",
                    Venue       = "Somewhere on the Thames",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                },
                new Activity
                {
                    Title       = "Future Activity 8",
                    Date        = DateTime.Now.AddMonths(8),
                    Description = "Activity 8 months in future",
                    Category    = "film",
                    City        = "London",
                    Venue       = "Cinema",
                    Attendees   = new List <ActivityAttendee>
                    {
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Arvis", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = true
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Niko", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Enzo", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                        new ActivityAttendee
                        {
                            AppUser = { DisplayName = "Irbe", UserName = "******", Email = "*****@*****.**" },
                            IsHost  = false
                        },
                    },
                }
            };

            await context.Activities.AddRangeAsync(activities);

            await context.SaveChangesAsync();
        }
示例#14
0
        public static async Task SeedData(DataContext context,
                                          UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <AppUser>
                {
                    new AppUser
                    {
                        Id          = "a",
                        DisplayName = "Bob",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser
                    {
                        Id          = "b",
                        DisplayName = "Jane",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser
                    {
                        Id          = "c",
                        DisplayName = "Tom",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }

            if (!context.Activities.Any())
            {
                var activities = new List <Activity>
                {
                    new Activity
                    {
                        Name           = "F_1",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 1",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-2)
                            }
                        }
                    },
                    new Activity
                    {
                        Name           = "F_2",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity  2 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                        }
                    },
                    new Activity
                    {
                        Name           = "F_3",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity  3 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(1)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(1)
                            },
                        }
                    },
                    new Activity
                    {
                        Name           = "F_4",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 4 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                        }
                    },
                    new Activity
                    {
                        Name           = "F_5",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 5 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(3)
                            },
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(3)
                            },
                        }
                    },
                    new Activity
                    {
                        Name           = "F_6",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity  6 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(4)
                            }
                        }
                    },
                    new Activity
                    {
                        Name           = "F_7",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 7 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(5)
                            },
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(5)
                            },
                        }
                    },
                    new Activity
                    {
                        Name           = "F_8",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity  8 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(6)
                            },
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(6)
                            },
                        }
                    },
                    new Activity
                    {
                        Name           = "F_9",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 9 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(7)
                            },
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(7)
                            },
                        }
                    },
                    new Activity
                    {
                        Name           = "F_10",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 10 is ready to do",
                        PhoneNumber    = "1234567890",
                        Address        = "Alampuram",
                        Status         = "Done",
                        NoOfAcres      = "2",
                        Amount         = "1000",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(8)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(8)
                            },
                        }
                    }
                };

                await context.Activities.AddRangeAsync(activities);

                await context.SaveChangesAsync();
            }
        }
示例#15
0
        public static async Task SeedData(DataContext context) //By making this method static we can run this function without creating an instance of Seed First
        {
            if (context.Thoughts.Any())
            {
                return;
            }

            var Thoughts = new List <Thought>
            {
                new Thought
                {
                    Context          = "At home in the office",
                    DateRecorded     = DateTime.Now.AddMonths(2),
                    DateLastAccessed = DateTime.Now.AddMonths(2),
                    Content          = "To create Hoomanz",
                    Category         = "Idea",
                    Tags             = "development",
                    Resolved         = false,
                    Anchored         = true,
                    Desirable        = true,
                    Desirability     = 90,
                },
                new Thought
                {
                    Context          = "In the garden",
                    DateRecorded     = DateTime.Now.AddMonths(0),
                    DateLastAccessed = DateTime.Now.AddMonths(0),
                    Content          = "To become a yogi",
                    Category         = "Habit",
                    Tags             = "health",
                    Resolved         = false,
                    Anchored         = true,
                    Desirable        = true,
                    Desirability     = 80,
                },
                new Thought
                {
                    Context          = "In the shower",
                    DateRecorded     = DateTime.Now.AddMonths(-1),
                    DateLastAccessed = DateTime.Now.AddMonths(-1),
                    Content          = "Don't forget to brush teeth",
                    Category         = "Memory",
                    Tags             = "health",
                    Resolved         = true,
                    Anchored         = true,
                    Desirable        = true,
                    Desirability     = 25,
                },
                new Thought
                {
                    Context          = "In the shower",
                    DateRecorded     = DateTime.Now.AddMonths(5),
                    DateLastAccessed = DateTime.Now.AddMonths(5),
                    Content          = "I should get some new body lotion",
                    Category         = "Memory",
                    Tags             = "misc",
                    Resolved         = false,
                    Anchored         = false,
                    Desirable        = false,
                    Desirability     = 10,
                },
                new Thought
                {
                    Context          = "While driving",
                    DateRecorded     = DateTime.Now.AddMonths(1),
                    DateLastAccessed = DateTime.Now.AddMonths(1),
                    Content          = "I'd love to make a podcost",
                    Category         = "Desire",
                    Tags             = "misc",
                    Resolved         = false,
                    Anchored         = false,
                    Desirable        = true,
                    Desirability     = 50,
                },
                new Thought
                {
                    Context          = "In the car",
                    DateRecorded     = DateTime.Now.AddMonths(7),
                    DateLastAccessed = DateTime.Now.AddMonths(7),
                    Content          = "I feel sweaty and gross",
                    Category         = "Feeling",
                    Tags             = "health",
                    Resolved         = false,
                    Anchored         = false,
                    Desirable        = false,
                    Desirability     = 50,
                },
            };

            await context.Thoughts.AddRangeAsync(Thoughts);

            await context.SaveChangesAsync();
        }
示例#16
0
        public static async Task SeedData(DataContext context,
                                          UserManager <AppUser> userManager)
        {
            if (!userManager.Users.Any())
            {
                var users = new List <AppUser>
                {
                    new AppUser
                    {
                        Id          = "a",
                        DisplayName = "Bob",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser
                    {
                        Id          = "b",
                        DisplayName = "Jane",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                    new AppUser
                    {
                        Id          = "c",
                        DisplayName = "Tom",
                        UserName    = "******",
                        Email       = "*****@*****.**"
                    },
                };

                foreach (var user in users)
                {
                    await userManager.CreateAsync(user, "Pa$$w0rd");
                }
            }

            if (!context.Activities.Any())
            {
                var activities = new List <Activity>
                {
                    new Activity
                    {
                        Title          = "Past Activity 1",
                        Date           = DateTime.Now.AddMonths(-2),
                        Description    = "Activity 2 months ago",
                        Category       = "Drinks",
                        City           = "London",
                        Venue          = "Pub",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-2)
                            }
                        }
                    },
                    new Activity
                    {
                        Title          = "Past Activity 2",
                        Date           = DateTime.Now.AddMonths(-1),
                        Description    = "Activity 1 month ago",
                        Category       = "Culture",
                        City           = "Paris",
                        Venue          = "The Louvre",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(-1)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 1",
                        Date           = DateTime.Now.AddMonths(1),
                        Description    = "Activity 1 month in future",
                        Category       = "Music",
                        City           = "London",
                        Venue          = "Wembly Stadium",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(1)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(1)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 2",
                        Date           = DateTime.Now.AddMonths(2),
                        Description    = "Activity 2 months in future",
                        Category       = "Food",
                        City           = "London",
                        Venue          = "Jamies Italian",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(2)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 3",
                        Date           = DateTime.Now.AddMonths(3),
                        Description    = "Activity 3 months in future",
                        Category       = "Drinks",
                        City           = "London",
                        Venue          = "Pub",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(3)
                            },
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(3)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 4",
                        Date           = DateTime.Now.AddMonths(4),
                        Description    = "Activity 4 months in future",
                        Category       = "Culture",
                        City           = "London",
                        Venue          = "British Museum",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(4)
                            }
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 5",
                        Date           = DateTime.Now.AddMonths(5),
                        Description    = "Activity 5 months in future",
                        Category       = "Drinks",
                        City           = "London",
                        Venue          = "Punch and Judy",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(5)
                            },
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(5)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 6",
                        Date           = DateTime.Now.AddMonths(6),
                        Description    = "Activity 6 months in future",
                        Category       = "Music",
                        City           = "London",
                        Venue          = "O2 Arena",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(6)
                            },
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(6)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 7",
                        Date           = DateTime.Now.AddMonths(7),
                        Description    = "Activity 7 months in future",
                        Category       = "Travel",
                        City           = "Berlin",
                        Venue          = "All",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(7)
                            },
                            new UserActivity
                            {
                                AppUserId  = "c",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(7)
                            },
                        }
                    },
                    new Activity
                    {
                        Title          = "Future Activity 8",
                        Date           = DateTime.Now.AddMonths(8),
                        Description    = "Activity 8 months in future",
                        Category       = "Drinks",
                        City           = "London",
                        Venue          = "Pub",
                        UserActivities = new List <UserActivity>
                        {
                            new UserActivity
                            {
                                AppUserId  = "b",
                                IsHost     = true,
                                DateJoined = DateTime.Now.AddMonths(8)
                            },
                            new UserActivity
                            {
                                AppUserId  = "a",
                                IsHost     = false,
                                DateJoined = DateTime.Now.AddMonths(8)
                            },
                        }
                    }
                };

                await context.Activities.AddRangeAsync(activities);

                await context.SaveChangesAsync();
            }
        }
示例#17
0
        public static async Task SeedData(DataContext context)
        {
            if (context.Books.Any())
            {
                return;
            }

            var activities = new List <Book>
            {
                new Book
                {
                    Title       = "Book1",
                    Date        = DateTime.Now.AddMonths(-2),
                    Description = "The book was launched 2 months ago",
                    Category    = "horror",
                },
                new Book
                {
                    Title       = "Book2",
                    Date        = DateTime.Now.AddMonths(-1),
                    Description = "The book was launched 1 month ago",
                    Category    = "culture",
                },
                new Book
                {
                    Title       = "Book3",
                    Date        = DateTime.Now.AddMonths(1),
                    Description = "The book will be launched in 1 month",
                    Category    = "culture",
                },
                new Book
                {
                    Title       = "Book4",
                    Date        = DateTime.Now.AddMonths(2),
                    Description = "The book will be launched in 2 months",
                    Category    = "horror",
                },
                new Book
                {
                    Title       = "Book5",
                    Date        = DateTime.Now.AddMonths(3),
                    Description = "The book will be launched in 3 months",
                    Category    = "kids",
                },
                new Book
                {
                    Title       = "Book6",
                    Date        = DateTime.Now.AddMonths(4),
                    Description = "The book will be launched in 4 months",
                    Category    = "kids",
                },
                new Book
                {
                    Title       = "Book7",
                    Date        = DateTime.Now.AddMonths(5),
                    Description = "The book will be launched in 5 months",
                    Category    = "kids",
                },
                new Book
                {
                    Title       = "Book8",
                    Date        = DateTime.Now.AddMonths(6),
                    Description = "The book will be launched in 6 months",
                    Category    = "culture",
                },
                new Book
                {
                    Title       = "Book9",
                    Date        = DateTime.Now.AddMonths(7),
                    Description = "The book was launched 2 months ago",
                    Category    = "travel",
                },
                new Book
                {
                    Title       = "Book10",
                    Date        = DateTime.Now.AddMonths(8),
                    Description = "The book will be launched 8 months",
                    Category    = "travel",
                }
            };

            await context.Books.AddRangeAsync(activities);

            await context.SaveChangesAsync();
        }