コード例 #1
0
ファイル: WebAccountService.cs プロジェクト: dblock/sncore
        public List<TransitAccountPropertyValue> GetAllAccountPropertyValues(string ticket, int accountid, 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(AccountProperty));
                if (groupid > 0) c.Add(Expression.Eq("AccountPropertyGroup.Id", groupid));
                IList properties = c.List();

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

                foreach (AccountProperty property in properties)
                {
                    AccountPropertyValue value = (AccountPropertyValue)session.CreateCriteria(typeof(AccountPropertyValue))
                        .Add(Expression.Eq("Account.Id", accountid))
                        .Add(Expression.Eq("AccountProperty.Id", property.Id))
                        .UniqueResult();

                    if (value == null)
                    {
                        value = new AccountPropertyValue();
                        value.AccountProperty = property;
                        value.Value = property.DefaultValue;
                        value.Account = session.Load<Account>(accountid);
                    }

                    ManagedAccountPropertyValue m_instance = new ManagedAccountPropertyValue(session, value);
                    result.Add(m_instance.GetTransitInstance(sec));
                }

                return result;
            }
        }
コード例 #2
0
ファイル: WebAccountService.cs プロジェクト: dblock/sncore
        public TransitAccountPropertyValue GetAccountPropertyValueByName(string ticket, int accountid, string groupname, string propertyname)
        {
            using (SnCore.Data.Hibernate.Session.OpenConnection())
            {
                ISession session = SnCore.Data.Hibernate.Session.Current;
                ManagedSecurityContext sec = new ManagedSecurityContext(session, ticket);

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

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

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

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

                AccountPropertyValue ppv = (AccountPropertyValue)session.CreateCriteria(typeof(AccountPropertyValue))
                    .Add(Expression.Eq("Account.Id", accountid))
                    .Add(Expression.Eq("AccountProperty.Id", pp.Id))
                    .UniqueResult();

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

                ManagedAccountPropertyValue result = new ManagedAccountPropertyValue(session, ppv);
                return result.GetTransitInstance(sec);
            }
        }