public void CreateManyPlaces(int count) { Random r = new Random(); ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session); // country TransitCountry t_country = new TransitCountry(); t_country.Name = Guid.NewGuid().ToString(); ManagedCountry country = new ManagedCountry(Session); country.CreateOrUpdate(t_country, sec); // state TransitState t_state = new TransitState(); t_state.Name = Guid.NewGuid().ToString(); t_state.Country = t_country.Name; ManagedState state = new ManagedState(Session); state.CreateOrUpdate(t_state, sec); // city TransitCity t_city = new TransitCity(); t_city.Name = Guid.NewGuid().ToString(); t_city.State = t_state.Name; t_city.Country = t_country.Name; ManagedCity city = new ManagedCity(Session); city.CreateOrUpdate(t_city, sec); // place type TransitPlaceType t_placetype = new TransitPlaceType(); t_placetype.Name = Guid.NewGuid().ToString(); ManagedPlaceType placetype = new ManagedPlaceType(Session); placetype.CreateOrUpdate(t_placetype, sec); for (int i = 0; i < count; i++) { TransitPlace t_place = new TransitPlace(); t_place.Name = Guid.NewGuid().ToString(); t_place.AccountId = sec.Account.Id; t_place.City = t_city.Name; t_place.Country = t_country.Name; t_place.State = t_state.Name; t_place.Street = string.Format("{0} {1} St.", r.Next(), Guid.NewGuid().ToString()); t_place.Zip = r.Next().ToString(); t_place.Type = t_placetype.Name; ManagedPlace place = new ManagedPlace(Session); place.CreateOrUpdate(t_place, sec); } }
public void CreatePlace() { ManagedPlaceType type = new ManagedPlaceType(Session); ManagedCountry c = new ManagedCountry(Session); ManagedState t = new ManagedState(Session); ManagedCity s = new ManagedCity(Session); ManagedAccount a = new ManagedAccount(Session); try { a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext); a.VerifyAllEmails(); a.AddDefaultPicture(); TransitCountry tc = new TransitCountry(); tc.Name = GetNewString(); TransitState tt = new TransitState(); tt.Name = GetNewString(); tt.Country = tc.Name; TransitCity ts = new TransitCity(); ts.Name = GetNewString(); ts.Country = tc.Name; ts.State = tt.Name; c.CreateOrUpdate(tc, AdminSecurityContext); t.CreateOrUpdate(tt, AdminSecurityContext); s.CreateOrUpdate(ts, AdminSecurityContext); TransitPlaceType t_type = new TransitPlaceType(); t_type.Name = GetNewString(); type.CreateOrUpdate(t_type, AdminSecurityContext); TransitPlace t_place = new TransitPlace(); t_place.Name = GetNewString(); t_place.Type = t_type.Name; t_place.City = ts.Name; t_place.Country = tc.Name; t_place.State = tt.Name; t_place.AccountId = a.Id; ManagedPlace m_place = new ManagedPlace(Session); m_place.CreateOrUpdate(t_place, a.GetSecurityContext()); } finally { try { a.Delete(AdminSecurityContext); type.Delete(AdminSecurityContext); s.Delete(AdminSecurityContext); t.Delete(AdminSecurityContext); c.Delete(AdminSecurityContext); } catch { } } }