예제 #1
0
        public List <User> GetAllUsersOfGroup(int groupId, List <SortCollection> sorted, int?skip, int?take, string searchKey, List <FilterCollection> filterCollection, out int usersCount)
        {
            var userResult       = new List <User>();
            var searchDescriptor = new List <String> {
                "DisplayName", "Email"
            };

            try
            {
                var selected = new List <SelectedColumn>
                {
                    new SelectedColumn
                    {
                        TableName  = GlobalAppSettings.DbColumns.DB_User.DB_TableName,
                        ColumnName = "*"
                    },
                    new SelectedColumn
                    {
                        TableName  = GlobalAppSettings.DbColumns.DB_UserGroup.DB_TableName,
                        ColumnName = GlobalAppSettings.DbColumns.DB_UserGroup.GroupId
                    },
                    new SelectedColumn
                    {
                        TableName  = GlobalAppSettings.DbColumns.DB_UserGroup.DB_TableName,
                        ColumnName = GlobalAppSettings.DbColumns.DB_UserGroup.UserId
                    }
                };
                var joinSpecification = new List <JoinSpecification>
                {
                    new JoinSpecification
                    {
                        Table  = GlobalAppSettings.DbColumns.DB_User.DB_TableName,
                        Column =
                            new List <JoinColumn>
                        {
                            new JoinColumn
                            {
                                TableName         = GlobalAppSettings.DbColumns.DB_User.DB_TableName,
                                JoinedColumn      = GlobalAppSettings.DbColumns.DB_User.UserId,
                                Operation         = Conditions.Equals,
                                ParentTableColumn = GlobalAppSettings.DbColumns.DB_UserGroup.UserId,
                                ParentTable       = GlobalAppSettings.DbColumns.DB_UserGroup.DB_TableName
                            }
                        },
                        JoinType = JoinTypes.Inner
                    }
                };
                var whereColumns = new List <ConditionColumn>
                {
                    new ConditionColumn
                    {
                        TableName  = GlobalAppSettings.DbColumns.DB_UserGroup.DB_TableName,
                        ColumnName = GlobalAppSettings.DbColumns.DB_UserGroup.GroupId,
                        Condition  = Conditions.Equals,
                        Value      = groupId
                    },
                    new ConditionColumn
                    {
                        TableName       = GlobalAppSettings.DbColumns.DB_UserGroup.DB_TableName,
                        ColumnName      = GlobalAppSettings.DbColumns.DB_UserGroup.IsActive,
                        Condition       = Conditions.Equals,
                        LogicalOperator = LogicalOperators.AND,
                        Value           = true
                    }
                };
                var query = _queryBuilder.ApplyWhereClause(
                    _queryBuilder.ApplyMultipleJoins(GlobalAppSettings.DbColumns.DB_UserGroup.DB_TableName, selected,
                                                     joinSpecification), whereColumns);
                var result =
                    _dataProvider.ExecuteReaderQuery(FilteringHelper(query, searchKey, filterCollection, sorted, searchDescriptor));
                if (result.Status)
                {
                    var userList =
                        result.DataTable.AsEnumerable()
                        .Select(row => new User
                    {
                        UserId       = row.Field <int>(GlobalAppSettings.DbColumns.DB_User.UserId),
                        UserName     = row.Field <string>(GlobalAppSettings.DbColumns.DB_User.UserName),
                        FirstName    = row.Field <string>(GlobalAppSettings.DbColumns.DB_User.FirstName),
                        LastName     = row.Field <string>(GlobalAppSettings.DbColumns.DB_User.LastName),
                        DisplayName  = row.Field <string>(GlobalAppSettings.DbColumns.DB_User.DisplayName),
                        Email        = row.Field <string>(GlobalAppSettings.DbColumns.DB_User.Email),
                        Avatar       = row.Field <string>(GlobalAppSettings.DbColumns.DB_User.Picture),
                        CreatedDate  = row.Field <DateTime>(GlobalAppSettings.DbColumns.DB_User.CreatedDate),
                        ModifiedDate = row.Field <DateTime>(GlobalAppSettings.DbColumns.DB_User.ModifiedDate)
                    });

                    usersCount = userList.ToList().Count;
                    if (!String.IsNullOrWhiteSpace(skip.ToString()) && !String.IsNullOrWhiteSpace(take.ToString()))
                    {
                        userResult = userList.Skip(Convert.ToInt32(skip)).Take(Convert.ToInt32(take)).ToList();
                    }
                    else
                    {
                        userResult = userList.ToList();
                    }
                }
                else
                {
                    usersCount = 0;
                }
                return(userResult);
            }
            catch (Exception e)
            {
                LogExtension.LogError("Error while getting user list of group", e,
                                      MethodBase.GetCurrentMethod(), " GroupId - " + groupId + " SearchKey - " + searchKey);
                usersCount = 0;
                return(userResult);
            }
        }