Ejemplo n.º 1
0
        public List <TransitNeighborhood> GetNeighborhoodsByLocation(string ticket, string country, string state, string city, ServiceQueryOptions options)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext     sec    = new ManagedSecurityContext(session, ticket);
                List <TransitNeighborhood> result = new List <TransitNeighborhood>();

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

                City t_city = ManagedCity.Find(session, city, state, country);

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

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

                return(WebServiceImpl <TransitNeighborhood, ManagedNeighborhood, Neighborhood> .GetTransformedList(
                           session, sec, cr.List <Neighborhood>()));
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
 public int MergeCitiesByName(string ticket, int target_id, string name, string state, string country)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session           = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedCity            m   = new ManagedCity(session, target_id);
         int result = m.Merge(sec, name, state, country);
         session.Flush();
         return(result);
     }
 }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        public string[] GetNeighborhoodsCompletionList(string prefixText, int count, string contextKey)
        {
            // TODO: manufacture a guest ticket and run this through WebServiceImpl

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

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

                int city_id = 0;
                if (!ManagedCity.TryGetCityId(session, context_parts[2], context_parts[1], context_parts[0], out city_id))
                {
                    return(null);
                }

                IList <Neighborhood> nhs = session.CreateCriteria(typeof(Neighborhood))
                                           .Add(Expression.Like("Name", string.Format("{0}%", Renderer.SqlEncode(prefixText))))
                                           .Add(Expression.Eq("City.Id", city_id))
                                           .AddOrder(Order.Asc("Name"))
                                           .SetMaxResults(count)
                                           .List <Neighborhood>();

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

                return(result.ToArray());
            }
        }
Ejemplo n.º 6
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
                {
                }
            }
        }
Ejemplo n.º 7
0
 public int MergeCitiesByName(string ticket, int target_id, string name, string state, string country)
 {
     using (SnCore.Data.Hibernate.Session.OpenConnection())
     {
         ISession session = SnCore.Data.Hibernate.Session.Current;
         ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
         ManagedCity m = new ManagedCity(session, target_id);
         int result = m.Merge(sec, name, state, country);
         session.Flush();
         return result;
     }
 }