PERMWebSolution.Models.Group.getGroupData C# (CSharp) Method

getGroupData() public method

Returns the data
public getGroupData ( int groupId ) : Group
groupId int
return Group
        public Group getGroupData(int groupId)
        {
            Group group = null;

            string sql = "SELECT [Users_Groups_Id], [Name], [Group_description], [Group_password] FROM [USERS_GROUPS] WHERE [USERS_User_Id] = @UserId AND [Users_Groups_Id] = @gruopId";
            var param = new Dictionary<string, object>();
            param.Add("@UserId", uId);
            param.Add("@gruopId", groupId);

            var result = DBContext.ExecuteQueryTable(sql, param);

            if (result != null && result.Rows.Count > 0)
            {

                    group = (new Group
                    {
                        groupId = Convert.ToInt16(result.Rows[0][0]),
                        groupName = Convert.ToString(result.Rows[0][1]),
                        groupDescription = Convert.ToString(result.Rows[0][2]),
                        groupPassword = Convert.ToString(result.Rows[0][3])
                    });

            }
            return group;
        }

Usage Example

 public IHttpActionResult getGroupData(int groupId)
 {
     IHttpActionResult ret = null;
     Group userGroups = new Group(UserSessionData.userId);
     Group group = userGroups.getGroupData(groupId);
     if (group != null)
     {
         ret = Ok(group);
     }
     else
     {
         ret = NotFound();
     }
     return ret;
 }