Esempio n. 1
0
        /// <summary>
        /// Adds group to database.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="groupId"></param>
        /// <param name="groupName"></param>
        public void AddGroup(User user, Group group)
        {
            using (var conn = this.Connection)
            using (var cmd = new InsertCommand("INSERT INTO `groups` {0}", conn))
            {
                cmd.Set("groupId", group.Id);
                cmd.Set("contactId", user.Id);
                cmd.Set("name", group.Name);

                cmd.Execute();
            }
        }
Esempio n. 2
0
		/// <summary>
		/// Returns list of all groups in user's friend list.
		/// </summary>
		/// <param name="user"></param>
		/// <returns></returns>
		public ICollection<Group> GetGroups(User user)
		{
			var result = new Dictionary<int, Group>();

			using (var conn = this.Connection)
			using (var mc = new MySqlCommand("SELECT * FROM `groups` WHERE `contactId` = @contactId", conn))
			{
				mc.Parameters.AddWithValue("@contactId", user.Id);

				using (var reader = mc.ExecuteReader())
				{
					while (reader.Read())
					{
						var group = new Group();
						group.Id = reader.GetInt32("groupId");
						group.Name = reader.GetStringSafe("name");

						// Override duplicate ids
						result[group.Id] = group;
					}
				}
			}

			return result.Values;
		}
Esempio n. 3
0
		/// <summary>
		/// Returns list of all groups in user's friend list.
		/// </summary>
		/// <param name="user"></param>
		/// <returns></returns>
		public List<Group> GetGroups(User user)
		{
			var result = new List<Group>();

			using (var conn = this.Connection)
			using (var mc = new MySqlCommand("SELECT * FROM `groups` WHERE `contactId` = @contactId", conn))
			{
				mc.Parameters.AddWithValue("@contactId", user.Id);

				using (var reader = mc.ExecuteReader())
				{
					while (reader.Read())
					{
						var group = new Group();
						group.Id = reader.GetInt32("groupId");
						group.Name = reader.GetStringSafe("name");

						result.Add(group);
					}
				}
			}

			return result;
		}