Exemple #1
0
        public virtual IActionResult List(ConstructionSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageConstruction))
            {
                return(AccessDeniedKendoGridJson());
            }

            //prepare model
            var model = _constructionModelFactory.PrepareConstructionListModel(searchModel);

            return(Json(model));
        }
        public ConstructionListModel PrepareConstructionListModel(ConstructionSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get items
            var items = _constructionService.GetContructionByName(searchModel.TypeId, searchModel.Name, searchModel.Page - 1, searchModel.PageSize);

            //prepare list model
            var model = new ConstructionListModel
            {
                //fill in model values from the entity
                Data  = items.Select(store => store.ToModel <ConstructionModel>()),
                Total = items.TotalCount
            };

            return(model);
        }
        public ConstructionSearchModel PrepareConstructionSearchModel(ConstructionSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare page parameters
            searchModel.SetGridPageSize();
            searchModel.lsType = _constructionTypeService.GetAllConstructionTypes().Select(c => new SelectListItem
            {
                Text     = c.Name,
                Value    = c.Id.ToString(),
                Selected = c.Id == searchModel.TypeId
            }).ToList();
            searchModel.lsType.Insert(0, new SelectListItem()
            {
                Text  = "Chọn loại công trình",
                Value = "0"
            });
            return(searchModel);
        }