public MemberAddress GenerateRandomMemberAddress(Member currMember) { double nextval; string rndstreetname; string rndroadtype; string rndsuburbname; string postcode = ""; int doornumber; // random door number nextval = GetRandomInteger(499); doornumber = (nextval > 0 ? (int)nextval : 1); string[] streetnames = { "Blaxand", "Herring", "Epping", "Agincourt", "North", "Talavera", "Khartoum", "Lane Cove", "Ryde", "Waterloo", "Rowe", "Second", "South", "First" }; string[] roadtypes = { "Road", "Street", "Lane", "Close", "Drive", "Ave" }; string[] suburbs = { "Ryde", "Marsfield", "Epping", "Macquarie Park", "Eastwood", "Denistone" }; Dictionary <string, string> postcodes = new Dictionary <string, string> { { "Ryde", "2112" }, { "Marsfield", "2122" }, { "Epping", "2121" }, { "Macquarie Park", "2113" }, { "Eastwood", "2122" }, { "Denistone", "2114" } }; // Generate address // randon road type rndroadtype = roadtypes[GetRandomInteger(roadtypes.Length)]; // random street address. rndstreetname = doornumber.ToString() + " " + streetnames[GetRandomInteger(streetnames.Length)] + " " + rndroadtype; // random suburb rndsuburbname = suburbs[GetRandomInteger(suburbs.Length)]; // suburb and postcode KeyValuePair <string, string> val = postcodes.Where(a => a.Key == rndsuburbname).SingleOrDefault(); if (val.Key != null) { postcode = val.Value; } MemberAddress address = new MemberAddress() { AddressLine1 = rndstreetname, AddressLine2 = "", Suburb = rndsuburbname, PostCode = postcode, State = "NSW", MemberID = currMember.ID }; return(address); }
// Use this to generate member addresses only. public void GenerateMemberAddresses() { List <Member> lmem = db.Members.ToList(); foreach (Member mem in lmem) { MemberAddress address = GenerateRandomMemberAddress(mem); db.MemberAddresses.Add(address); } db.SaveChanges(); }
// Use this to generate all membership sample data - Member, MemberDetails, MemberAddress public void GenerateMembers(int membersize) { for (int i = 0; i < membersize; i++) { Member member = GenerateRandomMember(); db.Members.Add(member); MemberDetails details = GenerateRandomMemberDetail(member); db.MemberDetails.Add(details); MemberAddress address = GenerateRandomMemberAddress(member); db.MemberAddresses.Add(address); } db.SaveChanges(); }