Ejemplo n.º 1
0
        public ActionResult GetList(string entName, string userName, FrontUserViewModel model)
        {
            var result = new StandardJsonResult <FrontUserJsonResultModel>();

            result.Try(() =>
            {
                if (!ModelState.IsValid)
                {
                    throw new KnownException(ModelState.GetFirstError());
                }

                if (model.page < 1)
                {
                    model.page = 1;
                }
                if (model.rows < 1)
                {
                    model.rows = 10;
                }
                //获取所有
                if (entName == null && userName == null)
                {
                    int amount;
                    //查询front用户列表
                    var temp = _userService.GetAllFrontUser("", model.rows, model.page, out amount);
                    List <FrontUserJsonItemModel> list = new List <FrontUserJsonItemModel>();
                    foreach (var dto in temp)
                    {
                        var item            = (FrontUserJsonItemModel)dto;
                        item.Roles          = _userRoleService.GetAllEnterpriseRolesByFrontUserId(dto.UserID);
                        item.EnterpriseName = _entService.GetOneByEnterpriseID(dto.EnterpiseID).Name;
                        if (dto.DepartmentID == null)
                        {
                            item.DepartName = "";
                        }
                        else
                        {
                            item.DepartName = Ioc.GetService <IEnterpriseDepartmentManagementService>().GetDepartmentNameById(dto.DepartmentID ?? 0);
                        }
                        list.Add(item);
                    }
                    result.Value       = new FrontUserJsonResultModel();
                    result.Value.rows  = list;
                    result.Value.total = amount;
                }
                else //搜索模式
                {
                    int amount;
                    var rlist    = new List <FrontUserJsonItemModel>();
                    var userList = _userService.SearchUserByName(entName, userName, model.page, model.rows, out amount);
                    foreach (var dto in userList)
                    {
                        var item            = (FrontUserJsonItemModel)dto;
                        item.Roles          = _userRoleService.GetAllEnterpriseRolesByFrontUserId(item.UserID);
                        item.EnterpriseName = _entService.GetOneByEnterpriseID(dto.EnterpiseID).Name;
                        rlist.Add(item);
                    }
                    result.Value       = new FrontUserJsonResultModel();
                    result.Value.total = amount;//赋值
                    result.Value.rows  = rlist;
                }
            });
            if (result.Success == true)
            {
                return(new OringinalJsonResult <FrontUserJsonResultModel> {
                    Value = result.Value
                });
            }
            else
            {
                return(new OringinalJsonResult <FrontUserJsonResultModel> {
                    Value = new FrontUserJsonResultModel()
                });
            }
        }
Ejemplo n.º 2
0
        public ActionResult GetUserList(EnterpriseUserViewModel model)
        {
            string _enterpriseID = GetSession().User.EnterpriseID;

            if (model.depart == null)
            {
                model.depart = "";
            }
            if (model.name == null)
            {
                model.name = "";
            }
            if (model.page < 1)
            {
                model.page = 1;
            }
            if (model.rows < 1)
            {
                model.rows = 10;
            }
            var result = new StandardJsonResult <EnterpriseUserResultModel>();

            result.Try(() =>
            {
                if (!ModelState.IsValid)
                {
                    throw new KnownException(ModelState.GetFirstError());
                }
                var temp = new List <FrontUserDto>();
                int amount;

                //获取所有用户模式 列表
                if (model.name.Equals("") && model.depart.Equals(""))
                {
                    temp = _userService.GetUserList(_enterpriseID, model.page, model.rows, out amount);
                }
                //搜索模式
                else
                {
                    temp = _userService.SearchUser(_enterpriseID, model.depart, model.name, model.page, model.rows, out amount);
                }


                List <EnterpriseUserJsonItemModel> list = new List <EnterpriseUserJsonItemModel>();
                foreach (var udto in temp)
                {
                    var item   = (EnterpriseUserJsonItemModel)udto;
                    item.Roles = new List <int>();
                    var name   = _entDepartService.GetDepartmentNameById(udto.DepartmentID ?? 0);
                    if (name == null)
                    {
                        name = "";
                    }
                    item.DepartmentName = name;

                    var rolelist = _entUserRoleService.GetAllEnterpriseRolesByFrontUserId(udto.UserID);
                    if (rolelist == null)
                    {
                        rolelist = new List <int>();
                    }
                    foreach (var rdto in rolelist)
                    {
                        item.Roles.Add((int)rdto);
                    }

                    list.Add(item);
                }

                result.Value       = new EnterpriseUserResultModel();
                result.Value.rows  = list;
                result.Value.total = amount;
            });
            if (result.Success == true)
            {
                return(new OringinalJsonResult <EnterpriseUserResultModel> {
                    Value = result.Value
                });
            }
            else
            {
                return(new OringinalJsonResult <EnterpriseUserResultModel> {
                    Value = new EnterpriseUserResultModel()
                });
            }
        }