public InfinityPagedList <ServicoContabilViewModel> MeusServicoSolicitados([FromBody] dynamic param) { int page = Convert.ToInt32(param.page); int pageSize = 5; string status = param.status?.ToString(); int cliente = AppExtension.IdUsuarioLogado(); Entities context = new Entities(); DateTime now = DateTime.Now; List <ServicoContabilViewModel> list = new List <ServicoContabilViewModel>(); var query = context.ServicoContabil.AsQueryable(); query = query.Where(ban => ban.IdCliente == cliente); query = query.Where(ban => ban.Status == status); query.OrderByDescending(ban => ban.DataSolicitacao).Skip(page * pageSize).Take(pageSize).ToList().ForEach(obj => { list.Add(new ServicoContabilViewModel(obj)); }); InfinityPagedList <ServicoContabilViewModel> paged = new InfinityPagedList <ServicoContabilViewModel>(); paged.list = list; paged.pageSize = pageSize; paged.current = page; return(paged); }
public InfinityPagedList <BannerViewModel> MeusBanners([FromBody] dynamic param) { int page = Convert.ToInt32(param.page); int pageSize = 5; string status = param.status.ToString(); int cliente = AppExtension.IdUsuarioLogado(); Entities context = new Entities(); DateTime now = DateTime.Now; List <BannerViewModel> list = new List <BannerViewModel>(); var query = context.Banner.AsQueryable(); if (status == "EXIBICAO") { query = query.Where(ban => ban.Expiracao > now && now > ban.Estreia && ban.Situacao == "A" && ban.IdCliente == cliente); } else if (status == "ESPERA") { query = query.Where(ban => ((ban.Expiracao > now && now > ban.Estreia && ban.Situacao == "E") || (ban.Expiracao > now && now < ban.Estreia && ban.Situacao != "I")) && ban.IdCliente == cliente); } else if (status == "EXPIRADO") { query = query.Where(ban => ban.Expiracao < now && ban.Situacao != "I" && ban.IdCliente == cliente); } query.OrderByDescending(ban => ban.Cadastro).Skip(page * pageSize).Take(pageSize).ToList().ForEach(obj => { list.Add(new BannerViewModel(obj)); }); InfinityPagedList <BannerViewModel> paged = new InfinityPagedList <BannerViewModel>(); paged.list = list; paged.pageSize = pageSize; paged.current = page; return(paged); }
public InfinityPagedList <BannerViewModel> EmExibicao([FromBody] dynamic param) { int pageSize = 3; Entities context = new Entities(); List <BannerViewModel> lista = new List <BannerViewModel>(); DateTime now = DateTime.Now; List <int> excludes = new List <int>(); foreach (int exc in param.Excludes) { excludes.Add(exc); } int page = Convert.ToInt32(param.page); var query = context.Banner.Where(ban => ban.Expiracao > now && now > ban.Estreia && ban.Situacao == "A"); query = query.Where(ban => excludes.Contains(ban.Id) == false); query = query.OrderBy(r => Guid.NewGuid()); query = query.Take(pageSize); query.ToList().ForEach(obj => { obj.Contador = obj.Contador == null ? 1 : obj.Contador + 1; lista.Add(new BannerViewModel(obj)); }); context.SaveChanges(); InfinityPagedList <BannerViewModel> paged = new InfinityPagedList <BannerViewModel>(); paged.list = lista; paged.pageSize = pageSize; paged.current = page; return(paged); }
public InfinityPagedList <ClienteViewModel> Buscar([FromBody] dynamic param) { Entities context = new Entities(); var cliente = context.Cliente.Find(AppExtension.IdUsuarioLogado()); if (cliente.FlagCliente != "A") { throw new Exception("Somente associados podem buscar profissionais."); } if (cliente.DataExpiracao < DateTime.Now) { throw new Exception("Somente assinantes podem buscar profissionais, Assine já!"); } int pageSize = 3; string profissao = param.profissao?.ToString(); string disponibilidade = param.disponibilidade?.ToString(); string sexo = param.sexo?.ToString(); string cidade = param.cidade?.ToString(); string experiencia = param.experiencia?.ToString(); string bairro = param.bairro?.ToString(); bool delivery = Convert.ToBoolean(param.delivery); int page = Convert.ToInt32(param.page); List <int> excludes = new List <int>(); foreach (int exc in param.Excludes) { excludes.Add(exc); } List <ClienteViewModel> lista = new List <ClienteViewModel>(); var query = context.Cliente.Where(pro => pro.FlagCliente == "P"); if (!String.IsNullOrEmpty(profissao)) { query = query.Where(pro => pro.ClienteProfissional.Any(cp => cp.Profissao.Id.ToString() == profissao)); } if (delivery == false && !String.IsNullOrEmpty(disponibilidade)) { query = query.Where(pro => pro.ClienteProfissional.Any(cp => cp.Disponibilidade.Id.ToString() == disponibilidade)); } if (delivery) { query = query.Where(pro => pro.ClienteProfissional.Any(cp => cp.FlagDelivery == true)); } if (!String.IsNullOrEmpty(sexo)) { query = query.Where(pro => pro.ClienteProfissional.Any(cp => cp.Sexo == sexo)); } if (!String.IsNullOrEmpty(experiencia)) { int tempExp = Convert.ToInt32(experiencia); query = query.Where(pro => pro.ClienteProfissional.Any(cp => cp.TempoExperiencia >= tempExp)); } if (!String.IsNullOrEmpty(cidade)) { query = query.Where(pro => pro.Cidade.Id.ToString() == cidade); } if (!String.IsNullOrEmpty(bairro)) { query = query.Where(pro => pro.Bairro.Contains(bairro)); } query = query.Where(pro => pro.Situacao == true); if (ParametroController.ObterParam("LimitarProfissionalPorExpiracao") == "S") { query = query.Where(pro => pro.DataExpiracao > DateTime.Now); } query = query.Where(pro => excludes.Contains(pro.Id) == false); query = query.OrderBy(r => Guid.NewGuid()); query = query.Take(pageSize); query.ToList().ForEach(obj => { lista.Add(new ClienteViewModel(obj, false)); }); InfinityPagedList <ClienteViewModel> paged = new InfinityPagedList <ClienteViewModel>(); paged.list = lista; paged.pageSize = pageSize; paged.current = page; return(paged); }