|
namespace TestMongo
{
using System;
using System.Collections.Generic;
using System.Linq;
using MongoDB.Driver;
public partial class Program
{
#region Methods
private static void BuildClubMembers(MongoCollection<ClubMember> collection, Random random, int counter)
{
string[] forenames = { "Anwen", "David", "Rhys", "Megan", "Sean", "Delyth", "Rhian", "Aled" };
string[] lastnames = { "Jones", "Davies", "Williams", "Rees", "Parry", "Edwards", "Thomas", "Richards" };
string[] vintageCars = { "Alvis", "Austin", "Cooper", "Bristol", "Hillman", "Humber", "Riley" };
Random rand = random;
for (int i = 0; i < counter; i++)
{
int forenameIndex = rand.Next(0, forenames.Count());
int lastnameIndex = rand.Next(0, lastnames.Count());
int totalNumberOfCars = rand.Next(0, vintageCars.Count());
DateTime today = DateTime.Now;
var member = new ClubMember
{
Forename = forenames[forenameIndex],
Lastname = lastnames[lastnameIndex],
Age = rand.Next(16, 65),
MembershipDate = today.AddDays(-1 * rand.Next(0, 7200))
};
if (totalNumberOfCars > 0)
{
member.Cars = new List<string>();
}
for (int c = 0; c < totalNumberOfCars; c++)
{
int carIndex = rand.Next(0, vintageCars.Count());
member.Cars.Add(vintageCars[carIndex]);
}
collection.Insert(member);
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.