Exemple #1
0
        public void GetStateId()
        {
            ManagedCountry c = new ManagedCountry(Session);
            ManagedState   s = new ManagedState(Session);

            try
            {
                TransitCountry tc = new TransitCountry();
                tc.Name = GetNewString();
                TransitState ts = new TransitState();
                ts.Name    = GetNewString();
                ts.Country = tc.Name;

                c.CreateOrUpdate(tc, AdminSecurityContext);
                Session.Flush();
                s.CreateOrUpdate(ts, AdminSecurityContext);
                Session.Flush();
                ManagedState.GetStateId(Session, ts.Name, tc.Name);
            }
            finally
            {
                s.Delete(AdminSecurityContext);
                c.Delete(AdminSecurityContext);
            }
        }
Exemple #2
0
        public void CreateCity()
        {
            ManagedCountry c = new ManagedCountry(Session);
            ManagedState   t = new ManagedState(Session);
            ManagedCity    s = new ManagedCity(Session);

            try
            {
                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);
                Session.Flush();
            }
            finally
            {
                s.Delete(AdminSecurityContext);
                t.Delete(AdminSecurityContext);
                c.Delete(AdminSecurityContext);
            }
        }
Exemple #3
0
        public void GetCityIdInvalid()
        {
            ManagedCountry c = new ManagedCountry(Session);
            ManagedCity    s = new ManagedCity(Session);
            ManagedState   t = new ManagedState(Session);

            try
            {
                TransitCountry tc = new TransitCountry();
                tc.Name = GetNewString();
                TransitState tt = new TransitState();
                tt.Name    = GetNewString();
                tt.Country = tc.Name;

                c.CreateOrUpdate(tc, AdminSecurityContext);
                t.CreateOrUpdate(tt, AdminSecurityContext);
                Session.Flush();

                ManagedCity.GetCityId(Session, GetNewString(), tt.Name, tc.Name);
            }
            finally
            {
                t.Delete(AdminSecurityContext);
                c.Delete(AdminSecurityContext);
            }
        }
Exemple #4
0
        public string[] GetCitiesCompletionList(string prefixText, int count, string contextKey)
        {
            // TODO: manufacture a guest ticket and run this through WebServiceImpl

            // country;state
            string[] context_parts = contextKey.Split(";,|".ToCharArray(), 2);
            if (context_parts.Length != 2)
            {
                return(null);
            }

            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;

                int country_id = 0;
                if (!string.IsNullOrEmpty(context_parts[0]))
                {
                    if (!ManagedCountry.TryGetCountryId(session, context_parts[0], out country_id))
                    {
                        return(null);
                    }
                }

                int state_id = 0;
                if (!string.IsNullOrEmpty(context_parts[1]))
                {
                    if (!ManagedState.TryGetStateId(session, context_parts[1], context_parts[0], out state_id))
                    {
                        return(null);
                    }
                }

                ICriteria ic = session.CreateCriteria(typeof(City))
                               .Add(Expression.Like("Name", string.Format("{0}%", Renderer.SqlEncode(prefixText))));

                if (country_id != 0)
                {
                    ic.Add(Expression.Eq("Country.Id", country_id));
                }
                if (state_id != 0)
                {
                    ic.Add(Expression.Eq("State.Id", state_id));
                }

                IList <City> nhs = ic.AddOrder(Order.Asc("Name"))
                                   .SetMaxResults(count)
                                   .List <City>();

                List <string> result = new List <string>(nhs.Count);
                foreach (City nh in nhs)
                {
                    result.Add(nh.Name);
                }

                return(result.ToArray());
            }
        }
        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 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);
            }
        }
Exemple #7
0
        public void CreateManyAccounts(int count)
        {
            ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session);

            TransitCountry tc = new TransitCountry();

            tc.Name = Guid.NewGuid().ToString();
            TransitState ts = new TransitState();

            ts.Name    = Guid.NewGuid().ToString();
            ts.Country = tc.Name;

            ManagedCountry c = new ManagedCountry(Session);

            c.CreateOrUpdate(tc, sec);

            ManagedState s = new ManagedState(Session);

            s.CreateOrUpdate(ts, sec);

            TransitAccountAddress ta = new TransitAccountAddress();

            ta.Apt     = "123";
            ta.City    = "New York";
            ta.Country = tc.Name;
            ta.Name    = "My Address";
            ta.State   = ts.Name;
            ta.Street  = "Houston St.";
            ta.Zip     = "10001";

            for (int i = 0; i < count; i++)
            {
                ManagedAccount a    = new ManagedAccount(Session);
                string         name = Guid.NewGuid().ToString();
                a.Create(
                    name,
                    "password",
                    string.Format("{0}@localhost.com", name),
                    DateTime.UtcNow,
                    sec);

                ManagedAccountAddress ma = new ManagedAccountAddress(Session);
                ma.CreateOrUpdate(ta, a.GetSecurityContext());
            }
        }
        public List <TransitCity> GetCitiesByLocation(string ticket, string country, string state, ServiceQueryOptions options)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session              = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec    = new ManagedSecurityContext(session, ticket);
                List <TransitCity>     result = new List <TransitCity>();

                if (string.IsNullOrEmpty(country))
                {
                    return(result);
                }

                Country t_country = ManagedCountry.Find(session, country);

                ICriteria cr = session.CreateCriteria(typeof(City))
                               .Add(Expression.Eq("Country.Id", t_country.Id));

                if (t_country.States != null && t_country.States.Count > 0 && string.IsNullOrEmpty(state))
                {
                    // no state specified but country has states
                    return(result);
                }

                if (!string.IsNullOrEmpty(state))
                {
                    // state specified
                    State t_state = ManagedState.Find(session, state, country);
                    cr.Add(Expression.Eq("State.Id", t_state.Id));
                }

                if (options != null)
                {
                    cr.SetFirstResult(options.FirstResult);
                    cr.SetMaxResults(options.PageSize);
                }

                return(WebServiceImpl <TransitCity, ManagedCity, City> .GetTransformedList(
                           session, sec, cr.List <City>()));
            }
        }
        public void CreateManyAccounts(int count)
        {
            ManagedSecurityContext sec = ManagedAccount.GetAdminSecurityContext(Session);

            TransitCountry tc = new TransitCountry();
            tc.Name = Guid.NewGuid().ToString();
            TransitState ts = new TransitState();
            ts.Name = Guid.NewGuid().ToString();
            ts.Country = tc.Name;

            ManagedCountry c = new ManagedCountry(Session);
            c.CreateOrUpdate(tc, sec);

            ManagedState s = new ManagedState(Session);
            s.CreateOrUpdate(ts, sec);

            TransitAccountAddress ta = new TransitAccountAddress();
            ta.Apt = "123";
            ta.City = "New York";
            ta.Country = tc.Name;
            ta.Name = "My Address";
            ta.State = ts.Name;
            ta.Street = "Houston St.";
            ta.Zip = "10001";

            for (int i = 0; i < count; i++)
            {

                ManagedAccount a = new ManagedAccount(Session);
                string name = Guid.NewGuid().ToString();
                a.Create(
                    name,
                    "password",
                    string.Format("{0}@localhost.com", name),
                    DateTime.UtcNow, 
                    sec);

                ManagedAccountAddress ma = new ManagedAccountAddress(Session);
                ma.CreateOrUpdate(ta, a.GetSecurityContext());
            }
        }
Exemple #10
0
        public void CreateAccountAddress()
        {
            ManagedAccount a = new ManagedAccount(Session);
            ManagedCountry c = new ManagedCountry(Session);
            ManagedState   s = new ManagedState(Session);

            try
            {
                a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext);

                TransitCountry tc = new TransitCountry();
                tc.Name = GetNewString();
                TransitState ts = new TransitState();
                ts.Name    = GetNewString();
                ts.Country = tc.Name;

                c.CreateOrUpdate(tc, AdminSecurityContext);
                s.CreateOrUpdate(ts, AdminSecurityContext);

                TransitAccountAddress ta = new TransitAccountAddress();
                ta.Apt     = "123";
                ta.City    = "New York";
                ta.Country = tc.Name;
                ta.Name    = "My Address";
                ta.State   = ts.Name;
                ta.Street  = "Houston St.";
                ta.Zip     = "10001";

                ManagedAccountAddress m_a = new ManagedAccountAddress(Session);
                m_a.CreateOrUpdate(ta, new ManagedSecurityContext(a.Instance));
            }
            finally
            {
                a.Delete(AdminSecurityContext);
                s.Delete(AdminSecurityContext);
                c.Delete(AdminSecurityContext);
                Session.Flush();
            }
        }
        public void CreateAccountAddress()
        {
            ManagedAccount a = new ManagedAccount(Session);
            ManagedCountry c = new ManagedCountry(Session);
            ManagedState s = new ManagedState(Session);

            try
            {
                a.Create("Test User", "testpassword", "*****@*****.**", DateTime.UtcNow, AdminSecurityContext);

                TransitCountry tc = new TransitCountry();
                tc.Name = GetNewString();
                TransitState ts = new TransitState();
                ts.Name = GetNewString();
                ts.Country = tc.Name;

                c.CreateOrUpdate(tc, AdminSecurityContext);
                s.CreateOrUpdate(ts, AdminSecurityContext);

                TransitAccountAddress ta = new TransitAccountAddress();
                ta.Apt = "123";
                ta.City = "New York";
                ta.Country = tc.Name;
                ta.Name = "My Address";
                ta.State = ts.Name;
                ta.Street = "Houston St.";
                ta.Zip = "10001";

                ManagedAccountAddress m_a = new ManagedAccountAddress(Session);
                m_a.CreateOrUpdate(ta, new ManagedSecurityContext(a.Instance));
            }
            finally
            {
                a.Delete(AdminSecurityContext);
                s.Delete(AdminSecurityContext);
                c.Delete(AdminSecurityContext);
                Session.Flush();
            }
        }
Exemple #12
0
        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
                {
                }
            }
        }