/// <summary>
        /// Returns the contact information for a particular user.
        /// </summary>
        /// <param name="accountId"></param>
        /// <returns></returns>
        public Dictionary<string, List<MembershipAttribute>> GetContacts(
            Guid accountId)
        {
            Dictionary<string, List<MembershipAttribute>> contacts = new Dictionary<string,List<MembershipAttribute>>();

            SQLiteConnection conn = null;
            SQLiteCommand cmd = null;
            SQLiteDataReader dr = null;

            try {
                conn = (SQLiteConnection)this.GetConnection();
                cmd = new SQLiteCommand();

                string sqlText = "select mc.contact_id, mc.contact_type_id, mc.contact_value " +
                                    "from member_contact mc " +
                                        "join member_account_contact macc on macc.contact_id = mc.contact_id " +
                                    "where macc.account_id = @accountId";

                cmd.Parameters.AddWithValue("@accountId", accountId);
                cmd.CommandText = sqlText;
                cmd.Connection = conn;

                cmd.Connection.Open();

                dr = cmd.ExecuteReader();

                while (dr.Read()) {
                            //read in info
                    int		typeId			= DbUtil.getIntValue(dr, "contact_type_id");
                    int		contactId		= DbUtil.getIntValue(dr, "contact_id");
                    string	contactValue	= DbUtil.getStringValue(dr, "contact_value");
                    string	contactTypeCode	= SingletonBase<ContactType>.GetInstance()[typeId].Code;

                            //create the contact
                    MembershipAttribute attr = new MembershipAttribute(contactId, contactTypeCode, typeId, contactValue);

                            //check if the contact type already exists, if not create it
                    if (contacts.ContainsKey(contactTypeCode)) {
                                //if exists, add the attribute to the list
                        contacts[contactTypeCode].Add(attr);
                    } else {
                        List<MembershipAttribute> attrList = new List<MembershipAttribute>();
                        attrList.Add(attr);
                        contacts.Add(contactTypeCode, attrList);
                    }
                }

            } catch (Exception e) {
                logger.Error("SQLiteAccountDAO:GetContacts: ", e);
            }
            finally {
                DbUtil.close((cmd == null) ? null : cmd.Connection, cmd, dr);
            }

            return contacts;
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the attributes for a particular user.
        /// </summary>
        /// <param name="accountId"></param>
        /// <returns></returns>
        public Dictionary<string, List<MembershipAttribute>> GetAttributes(
            Guid accountId)
        {
            Dictionary<string,List<MembershipAttribute>> attributes = new Dictionary<string,List<MembershipAttribute>>();

            SqlConnection	conn	= null;
            SqlCommand		cmd		= null;
            SqlDataReader	dr		= null;

            try {
                conn	= (SqlConnection)this.GetConnection();
                cmd		= new SqlCommand();

                string sqlText = "select maat.account_attribute_type_id, maat.account_attribute_value " +
                                    "from member_account_attribute maat " +
                                    "where maat.account_id = @accountId";

                cmd.Parameters.AddWithValue("@accountId", accountId);
                cmd.CommandText = sqlText;
                cmd.Connection = conn;

                cmd.Connection.Open();

                dr = cmd.ExecuteReader();

                while (dr.Read()) {
                            //read in info
                    int		typeId				= DbUtil.getIntValue(dr, "account_attribute_type_id");
                    string	attributeValue		= DbUtil.getStringValue(dr, "account_attribute_value");
                    string	attributeTypeCode	= SingletonBase<AccountAttributeType>.GetInstance()[typeId].Code;

                            //create the attribute
                    MembershipAttribute attr = new MembershipAttribute(null, attributeTypeCode, typeId, attributeValue);
                    //attr.TypeId = typeId;

                            //check if the attribute type already exists, if not create it
                    if (attributes.ContainsKey(attributeTypeCode)) {
                                //if exists, add the attribute to the list
                        attributes[attributeTypeCode].Add(attr);
                    } else {
                        List<MembershipAttribute> attrList = new List<MembershipAttribute>();
                        attrList.Add(attr);
                        attributes.Add(attributeTypeCode, attrList);
                    }
                }

            } catch (Exception e) {
                logger.Error("MSAccountDAO:GetAttributes: ", e);
            } finally {
                DbUtil.close((cmd == null) ? null : cmd.Connection, cmd, dr);
            }

            return attributes;
        }