示例#1
0
        public List <Models.Response.GerenteResponse.topMelhoresClienteResponse> TopMelhoresClientes()
        {
            Models.TccContext db = new Models.TccContext();
            Utils.ConversorGerenteUtils.ConversordoRelatorioUtils             buscarclientes = new Utils.ConversorGerenteUtils.ConversordoRelatorioUtils();
            List <Models.Response.GerenteResponse.topMelhoresClienteResponse> ctx            = new List <Models.Response.GerenteResponse.topMelhoresClienteResponse>();

            List <Models.TbCompra> compras = db.TbCompra.Include(x => x.IdClienteNavigation).ToList();

            foreach (Models.TbCompra item in compras)
            {
                Models.Response.GerenteResponse.topMelhoresClienteResponse osmelhores = buscarclientes.melhoresCliente(item);
                Models.Response.GerenteResponse.topMelhoresClienteResponse existente  = ctx.FirstOrDefault(x => x.telefone == osmelhores.telefone);
                if (existente == null)
                {
                    ctx.Add(osmelhores);
                }
                else
                {
                    continue;
                }
            }
            return(ctx.OrderByDescending(x => x.totaldegastos).Take(10).ToList());
        }
示例#2
0
        public Models.Response.GerenteResponse.topMelhoresClienteResponse melhoresCliente(Models.TbCompra req)
        {
            Models.TccContext       db       = new Models.TccContext();
            List <Models.TbCliente> clientes = db.TbCliente.Include(x => x.IdLoginNavigation).ToList();

            Models.TbCliente       infocliente = clientes.First(x => x.IdCliente == req.IdCliente);
            List <Models.TbCompra> infocompras = db.TbCompra.Where(x => x.IdCliente == infocliente.IdCliente).ToList();
            List <decimal>         valortotal  = new List <decimal>();

            Models.Response.GerenteResponse.topMelhoresClienteResponse response = new Models.Response.GerenteResponse.topMelhoresClienteResponse();

            response.email      = infocliente.IdLoginNavigation.DsEmail;
            response.nome       = infocliente.NmCliente;
            response.telefone   = infocliente.DsTelefone;
            response.qtdpedidos = infocompras.Count();

            foreach (Models.TbCompra ii in infocompras)
            {
                valortotal.Add(ii.VlTotal);
            }

            response.totaldegastos = valortotal.Sum();
            return(response);
        }