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

getGroups() public method

Method returns list of user groups
public getGroups ( ) : List
return List
        public List<Group> getGroups()
        {
            List<Group> groups = new List<Group>();

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

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

            if (result != null && result.Rows.Count > 0)
            {
                for (int i = 0; i < result.Rows.Count; i++)
                {
                    groups.Add(new Group
                    {
                        groupId = Convert.ToInt16(result.Rows[i][0]),
                        groupName = Convert.ToString(result.Rows[i][1]),
                        groupDescription = Convert.ToString(result.Rows[i][2]),
                        groupPassword = Convert.ToString(result.Rows[i][3])
                    });
                }
            }
            return groups;
        }

Usage Example

Ejemplo n.º 1
0
 public IHttpActionResult getGroups()
 {
     IHttpActionResult ret = null;
     Group userGroups = new Group(UserSessionData.userId);
     List<Group> groups = userGroups.getGroups();
     if (groups.Any() || groups.Count == 0)
     {
         ret = Ok(groups);
     }
     else
     {
         ret = NotFound();
     }
     return ret;
 }