public JsonResult getGridTransaction(string sEcho, int iDisplayStart, int iDisplayLength, string sSortDir_0, int iSortCol_0) { var msgTransactions = new Dominio.Mensagens.Filtro.Transactions(); msgTransactions.iDisplayStart = iDisplayStart; msgTransactions.iDisplayLength = iDisplayLength; msgTransactions.sSortDir_0 = sSortDir_0; msgTransactions.iSortCol_0 = iSortCol_0; msgTransactions.ID_TOTAL_TRANSACTION = Convert.ToInt32(!string.IsNullOrEmpty(RouteData.Values["id"].ToString()) && int.TryParse(RouteData.Values["id"].ToString(), out msgTransactions.ID_TOTAL_TRANSACTION) ? RouteData.Values["id"]:0); var displayedCompanies = Fachada.Repositorio.TRANSACTIONS.GetAllTransactionsByID_Total_Transactions(msgTransactions); var result = (from c in displayedCompanies.Instances select new[] { //c.ID.ToString(), Convert.ToDateTime(c.Date).ToString("dd/MM/yyyy"), Convert.ToDateTime(c.Date).ToString("HH:MM"), c.User, c.Reservation_Number, c.Guest_Name, c.Transaction_Type, c.Payment_Type, c.Card_Type, c.Description, c.Total.ToString("C2") // TODOS OS CAMPOS DEVEM SER CONVERTIDOS PARA STRING senão o plugin não reconhece //Convert.ToString(c.identificador), //c.identificador.ToString(), //c.nome, //Convert.ToDateTime(c.dtCadastro).ToString("dd/MM/yyyy"), //c.Estado, //c.numeroProcesso, //UtilsLibrary.GetListEnum(typeof(TabTipoSolicitacao)).Where(w=>w.Value == c.TipoAtoPessoal.ToString()).Select(s=>s.StringTitulo).FirstOrDefault(), }).Take(10); return(Json(new { sEcho = sEcho, // Variável Padraão do plugin iTotalRecords = 50, // Deve realizar outra pesquisa no Banco de Daods sem Filtro de pesquisa e mostar a quantidade de registros no Banco nessa variável "iTotalRecords" no exemplo esta 1000 fixo mas deve ser a qtde total de registro que existe na tabela iTotalDisplayRecords = displayedCompanies.Code, //Total de Registro com filtro Aplicado aaData = result // Lista que será exibida do grid }, JsonRequestBehavior.AllowGet)); }
MessageCollection <GridTransactions> ITRANSACTIONS.GetAllTransactionsByID_Total_Transactions(Dominio.Mensagens.Filtro.Transactions filtroPesquisa) { var msg = new MessageCollection <Dominio.Mensagens.GridTransactions>(); try { using (var context = new HostelEntities()) { ////Não pode ser feito o .ToList nesse momento, a query SQL esta esta sendo montada de acordo com os filtros var query = (from c in context.Transactions join transType in context.Transaction_Type on c.ID_Transaction_Type equals transType.ID join pt in context.Payment_Type on c.ID_Payment_Type equals pt.ID join tt in context.Total_Transactions on c.ID_Total_Transactions equals tt.ID join ct in context.Card_Type on c.ID_Card_Type equals ct.ID into ptLeft from subCT in ptLeft.DefaultIfEmpty() where c.ID_Total_Transactions == filtroPesquisa.ID_TOTAL_TRANSACTION select new Dominio.Mensagens.GridTransactions() { ID = c.ID, Date = c.DT_Reg.ToString(), User = c.LogLogin, Reservation_Number = c.Reservation_Number, Guest_Name = c.GuestName, Transaction_Type = transType.Description, Card_Type = (subCT != null && !string.IsNullOrEmpty(subCT.Description) ? subCT.Description : string.Empty), Payment_Type = pt.Description, Description = c.Description, Total = c.Total, ID_TOTAL_TRANSACTIONS = tt.ID }); ////Filtros de Pesquisa //if (filtroPesquisa.ID_TOTAL_TRANSACTION> 0) //query = query.Where(q => q.ID_TOTAL_TRANSACTIONS == 23); //if (filtroPesquisa.ID_Calc_Type > 0) // query = query.Where(q => q.Calc_Type == (from c in context.Calc_Type where c.ID == filtroPesquisa.ID_Calc_Type select c.Description).FirstOrDefault().ToString()); //if (!string.IsNullOrEmpty(filtroPesquisa.dtInicio)) //{ // DateTime dtFim = DateTime.Now; // if (!string.IsNullOrEmpty(filtroPesquisa.dtFim)) // dtFim = Convert.ToDateTime(filtroPesquisa.dtFim); // query = query.Where(q => (Convert.ToDateTime(q.DT_reg) >= Convert.ToDateTime(filtroPesquisa.dtInicio) && Convert.ToDateTime(q.DT_reg) <= dtFim)); //} //ordenação if (filtroPesquisa.sSortDir_0 == "asc") { if (filtroPesquisa.iSortCol_0 == 1) { query = query.OrderByDescending(q => q.Date); } else if (filtroPesquisa.iSortCol_0 == 2) { query = query.OrderByDescending(q => q.User); } else if (filtroPesquisa.iSortCol_0 == 3) { query = query.OrderByDescending(q => q.ID); } else { query = query.OrderByDescending(q => q.Date); } } else if (filtroPesquisa.sSortDir_0 == "desc") { if (filtroPesquisa.iSortCol_0 == 1) { query = query.OrderBy(q => q.Date); } else if (filtroPesquisa.iSortCol_0 == 2) { query = query.OrderBy(q => q.User); } else if (filtroPesquisa.iSortCol_0 == 3) { query = query.OrderBy(q => q.ID); } else { query = query.OrderBy(q => q.Date); } } else { query = query.OrderByDescending(q => q.Date); } query = query.Take(100); ////Extract only current page msg.Instances = query.Skip(filtroPesquisa.iDisplayStart).Take(filtroPesquisa.iDisplayLength).ToList(); ////Campo improvisado para gerar o total de paginacao msg.Code = query.Count();//Total de registro com filtros aplicados //Total de registro no banco sem filtro aplicado Deve ser feito uma pesquisa direto na Tabela outra Query Deverrá ser informado em outro campo no grid CONtroller eu coloquei fixo 110 pra teste } } catch (Exception ex) { msg.Exception = ex; } return(msg); }