Ejemplo n.º 1
0
        public ActionResult GetList(string keyword, BackUserViewModel model)
        {
            var result = new StandardJsonResult <UserJsonResultModel>();

            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 (keyword == null)
                {
                    keyword = "";
                }
                int amount;
                var list = _userManageService.SearchUserByName(keyword, model.page, model.rows, out amount);

                List <UserJsonItemModel> listr = new List <UserJsonItemModel>();
                foreach (var dto in list)
                {
                    UserJsonItemModel item = dto;
                    item.Roles             = new List <String>();
                    var service            = new UserRolesServerce();
                    var listi       = service.GetAllRolesByUserId(dto.UserID);
                    List <string> t = new List <string>();
                    foreach (var iit in listi)
                    {
                        t.Add(iit + "");
                    }
                    item.Roles = t;
                    listr.Add(item);
                }
                result.Value       = new UserJsonResultModel();
                result.Value.total = amount;    //赋值
                result.Value.rows  = listr;
            });
            if (result.Success == true)
            {
                return(new OringinalJsonResult <UserJsonResultModel> {
                    Value = result.Value
                });
            }
            else
            {
                return(new OringinalJsonResult <UserJsonResultModel> {
                    Value = new UserJsonResultModel()
                });
            }
        }
Ejemplo n.º 2
0
        public ActionResult Search(string keyword)
        {
            if (keyword == null)
            {
                keyword = "";
            }
            var result = new StandardJsonResult <UserJsonResultModel>();

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


                int amount;
                var list = _userManageService.SearchUserByName(keyword, 1, 30, out amount);

                List <UserJsonItemModel> listr = new List <UserJsonItemModel>();
                foreach (var dto in list)
                {
                    UserJsonItemModel item = dto;
                    item.Roles             = new List <String>();
                    var service            = new UserRolesServerce();
                    var listi       = service.GetAllRolesByUserId(dto.UserID);
                    List <string> t = new List <string>();
                    foreach (var iit in listi)
                    {
                        t.Add(iit + "");
                    }
                    item.Roles = t;
                    listr.Add(item);
                }
                result.Value       = new UserJsonResultModel();
                result.Value.total = amount;//赋值
                result.Value.rows  = listr;
                //var x = new { total = amount, rows = list };
            });
            return(result);
        }