public async Task <IActionResult> LogonCostCenter(DataSourceRequest command, LogonCostCenterListModel model) { model.ClientId = (int)_workContext.CurrentCustomer.ClientId; var(LogoncostcenterListModel, totalCount) = await _setupDataViewModelService.PrepareLogonCostCenterListModel(model, command.Page, command.PageSize); var gridModel = new DataSourceResult { Data = LogoncostcenterListModel.ToList(), Total = totalCount }; return(Json(gridModel)); }
public async Task <(IEnumerable <LogonCostCenterModel> CostCenterModelList, int totalCount)> PrepareLogonCostCenterListModel(LogonCostCenterListModel model, int pageIndex, int pageSize) { SqlParameter[] pr = new SqlParameter[] { new SqlParameter("@ClientID", model.ClientId), new SqlParameter("@intSort", model.SearchSortBy) }; var logoncostcenters = await _dbContext.Set <LogonUser1>().FromSqlRaw("exec LogonUser1 @ClientID,@intSort", pr).ToListAsync(); int totalCount = logoncostcenters.Count; int pageOffSet = (Convert.ToInt32(pageIndex) - 1) * 10; logoncostcenters = logoncostcenters.Skip(pageOffSet).Take(Convert.ToInt32(pageSize)).ToList(); ///Add from store procedure response to model var LogoncostcenterListModel = new List <LogonCostCenterModel>(); foreach (var p in logoncostcenters) { LogoncostcenterListModel.Add(new LogonCostCenterModel { ClientId = (int)p.ClientId, LogonId = (int)p.LogonId, UserName = p.UserName, SName = p.SName, ShipID = p.ShipID, Password = p.Password, Email = p.Email, ContactPH = p.ContactPH, LogDate = p.LogDate, LogCount = p.LogonCount }); } return(LogoncostcenterListModel, totalCount); }