public async Task <JsonResult> ListaRutas(int IdVendedor, DateTime fecha) { var lista = new RutasVisitasRequest(); VendedorRequest vendedorRequest = new VendedorRequest(); vendedorRequest.FechaRuta = fecha; int idEmpresaInt = 0; try { ApplicationDbContext db = new ApplicationDbContext(); var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); // obtener el idEmpresa var userWithClaims = (ClaimsPrincipal)User; var idEmpresa = userWithClaims.Claims.First(c => c.Type == Constantes.Empresa).Value; // convertir el idEmpresa a int idEmpresaInt = Convert.ToInt32(idEmpresa); //** agregar el idEmpresa al vendedorRequest ** vendedorRequest.idEmpresa = idEmpresaInt; //** agregar el idVendedor al vendedorRequest ** vendedorRequest.IdVendedor = IdVendedor; lista = await ApiServicio.ObtenerElementoAsync1 <RutasVisitasRequest>(vendedorRequest, new Uri(WebApp.BaseAddress), "api/Vendedores/ListarRutaVendedores"); return(Json(lista)); } catch (Exception ex) { return(Json(false)); } }
public async Task <RutasVisitasRequest> ListarRutaVendedores(VendedorRequest vendedorRequest) { // Necesarios: IdEmpresa e IdVendedor // solo muestra vendedores con estado 1("Activado") db.Configuration.ProxyCreationEnabled = false; //var lista = new List<RutaRequest>(); //var lista2 = new List<RutaRequest>(); RutasVisitasRequest RutaVisitas = new RutasVisitasRequest(); var ListaRuta = new List <RutaRequest>(); var Lista2 = new List <RutaRequest>(); DateTime hoy = vendedorRequest.FechaRuta; try { //Lista para la ruta del vendedor ListaRuta = await db.LogRutaVendedor .Where( x => x.Vendedor.AspNetUsers.IdEmpresa == vendedorRequest.idEmpresa && x.Vendedor.AspNetUsers.Estado == 1 && x.Vendedor.IdVendedor == vendedorRequest.IdVendedor && DbFunctions.TruncateTime(x.Fecha.Value) == hoy) .Select( x => new RutaRequest { IdLogRutaVendedor = x.IdLogRutaVendedor, IdVendedor = x.IdVendedor, Fecha = x.Fecha, Latitud = x.Latitud, Longitud = x.Longitud } ).OrderBy(or => or.Fecha).ToListAsync(); //Lista de Visitas Lista2 = await db.Visita .Where(y => y.Vendedor.AspNetUsers.IdEmpresa == vendedorRequest.idEmpresa && y.Vendedor.AspNetUsers.Estado == 1 && y.Vendedor.IdVendedor == vendedorRequest.IdVendedor && DbFunctions.TruncateTime(y.Fecha) == hoy) .Select(y => new RutaRequest { IdLogRutaVendedor = 0, IdVendedor = y.IdVendedor, Fecha = y.Fecha, Latitud = y.Latitud, Longitud = y.Longitud, ClienteRequest = new ClienteRequest { IdCliente = y.idCliente, Nombre = y.Cliente.Nombre, RazonSocial = y.Cliente.RazonSocial, Apellido = y.Cliente.Apellido, Direccion = y.Cliente.Direccion, Identificacion = y.Cliente.Identificacion, Foto = y.Cliente.Foto, } }).OrderBy(or => or.Fecha).ToListAsync(); ListaRuta.AddRange(Lista2); ListaRuta.OrderBy(or => or.Fecha).ToList(); // Visitas var listaVisitas = await db.Visita .Where(x => x.Fecha.Day == hoy.Day && x.Vendedor.IdVendedor == vendedorRequest.IdVendedor) .Select(c => new VisitaRecorrido { ClienteRequest = new ClienteRequest { IdCliente = c.idCliente, Nombre = c.Cliente.Nombre, RazonSocial = c.Cliente.RazonSocial, Apellido = c.Cliente.Apellido, Direccion = c.Cliente.Direccion, Identificacion = c.Cliente.Identificacion, Foto = c.Cliente.Foto, }, ListaCompromisos = c.Compromiso.Select(y => new CompromisosRecorrido { Detalle = y.Descripcion, TipoCompromiso = y.TipoCompromiso.Descripcion, Solucion = y.Solucion }).ToList(), Fecha = c.Fecha, IdVisita = c.idVisita, } ).ToListAsync(); listaVisitas.Count(); RutaVisitas = new RutasVisitasRequest { ListaRutas = ListaRuta, ListaVisitas = listaVisitas, }; return(RutaVisitas); } catch (Exception ex) { return(RutaVisitas); } }