Exemplo n.º 1
0
        public ActionResult AddUser(string keywords)
        {
            var query  = new UserQueryModel();
            var userId = 0L;

            if (ValidatorHelper.IsMobilePhoneNumber(keywords))
            {
                query.Phone = keywords;
            }
            else if (long.TryParse(keywords, out userId))
            {
                query.UserId = userId;
            }
            else if (!string.IsNullOrEmpty(keywords))
            {
                query.RealNameLike = keywords;
            }
            else
            {
                //为输入正确条件 直接返回null
                return(View());
            }

            using (var db = new MbContext())
            {
                var models = db.User.Where(query).ToList();
                return(View(models));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 用户列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public ActionResult UserList(UserQueryModel query, string keywords)
        {
            //DOTO 条件
            var userId = 0L;

            if (ValidatorHelper.IsMobilePhoneNumber(keywords))
            {
                query.Phone = keywords;
            }
            else if (long.TryParse(keywords, out userId))
            {
                query.UserId = userId;
            }
            else
            {
                query.RealNameLike = keywords;
            }
            if (CurrentUser.User.RoleKey == LZY.BX.Model.Enum.UserType.UseCompanyUserAdmin)
            {
                //DOTO 根据当前用户的单位查找该单位下的所有人员
                using (var db = new MbContext())
                {
                    //DOTO获取当前报修单位下的用户Id
                    var userIds =
                        db.UseCompanyUser
                        .Where(x => x.UseCompanyId == CurrentUser.User.UseCompanyId)
                        .Select(x => x.UserId)
                        .ToArray();

                    //DOTO人员数量
                    var countModel = db.User.Where(x => userIds.Contains(x.UserId)).Where(query);

                    //DOTO人员列表
                    query.Data = countModel
                                 .OrderByDescending(x => x.RegTime)
                                 .Skip(query.PageInfo.RecIndex)
                                 .Take(query.PageInfo.PageSize)
                                 .ToList();

                    //DOTO人员数量
                    query.PageInfo.TotalCount = countModel.Count();
                }

                return(View(query));
            }
            else
            {
                return(View(query));
            }
        }