/// <summary>
        /// リクエストから条件入力インスタンスを取得
        /// </summary>
        /// <param name="src">リクエスト</param>
        /// <returns>条件入力インスタンス</returns>
        private UserSearchCondition getUserSearchCondition(Newtonsoft.Json.Linq.JObject src)
        {
            var searchCondition = new UserSearchCondition();

            Newtonsoft.Json.Linq.JToken jsonToken = null;

            var paramName = string.Empty;

            // パラメータの設定
            paramName = "searchUserId";
            if (src.TryGetValue(paramName, out jsonToken))
            {
                searchCondition.SearchUserId = src[paramName].ToString();
            }
            paramName = "pageIndex";
            if (src.TryGetValue(paramName, out jsonToken))
            {
                searchCondition.PageIndex = (int)src[paramName];
            }
            paramName = "sortKey";
            if (src.TryGetValue(paramName, out jsonToken))
            {
                searchCondition.SortKey = src[paramName].ToString();
            }
            paramName = "sortType";
            if (src.TryGetValue(paramName, out jsonToken))
            {
                searchCondition.SortType = src[paramName].ToString();
            }

            return(searchCondition);
        }
        /// <summary>
        /// 検索結果のレコード件数を取得する
        /// </summary>
        /// <param name="seachCondition">検索条件</param>
        /// <returns>レコード数</returns>
        public int GetRecordCount(UserSearchCondition seachCondition)
        {
            var sql = new StringBuilder();

            sql.AppendLine("select");
            sql.AppendLine("  cast(count(USER_ID) as int) CNT");
            sql.AppendLine("from");
            sql.AppendLine("  MT_USER");

            // Param設定
            db.ClearParam();
            if (!string.IsNullOrEmpty(seachCondition.SearchUserId))
            {
                sql.AppendLine("where ");
                sql.AppendLine("  USER_ID like @USER_ID");
                db.AddParam("@USER_ID", string.Format("%{0}%", seachCondition.SearchUserId));
            }

            int recordCount = -1;
            var result      = db.Fill(sql.ToString());

            if (result.Rows.Count > 0)
            {
                int.TryParse(result.Rows[0]["CNT"].ToString(), out recordCount);
            }

            // レコード件数を返す
            return(recordCount);
        }
Esempio n. 3
0
 public int GetUserCountByCondition(UserSearchCondition condition)
 {
     try
     {
         var query = _userRepository.Table;
         if (condition.BeginTime.HasValue)
         {
             query = query.Where(c => c.RegTime >= condition.BeginTime.Value);
         }
         if (condition.EndTime.HasValue)
         {
             query = query.Where(c => c.RegTime < condition.EndTime.Value);
         }
         if (condition.Status.HasValue)
         {
             query = query.Where(c => c.Status == condition.Status);
         }
         if (condition.Ids != null && condition.Ids.Length > 0)
         {
             query = query.Where(c => condition.Ids.Contains(c.Id));
         }
         if (!string.IsNullOrEmpty(condition.UserName))
         {
             query = query.Where(c => c.UserName.Contains(condition.UserName));
         }
         return(query.Count());
     }
     catch (Exception e)
     {
         _log.Error(e, "获取用户列表失败");
         return(-1);
     }
 }
Esempio n. 4
0
        public static string CompleteConditionString(UserSearchCondition conditions)
        {
            List <UserFilter> list = conditions.filters;

            if (list.Count == 0)
            {
                return(String.Empty);
            }
            for (int i = list.Count - 1; i < -1; i -= 1)
            {
                if (String.IsNullOrEmpty(list[i].field))
                {
                    list.RemoveAt(i);
                }
            }
            StringBuilder str = new StringBuilder();

            foreach (var x in list)
            {
                str.Append(" ");
                str.Append(GetConditionString(x));
            }
            string y = str.ToString().Trim();

            return(y[3..].Trim());
Esempio n. 5
0
        public int SearchListCount(UserSearchCondition condition)
        {
            var query = context.Query <UserMySql>();
            var count = query.Count();

            return(count);
        }
Esempio n. 6
0
        public List <UserMySql> SearchList(UserSearchCondition condition)
        {
            var query = context.Query <UserMySql>();
            var list  = query.Where(a => !string.IsNullOrEmpty(a.ID)).OrderBy(a => a.ID).Skip(condition.PageIndex).Take(condition.PageSize).ToList();

            return(list);
        }
Esempio n. 7
0
        public PageList <UserModel> SearchUsers(UserSearchCondition condition)
        {
            var query = _shoppingContext.Users.AsNoTracking().AsQueryable();

            if (!string.IsNullOrEmpty(condition.UserName))
            {
                query = query.Where(p => p.UserName.ToLower().Contains(condition.UserName.ToLower()));
            }

            if (condition.GroupUserId > 0)
            {
                query = query.Where(p => p.GroupUserId == condition.GroupUserId);
            }

            if (condition.Status.HasValue)
            {
                query = query.Where(p => p.Status == condition.Status.Value);
            }

            if (condition.DateFrom.HasValue)
            {
                query = query.Where(p => p.CreatedDateTime >= condition.DateFrom.Value);
            }

            if (condition.DateTo.HasValue)
            {
                var dateTo = condition.DateTo.Value.AddDays(1);
                query = query.Where(p => p.CreatedDateTime < dateTo);
            }
            var users = query.OrderBy(o => o.CreatedDateTime).Skip(condition.PageSize * condition.PageNumber).Take(condition.PageSize).ToList();

            return(new PageList <UserModel>(Mapper.Map <List <UserModel> >(users), query.Count()));
        }
Esempio n. 8
0
 public void SearchListMethod()
 {
     var condition = new UserSearchCondition {
         PageIndex = 1,
         PageSize  = 10,
     };
     var result = Hubert.Service.System.UserService.Instance.SearchList(condition);
 }
Esempio n. 9
0
 public int SearchListCount(UserSearchCondition condition)
 {
     using (var context = new MySqlDbContext())
     {
         var count = context.UserMySql.Count();
         return(count);
     }
 }
Esempio n. 10
0
 public List <UserMySql> SearchList(UserSearchCondition condition)
 {
     using (var context = new MySqlDbContext())
     {
         var list = context.UserMySql.OrderByDescending(m => m.ID).Skip(condition.PageIndex).Take(condition.PageSize).ToList();
         return(list);
     }
 }
        public IActionResult DownloadHeaderCSVJS([FromBody] Dictionary <string, object> param)
        {
            // ログインチェック
            if (!isLogin(param))
            {
                return(Unauthorized());
            }

            var searchCondition = new UserSearchCondition();

            if (param.ContainsKey("requestData"))
            {
                // パラメータの設定
                var requestData = param["requestData"] as Newtonsoft.Json.Linq.JObject;
                searchCondition = getUserSearchCondition(requestData);
            }

            var csvData = new System.Text.StringBuilder();

            try
            {
                // データ取得とCSV文字列取得
                var models    = service.GetAllUsers(searchCondition);
                var generator = new CSVGenerator <UserModel>();
                foreach (var model in models)
                {
                    generator.Add(model);
                }
                csvData.AppendLine(generator.GetCSV(true, getDownloadColumnUserModel()));
            }
            catch (Exception ex)
            {
                logger.LogCritical("{0}", ex.Message);
                return(BadRequest());
            }

            var status  = ResponseDTO.Results.OK;
            var message = string.Empty;
            var data    = new Dictionary <string, string>();

            if (csvData.Length > 0)
            {
                data.Add("csv", csvData.ToString());

                // サンプルのファイル名
                string fileName = string.Format("テスト_{0:yyyyMMddHHmmss}.csv", DateTime.Now);
                fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
                data.Add("filename", fileName);
            }
            else
            {
                status  = ResponseDTO.Results.NG;
                message = SearchResultZero;
            }

            return(Json(new ResponseDTO(status, message, data)));
        }
Esempio n. 12
0
        /// <summary>
        /// ユーザーのページ分を取得する
        /// </summary>
        /// <param name="seachCondition">検索条件</param>
        /// <param name="pageCount">1ページ当たりの係数</param>
        /// <returns>ユーザーのリスト</returns>
        public List <UserModel> GetUsers(UserSearchCondition seachCondition, int pageCount)
        {
            var sql = new StringBuilder();

            sql.AppendLine("select * from MT_USER ");

            // 検索条件
            int    pageIndex    = seachCondition.PageIndex;
            string searchUserId = seachCondition.SearchUserId;

            // ソートキー
            var sortKeys = new Dictionary <string, string>();

            sortKeys.Add("ID", "USER_ID");
            sortKeys.Add("NAME", "USER_NAME");
            sortKeys.Add("REMOVE", "DEL_FLAG");

            string sortKey = "USER_ID ";

            if (sortKeys.ContainsKey(seachCondition.SortKey))
            {
                sortKey = sortKeys[seachCondition.SortKey] + " ";
            }
            if (!string.IsNullOrEmpty(seachCondition.SortType))
            {
                string tempType = seachCondition.SortType.ToUpper();

                if (new string[] { "ASC", "DESC" }.Any((sortType) => { return(sortType == tempType); }))
                {
                    sortKey += tempType;
                }
            }

            // パラメータの設定
            db.ClearParam();
            if (!string.IsNullOrEmpty(seachCondition.SearchUserId))
            {
                sql.AppendLine("where ");
                sql.AppendLine("  USER_ID like @USER_ID");
                db.AddParam("@USER_ID", string.Format("%{0}%", seachCondition.SearchUserId));
            }
            sql.AppendLine(string.Format(" ORDER BY {0}", sortKey));
            sql.AppendLine(string.Format("LIMIT {0} OFFSET {1}", pageCount, pageIndex * pageCount));

            // SQL発行
            var result   = new List <UserModel>();
            var dbResult = db.Fill(sql.ToString());

            foreach (DataRow row in dbResult.Rows)
            {
                result.Add(createUserModel(row, false));
            }

            return(result);
        }
Esempio n. 13
0
        public int SearchListCount(UserSearchCondition condition)
        {
            StringBuilder sql = new StringBuilder(@"
SELECT COUNT(0) Total FROM dbo.[User]
");

            using (IDbConnection conn = DapperContext.GetSqlConnection())
            {
                return(conn.Query <User>(sql.ToString(), null).ToList().Count());
            }
        }
Esempio n. 14
0
        public ActionResult List()
        {
            var currentUser = Session[Values.USER_SESSION] as UserModel;

            if (currentUser.GroupUserId != (int)UserRole.Admin)
            {
                return(RedirectToAction("UnAuthorize", "Exception"));
            }
            var model = new UserSearchCondition();

            return(View(model));
        }
Esempio n. 15
0
        public async Task <IActionResult> DownloadAllUser([FromBody] UserSearchCondition conditionSet)
        {
            long           _pageSize    = 100;
            long           _requestPage = 1;
            UserCollection _obj         = await dal.listAllUserWithPaging(_pageSize, _requestPage, conditionSet, "yes");

            if (_obj.status != "000")
            {
                return(NotFound(_obj));
            }
            return(Ok(_obj));
        }
Esempio n. 16
0
        public async Task <IActionResult> ListAllUser([FromBody] UserSearchCondition conditionSet)
        {
            long           _pageSize    = conditionSet.pageSize <= 0 ? DefautltPageSize : conditionSet.pageSize;
            long           _requestPage = conditionSet.requestPage <= 0 ? DefaultRequestPage : conditionSet.requestPage;
            UserCollection _obj         = await dal.listAllUserWithPaging(_pageSize, _requestPage, conditionSet, "no");

            if (_obj.status != "000")
            {
                return(NotFound(_obj));
            }
            return(Ok(_obj));
        }
Esempio n. 17
0
        public ActionResult List(DataSourceRequest command, UserSearchCondition condition)
        {
            condition.PageSize   = command.PageSize;
            condition.PageNumber = command.Page - 1;

            var users     = _userService.SearchUsers(condition);
            var gridModel = new DataSourceResult()
            {
                Data  = users.DataSource,
                Total = users.TotalItems
            };

            return(Json(gridModel));
        }
        public HttpResponseMessage SearchUserCustomer(UserSearchCondition userSearchConditionEntity)
        {
            try
            {
                SearchResultObject <UserSearchResult> result = _userBusiness.SearchUserCustomer(userSearchConditionEntity);

                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex.InnerException);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Esempio n. 19
0
        public List <User> SearchList(UserSearchCondition condition)
        {
            StringBuilder sql  = new StringBuilder(@"
SELECT  *
FROM    ( SELECT    ROW_NUMBER() OVER ( ORDER BY CreateTime DESC ) AS RowNum,*
          FROM      dbo.[User]
        ) tb
WHERE   RowNum BETWEEN STR(@PageIndex - 1) * @PageSize + 1
               AND     STR(@PageIndex * @PageSize)
");
            var           list = new List <User>();

            using (IDbConnection conn = DapperContext.GetSqlConnection())
            {
                return(conn.Query <User>(sql.ToString(), condition).ToList());
            }
        }
Esempio n. 20
0
 public PagingResult SearchList(UserSearchCondition condition)
 {
     try
     {
         if (condition is null)
         {
             return(new PagingResult(-1, "服务器异常", null, 0));
         }
         var list  = Hubert.ORM.Dapper.DataProviders.UserDataProvider.SearchList(condition);
         var count = Hubert.ORM.Dapper.DataProviders.UserDataProvider.SearchListCount(condition);
         return(new PagingResult(0, "查询成功", list, count));
     }
     catch (Exception e)
     {
         Logger.Error("SearchList is error", GetType(), e);
         return(new PagingResult(-1, "服务器异常", null, 0));
     }
 }
Esempio n. 21
0
 public PagingResult SearchListByEF(UserSearchCondition condition)
 {
     try
     {
         if (condition == null)
         {
             return(new PagingResult(-1, "参数错误", null, 0));
         }
         var list  = Hubert.ORM.EF.DataProviders.UserDataProvider.SearchList(condition);
         var count = Hubert.ORM.EF.DataProviders.UserDataProvider.SearchListCount(condition);
         return(new PagingResult(0, "查询成功", list, count));
     }
     catch (Exception ex)
     {
         Logger.Error("SearchListByEF is error", GetType(), ex);
         return(new PagingResult(-1, "系统异常", null, 0));
     }
 }
Esempio n. 22
0
        /// <summary>
        /// ユーザーリストを取得する
        /// </summary>
        /// <param name="seachCondition">検索条件</param>
        /// <returns>ユーザーリスト</returns>
        public List <UserModel> GetAllUsers(UserSearchCondition seachCondition)
        {
            var sql = new StringBuilder();

            sql.AppendLine("SELECT");
            sql.AppendLine("  MT_USER.USER_ID");
            sql.AppendLine("  , MT_USER.USER_NAME");
            sql.AppendLine("  , MT_USER.PASSWORD");
            sql.AppendLine("  , MT_USER.DEL_FLAG");
            sql.AppendLine("  , ENTRY_USER_INFO.USER_NAME ENTRY_USER");
            sql.AppendLine("  , MT_USER.ENTRY_DATE");
            sql.AppendLine("  , MOD_USER_NFO.USER_NAME MOD_USER");
            sql.AppendLine("  , MT_USER.MOD_DATE");
            sql.AppendLine("  , MT_USER.MOD_VERSION ");
            sql.AppendLine("FROM");
            sql.AppendLine("  MT_USER ");
            sql.AppendLine("  LEFT JOIN MT_USER ENTRY_USER_INFO ");
            sql.AppendLine("    ON ENTRY_USER_INFO.USER_ID = MT_USER.ENTRY_USER");
            sql.AppendLine("  LEFT JOIN MT_USER MOD_USER_NFO ");
            sql.AppendLine("    ON MOD_USER_NFO.USER_ID = MT_USER.MOD_USER");

            // パラメータの設定
            db.ClearParam();
            if (!string.IsNullOrEmpty(seachCondition.SearchUserId))
            {
                sql.AppendLine("where ");
                sql.AppendLine("  MT_USER.USER_ID like @USER_ID");
                db.AddParam("@USER_ID", string.Format("%{0}%", seachCondition.SearchUserId));
            }
            sql.AppendLine("ORDER BY");
            sql.AppendLine("  MT_USER.USER_ID");

            // SQL発行
            var result   = new List <UserModel>();
            var dbResult = db.Fill(sql.ToString());

            foreach (DataRow row in dbResult.Rows)
            {
                result.Add(createUserModel(row, false));
            }

            return(result);
        }
Esempio n. 23
0
        public HttpResponseMessage GetUserList(string userName = null, int page = 1, int pageSize = 10)
        {
            var userCondition = new UserSearchCondition
            {
                UserName = userName,
                Page     = page,
                PageSize = pageSize
            };

            var userList = _userService.GetUserByCondition(userCondition).Select(a => new UserModel
            {
                Id       = a.Id,
                UserName = a.UserName,
                Status   = a.Status
            }).ToList();
            var userCount = _userService.GetUserCountByCondition(userCondition);

            return(PageHelper.toJson(new{ List = userList, Condition = userCondition, TotalCount = userCount }));
        }
Esempio n. 24
0
        public HttpResponseMessage GetUserList(bool isDes = true, EnumUserOrderBy orderByAll = EnumUserOrderBy.OrderById, string userName = null, int page = 1, int pageSize = 10)
        {
            var userCondition = new UserSearchCondition
            {
                UserName     = userName,
                Page         = page,
                PageSize     = pageSize,
                IsDescending = isDes,
                OrderBy      = orderByAll
            };

            var userList = _userService.GetUserByCondition(userCondition).Select(a => new UserModel
            {
                Id       = a.Id,
                UserName = a.UserName,
                Status   = a.Status
            }).ToList();
            var userCount = _userService.GetUserCountByCondition(userCondition);

            return(PageHelper.toJson(new { List = userList, Condition = userCondition, TotalCount = userCount }));
        }
Esempio n. 25
0
        public JsonResult GetList(UserSearchCondition condition)
        {
            var list = (from u in CurrentDb.Users
                        where (condition.UserName == null || u.UserName.Contains(condition.UserName)) &&
                        (condition.FullName == null || u.FullName.Contains(condition.FullName)) &&
                        u.IsDelete == false
                        select new { u.Id, u.UserName, u.FullName, u.Email, u.PhoneNumber, u.CreateTime, u.IsDelete });

            int total = list.Count();

            int pageIndex = condition.PageIndex;
            int pageSize  = 10;

            list = list.OrderByDescending(r => r.CreateTime).Skip(pageSize * (pageIndex)).Take(pageSize);

            PageEntity pageEntity = new PageEntity {
                PageSize = pageSize, TotalRecord = total, Rows = list
            };

            return(Json(ResultType.Success, pageEntity, ""));
        }
        public IActionResult Page([FromBody] Dictionary <string, object> param)
        {
            // ログインチェック
            if (!isLogin(param))
            {
                return(Unauthorized());
            }

            var searchCondition = new UserSearchCondition();

            if (param.ContainsKey("requestData"))
            {
                // パラメータの設定
                var requestData = param["requestData"] as Newtonsoft.Json.Linq.JObject;
                searchCondition = getUserSearchCondition(requestData);
            }

            var serviceResult = new List <UserModel>();

            try
            {
                serviceResult.AddRange(service.GetUsers(searchCondition));
            }
            catch (Exception ex)
            {
                logger.LogCritical("{0}", ex.Message);
                return(BadRequest());
            }

            var status  = ResponseDTO.Results.OK;
            var message = string.Empty;

            if (!serviceResult.Any())
            {
                status  = ResponseDTO.Results.NG;
                message = SearchResultZero;
            }

            return(Json(new ResponseDTO(status, message, serviceResult)));
        }
Esempio n. 27
0
        public async Task <PagingResponseMessage <UserInfoResponse> > Search(UserSearchCondition condition, CancellationToken cancellationToken)
        {
            PagingResponseMessage <UserInfoResponse> pagingResponse = new PagingResponseMessage <UserInfoResponse>();

            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }
            if (!string.IsNullOrEmpty(condition.RoleId))
            {
                var q = from ur in _userRoleStore.UserRoles.AsNoTracking()
                        join r1 in _roleManager.Roles.AsNoTracking() on ur.RoleId equals r1.Id into r2
                        from r in r2.DefaultIfEmpty()
                        join u1 in _extendUserStore.Users.AsNoTracking() on ur.UserId equals u1.Id into u2
                        from u in u2.DefaultIfEmpty()
                        join b in _organizationStore.Organizations.AsNoTracking() on u.OrganizationId equals b.Id into b1
                        from b2 in b1.DefaultIfEmpty()
                        join c in _organizationStore.Organizations.AsNoTracking() on u.FilialeId equals c.Id into c1
                        from c2 in c1.DefaultIfEmpty()
                        where !u.IsDeleted
                        select new UserRole
                {
                    UserId = ur.UserId,
                    RoleId = ur.RoleId,
                    Roles  = new Roles
                    {
                        Id             = r.Id,
                        Name           = r.Name,
                        Type           = r.Type,
                        NormalizedName = r.NormalizedName,
                        OrganizationId = r.OrganizationId
                    },
                    Users = new Users
                    {
                        Avatar         = u.Avatar,
                        Email          = u.Email,
                        Filiale        = c2.OrganizationName,
                        Id             = u.Id,
                        OrganizationId = u.OrganizationId,
                        FilialeId      = u.FilialeId,
                        Organization   = b2.OrganizationName,
                        PhoneNumber    = u.PhoneNumber,
                        Position       = u.Position,
                        TrueName       = u.TrueName,
                        UserName       = u.UserName,
                        CityCode       = c2.City,
                    }
                };
                if (condition?.OrganizationIds?.Count > 0)
                {
                    q = q.Where(x => condition.OrganizationIds.Contains(x.Users.OrganizationId));
                }
                if (!string.IsNullOrEmpty(condition.KeyWords))
                {
                    q = q.Where(x => x.Users.TrueName.Contains(condition.KeyWords) || x.Users.UserName.Contains(condition.KeyWords) || x.Users.PhoneNumber.Contains(condition.KeyWords));
                }
                if (!string.IsNullOrEmpty(condition.RoleId))
                {
                    q = q.Where(x => x.RoleId == condition.RoleId);
                }
                pagingResponse.TotalCount = await q.CountAsync();

                var qlist = await q.OrderBy(a => a.Users.TrueName).Skip(condition.PageIndex * condition.PageSize).Take(condition.PageSize).ToListAsync(cancellationToken);

                var resulte = qlist.Select(a => new UserInfoResponse
                {
                    Avatar         = a.Users.Avatar,
                    CityCode       = a.Users.CityCode,
                    Email          = a.Users.Email,
                    Filiale        = a.Users.Filiale,
                    FilialeId      = a.Users.FilialeId,
                    Id             = a.Users.Id,
                    Organization   = a.Users.Organization,
                    OrganizationId = a.Users.OrganizationId,
                    PhoneNumber    = a.Users.PhoneNumber,
                    Position       = a.Users.Position,
                    TrueName       = a.Users.TrueName,
                    UserName       = a.Users.UserName,
                    RoleId         = a.RoleId
                }).ToList();
                pagingResponse.PageIndex = condition.PageIndex;
                pagingResponse.PageSize  = condition.PageSize;
                pagingResponse.Extension = resulte;
            }
            else
            {
                var q = from a in _extendUserStore.Users.AsNoTracking()
                        join b in _organizationStore.Organizations.AsNoTracking() on a.OrganizationId equals b.Id into b1
                        from b2 in b1.DefaultIfEmpty()
                        join c in _organizationStore.Organizations.AsNoTracking() on a.FilialeId equals c.Id into c1
                        from c2 in c1.DefaultIfEmpty()
                        where !a.IsDeleted
                        select new UserInfoResponse
                {
                    Avatar         = a.Avatar,
                    Email          = a.Email,
                    Filiale        = c2.OrganizationName,
                    Id             = a.Id,
                    OrganizationId = a.OrganizationId,
                    FilialeId      = a.FilialeId,
                    Organization   = b2.OrganizationName,
                    PhoneNumber    = a.PhoneNumber,
                    Position       = a.Position,
                    TrueName       = a.TrueName,
                    UserName       = a.UserName,
                    CityCode       = c2.City
                };
                if (condition?.OrganizationIds?.Count > 0)
                {
                    q = q.Where(x => condition.OrganizationIds.Contains(x.OrganizationId));
                }
                if (!string.IsNullOrEmpty(condition.KeyWords))
                {
                    q = q.Where(x => x.TrueName.Contains(condition.KeyWords) || x.UserName.Contains(condition.KeyWords) || x.PhoneNumber.Contains(condition.KeyWords));
                }
                pagingResponse.TotalCount = await q.CountAsync();

                var resulte = await q.OrderBy(a => a.TrueName).Skip(condition.PageIndex * condition.PageSize).Take(condition.PageSize).ToListAsync(cancellationToken);

                for (int i = 0; i < resulte.Count; i++)
                {
                    resulte[i].Roles = (await _extendUserStore.GetRolesAsync(_mapper.Map <Users>(resulte[i]))).ToList();
                }
                pagingResponse.PageIndex = condition.PageIndex;
                pagingResponse.PageSize  = condition.PageSize;
                pagingResponse.Extension = resulte;
            }
            return(pagingResponse);
        }
Esempio n. 28
0
        public IQueryable <UserBase> GetUserByCondition(UserSearchCondition condition)
        {
            try
            {
                var query = _userRepository.Table;
                if (condition.BeginTime.HasValue)
                {
                    query = query.Where(c => c.RegTime >= condition.BeginTime.Value);
                }
                if (condition.EndTime.HasValue)
                {
                    query = query.Where(c => c.RegTime < condition.EndTime.Value);
                }
                if (condition.Status.HasValue)
                {
                    query = query.Where(c => c.Status == condition.Status);
                }
                if (condition.Ids != null && condition.Ids.Length > 0)
                {
                    query = query.Where(c => condition.Ids.Contains(c.Id));
                }
                if (!string.IsNullOrEmpty(condition.UserName))
                {
                    query = query.Where(c => c.UserName.Contains(condition.UserName));
                }
                if (condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy)
                    {
                    case EnumUserOrderBy.Default:
                        query = condition.IsDescending
                                ? query.OrderByDescending(c => c.Id)
                                : query.OrderBy(c => c.Id);
                        break;

                    case EnumUserOrderBy.ById:
                        query = condition.IsDescending
                                ? query.OrderByDescending(c => c.Id)
                                : query.OrderBy(c => c.Id);
                        break;

                    case EnumUserOrderBy.ByName:
                        query = condition.IsDescending
                                ? query.OrderByDescending(c => c.UserName)
                                : query.OrderBy(c => c.UserName);
                        break;

                    case EnumUserOrderBy.RegTime:
                        query = condition.IsDescending
                                ? query.OrderByDescending(c => c)
                                : query.OrderBy(c => c.RegTime);
                        break;
                    }
                }
                else
                {
                    query = condition.IsDescending
                                ? query.OrderByDescending(c => c.Id)
                                : query.OrderBy(c => c.Id);
                }
                if (condition.Page.HasValue && condition.PageSize.HasValue)
                {
                    query =
                        query.Skip((condition.Page.Value - 1) * condition.PageSize.Value).Take(condition.PageSize.Value);
                }
                return(query);
            }
            catch (Exception e)
            {
                _log.Error(e, "获取用户列表失败");
                return(null);
            }
        }
        public async Task <PagingResponseMessage <UserInfoResponse> > GetList(string userId, [FromBody] UserSearchCondition condition)
        {
            PagingResponseMessage <UserInfoResponse> pagingResponse = new PagingResponseMessage <UserInfoResponse>();

            var organizationIds = await _permissionExpansionManager.GetOrganizationOfPermission(userId, "UserInfoRetrieve");

            if (organizationIds?.Count == 0)
            {
                pagingResponse.Code    = ResponseCodeDefines.NotAllow;
                pagingResponse.Message = "没有权限";
                return(pagingResponse);
            }
            if (condition == null)
            {
                pagingResponse.Code = ResponseCodeDefines.ArgumentNullError;
                return(pagingResponse);
            }
            if (condition.OrganizationIds?.Count > 0)
            {
                condition.OrganizationIds = condition.OrganizationIds.Where(a => organizationIds.Contains(a)).ToList();
            }
            return(await _extendUserManager.Search(condition, HttpContext.RequestAborted));
        }
        public SearchResultObject <UserSearchResult> SearchUserCustomer(UserSearchCondition searchCondition)
        {
            db = new TimeAttendanceEntities();
            SearchResultObject <UserSearchResult> searchResult = new SearchResultObject <UserSearchResult>();

            try
            {
                var listmodel = (from a in db.User.AsNoTracking()
                                 where a.DeleteFlg == Constants.DeleteFalse && (string.IsNullOrEmpty(searchCondition.Type) || a.Type.Equals(searchCondition.Type))
                                 join c in db.UserGroup.AsNoTracking() on a.UserId equals c.UserId into ac
                                 from acv in ac.DefaultIfEmpty()
                                 join d in db.Group.AsNoTracking() on acv.GroupId equals d.GroupId into cd
                                 from cdv in cd.DefaultIfEmpty()
                                 select new UserSearchResult
                {
                    UserId = a.UserId,
                    UnitId = a.UnitId,
                    Name = a.Name,
                    FullName = a.FullName,
                    BirthDay = a.BirthDay,
                    Agency = a.Agency,
                    Email = a.Email,
                    Role = a.Role,
                    PhoneNumber = a.PhoneNumber,
                    Status = a.Status,
                    Description = a.Description,
                    ImageLink = a.ImageLink,
                    Address = a.Address,
                    CreateBy = a.CreateBy,
                    CreateDate = a.CreateDate,
                    UpdateBy = a.UpdateBy,
                    UpdateDate = a.UpdateDate,
                    GroupId = acv.GroupId,
                    GroupName = cdv != null ? cdv.Name : string.Empty,
                    Type = a.Type,
                }).AsQueryable();

                if (!string.IsNullOrEmpty(searchCondition.GroupId))
                {
                    listmodel = listmodel.Where(r => r.GroupId.Equals(searchCondition.GroupId));
                }
                if (!string.IsNullOrEmpty(searchCondition.Name))
                {
                    listmodel = listmodel.Where(r => r.Name.ToUpper().Contains(searchCondition.Name.ToUpper()));
                }
                if (!string.IsNullOrEmpty(searchCondition.FullName))
                {
                    listmodel = listmodel.Where(r => r.FullName.ToUpper().Contains(searchCondition.FullName.ToUpper()));
                }
                if (searchCondition.Status.HasValue)
                {
                    listmodel = listmodel.Where(r => r.Status.HasValue && r.Status.Value == searchCondition.Status.Value);
                }
                if (!string.IsNullOrEmpty(searchCondition.UnitId))
                {
                    listmodel = listmodel.Where(r => r.UnitId.Equals(searchCondition.UnitId));
                }
                if (!string.IsNullOrEmpty(searchCondition.PhoneNumber))
                {
                    listmodel = listmodel.Where(r => r.PhoneNumber.ToUpper().Contains(searchCondition.PhoneNumber.ToUpper()));
                }
                if (searchCondition.Status.HasValue)
                {
                    listmodel = listmodel.Where(r => r.Status.HasValue && r.Status.Value == searchCondition.Status.Value);
                }

                searchResult.TotalItem = listmodel.Select(r => r.UserId).Count();
                var listResult = SQLHelpper.OrderBy(listmodel, searchCondition.OrderBy, searchCondition.OrderType).Skip((searchCondition.PageNumber - 1) * searchCondition.PageSize)
                                 .Take(searchCondition.PageSize)
                                 .ToList();
                searchResult.ListResult = listResult;
            }

            catch (Exception ex)
            {
                throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
            }
            return(searchResult);
        }