Ejemplo n.º 1
0
        public List<TransitPlacePropertyValue> GetAllPlacePropertyValuesById(string ticket, int placeid, int groupid)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

                ICriteria c = session.CreateCriteria(typeof(PlaceProperty));
                if (groupid > 0) c.Add(Expression.Eq("PlacePropertyGroup.Id", groupid));
                IList properties = c.List();

                List<TransitPlacePropertyValue> result = new List<TransitPlacePropertyValue>(properties.Count);

                foreach (PlaceProperty property in properties)
                {
                    PlacePropertyValue value = (PlacePropertyValue)session.CreateCriteria(typeof(PlacePropertyValue))
                        .Add(Expression.Eq("Place.Id", placeid))
                        .Add(Expression.Eq("PlaceProperty.Id", property.Id))
                        .UniqueResult();

                    if (value == null)
                    {
                        value = new PlacePropertyValue();
                        value.PlaceProperty = property;
                        value.Value = property.DefaultValue;
                        if (placeid > 0) value.Place = session.Load<Place>(placeid);
                    }

                    ManagedPlacePropertyValue m_ppv = new ManagedPlacePropertyValue(session, value);
                    result.Add(m_ppv.GetTransitInstance(sec));
                }

                return result;
            }
        }
Ejemplo n.º 2
0
        public TransitPlacePropertyValue GetPlacePropertyValueByName(string ticket, int placeid, string groupname, string propertyname)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;

                PlacePropertyGroup ppg = (PlacePropertyGroup)session.CreateCriteria(typeof(PlacePropertyGroup))
                    .Add(Expression.Eq("Name", groupname))
                    .UniqueResult();

                if (ppg == null)
                {
                    throw new Exception(string.Format(
                        "No property group with the name \"{0}\" found.", groupname));
                }

                PlaceProperty pp = (PlaceProperty)session.CreateCriteria(typeof(PlaceProperty))
                    .Add(Expression.Eq("Name", propertyname))
                    .Add(Expression.Eq("PlacePropertyGroup.Id", ppg.Id))
                    .UniqueResult();

                if (pp == null)
                {
                    throw new Exception(string.Format(
                        "No property with the name \"{0}\" found.", propertyname));
                }

                PlacePropertyValue ppv = (PlacePropertyValue)session.CreateCriteria(typeof(PlacePropertyValue))
                    .Add(Expression.Eq("Place.Id", placeid))
                    .Add(Expression.Eq("PlaceProperty.Id", pp.Id))
                    .UniqueResult();

                if (ppv == null)
                {
                    throw new Exception(string.Format(
                        "No property value for \"{0}\" of place \"{0}\" of group \"{0}\" found.",
                        propertyname, placeid, groupname));
                }

                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);
                TransitPlacePropertyValue result = new ManagedPlacePropertyValue(session, ppv).GetTransitInstance(sec);
                return result;
            }
        }