public MenuRequestModel GetAllMenu(string KeySearch, int page, int pageSize) { MenuRequestModel request = new MenuRequestModel(); request.page = page; request.pageSize = pageSize; int startRow = (page - 1) * pageSize; var lst = from m in db.Menus.Where(x => x.IsDeleted == 0) select(m); if (!string.IsNullOrEmpty(KeySearch)) { request.totalRecord = lst.Where(x => x.MenuCode.Contains(KeySearch) || x.MenuName.Contains(KeySearch)).ToList().Count; request.data = lst.Where(x => x.MenuCode.Contains(KeySearch) || x.MenuName.Contains(KeySearch)).OrderBy(x => x.ModifyDate).Skip(startRow).Take(pageSize).ToList(); } else { request.totalRecord = lst.ToList().Count; request.data = lst.OrderBy(x => x.ModifyDate).Skip(startRow).Take(pageSize).ToList(); } int totalPage = 0; if (request.totalRecord % pageSize == 0) { totalPage = request.totalRecord / pageSize; } else { totalPage = request.totalRecord / pageSize + 1; } request.totalPage = totalPage; request.KeyWord = KeySearch; return(request); }
public IActionResult Get([FromQuery] MenuRequestModel requestModel) { Expression <Func <Menu, bool> > where = x => true; DateTime dateFrom, dateTo; if (!string.IsNullOrWhiteSpace(requestModel.Name)) { where = ExpressionHelpers.CombineAnd(where, a => a.Name.Contains(requestModel.Name)); } if ((requestModel.DateFrom.IsNotNullOrEmpty())) { dateFrom = requestModel.DateFrom.ToDateTime(); where = ExpressionHelpers.CombineAnd(where, a => a.CreatedDate >= dateFrom); } if ((requestModel.DateTo.IsNotNullOrEmpty())) { dateTo = requestModel.DateTo.ToDateTime().AddDays(1); where = ExpressionHelpers.CombineAnd(where, a => a.CreatedDate <= dateTo); } var services = _menuService.GetPagedList(where, x => x.Sequence, true, requestModel.Page - 1, requestModel.Count); if (services == null) { return(RespondFailure()); } List <MenuModel> serviceModels = services.Select(x => x.ToModel(requestModel.LanguageId)).ToList(); return(RespondSuccess(serviceModels, services.TotalCount)); }
public DataRes <List <ResMenuResponse> > EditMenus([FromBody] MenuRequestModel menu) { var res = new GridPage <List <ResMenuResponse> >() { code = ResCode.Success }; try { using (var uow = _uowProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <ResMenu>(); if (menu.parentId != null && menu.parentId != 0) { menu.Parent = repository.Get(menu.parentId); } menu.Url = menu.path; repository.Update(menu); uow.SaveChanges(); res.data = null; res.msg = "修改成功"; } } catch (Exception ex) { res.code = ResCode.ServerError; res.msg = ex.Message; } return(res); }
public TableDataModel LoadData(MenuRequestModel model) { string conditions = "where IsDelete=0 ";//未删除的 if (!model.Key.IsNullOrWhiteSpace()) { conditions += $"and DisplayName like '%{model.Key}%'"; } return(new TableDataModel { count = _repository.RecordCount(conditions), data = _repository.GetListPaged(model.Page, model.Limit, conditions, "Id desc").ToList(), }); }
public IActionResult GetParents([FromQuery] MenuRequestModel requestModel) { #region predicate Expression <Func <Menu, bool> > where = x => true; if (!string.IsNullOrWhiteSpace(requestModel.Name)) { where = ExpressionHelpers.CombineAnd(where, a => a.Name.Contains(requestModel.Name)); } if (requestModel.PositionId.HasValue) { where = ExpressionHelpers.CombineAnd(where, x => x.PositionId == requestModel.PositionId); } if (requestModel.ParentId.HasValue) { where = ExpressionHelpers.CombineAnd(where, x => x.ParentId == requestModel.ParentId); } if (requestModel.Active.HasValue) { where = ExpressionHelpers.CombineAnd(where, x => x.Active == requestModel.Active); } #endregion var menus = _menuService.Get( where).ToList(); #region get permissions // TODO fix menus null exception //foreach (var userRole in CurrentUser.UserRoles) //{ // var permissions = _permissionRecordService.GetPermissionRecords(userRole.Role); // foreach (var permission in permissions) // { // menus = menus.Where(x => x.Url.Contains(permission.Category)).ToList(); // } //} #endregion List <MenuModel> menuModelParents = menus.ToParentModels(requestModel.LanguageId); return(RespondSuccess(menuModelParents, menuModelParents.Count)); }
public IEnumerable <MenuItemsDisplayModel> GetData(MenuRequestModel lm) { try { using (var db = DbContextProvider.GetDbContext().InReadContext()) { var param = new Dapper.DynamicParameters(); //param.Add("Id", lm.Id, System.Data.DbType.Int32, System.Data.ParameterDirection.Input); param.Add("Name", lm.Name, System.Data.DbType.String, System.Data.ParameterDirection.Input); var result = db.ExecProcWithResults <MenuItemsDisplayModel>("dbo.spFetchMenu", param);//.ToList().First(); return(result); } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } return(null); }
public BaseResponse GetPizzas([FromBody] MenuRequestModel lm) { BaseResponse br = new BaseResponse(); try { var data = new MenuDataProvider(); var retval = data.GetData(lm); br.Result = Newtonsoft.Json.JsonConvert.SerializeObject(retval); br.ErrorCode = 0; br.ErrorMessage = ""; } catch (Exception ex) { br.ErrorCode = -1; br.ErrorMessage = ex.ToString(); } return(br); }
public async Task <TableDataModel> LoadDataAsync(MenuRequestModel model) { string conditions = $"where IsDelete=0 ";//未删除的 if (!model.Key.IsNullOrWhiteSpace()) { conditions += $"and DisplayName like '%'+@Key+'%'"; } return(new TableDataModel { count = await _repository.RecordCountAsync(conditions, new { Key = model.Key, }), data = (await _repository.GetListPagedAsync(model.Page, model.Limit, conditions, "Id desc", new { Key = model.Key, }))?.ToList(), }); }
public TableDataModel LoadData(MenuRequestModel model) { var menus = _dbContext.Menus.ToList(); if (!string.IsNullOrEmpty(model.Key)) { menus = menus.Where(t => t.Name.Contains(model.Key)).ToList(); } List <MenuDTO> list = new List <MenuDTO>(); foreach (var menu in menus) { list.Add(Todto(menu)); } var table = new TableDataModel() { count = list.Count, data = list }; return(table); }
public string LoadData([FromQuery] MenuRequestModel model) { return(JsonHelper.ObjectToJSON(_service.LoadData(model))); }
public async Task <string> LoadDataAsync([FromQuery] MenuRequestModel model) { return(JsonHelper.ObjectToJSON(await _service.LoadDataAsync(model))); }
public string LoadData([FromQuery] MenuRequestModel model) { var tableData = _menuService.LoadData(model); return(JsonHelper.ObjectToJSON(tableData)); }