public JsonResult GetRutaDeUsuario(int idUsuario, string FechaHoy) { GeoRuta datos = geoRepository.GetRutaDeUsuario(FechaHoy, idUsuario, GetClienteSeleccionado()); var _geoRuta = datos.ruta .Select(r => new GeoPosViewModel(r.lat, r.lng, r.label)) .ToList(); var _geoMarker = datos.marcadores .Select(m => new GeoMarkerViewModel() { position = new GeoPosViewModel(m.lat, m.lng), icon = m.icon, visitado = m.visitado, label = m.label, idReporte = m.idReporte, fecha = m.fecha, operacion = m.operacion, categoria = m.categoria, }).ToList(); GeoRutaViewModel model = new GeoRutaViewModel() { marcadores = _geoMarker, ruta = _geoRuta }; return(Json(model, JsonRequestBehavior.AllowGet)); }
public GeoRuta GetRutaDeUsuario(string FechaHoy, int IdUsuario, int ClienteId) { GeoRuta ruta = new GeoRuta(); using (SqlConnection cn = new SqlConnection((new RepContext()).Database.Connection.ConnectionString.ToString())) { DataTable dtfiltros = new DataTable(); dtfiltros.Columns.Add(new DataColumn("IdFiltro", typeof(string))); dtfiltros.Columns.Add(new DataColumn("Valores", typeof(string))); SqlCommand cmd = new SqlCommand("GetUserTrack", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@IdCliente", SqlDbType.Int).Value = ClienteId; var fecha = new string[] { "D", FechaHoy, FechaHoy }; DataRow newRow = dtfiltros.NewRow(); newRow[0] = "fltFechaReporte"; newRow[1] = string.Join(",", fecha); dtfiltros.Rows.Add(newRow); newRow = dtfiltros.NewRow(); newRow[0] = "IdUsuario"; newRow[1] = IdUsuario; dtfiltros.Rows.Add(newRow); cmd.Parameters.Add("@Filtros", SqlDbType.Structured).Value = dtfiltros; cmd.Parameters.Add("@Lenguaje", SqlDbType.VarChar).Value = System.Threading.Thread.CurrentThread.CurrentCulture.Name; cn.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); //Marcadores DataTable dtMarcadores = ds.Tables[0]; foreach (DataRow row in dtMarcadores.Rows) { ruta.marcadores.Add(new GeoMarker() { lat = decimal.Parse(row["lat"].ToString()), lng = decimal.Parse(row["lng"].ToString()), idUsuario = int.Parse(row["idUsuario"].ToString()), icon = row["icon"].ToString(), idReporte = int.Parse((string.IsNullOrEmpty(row["idReporte"].ToString())) ? "0" : row["idReporte"].ToString()), usuario = row["usuario"].ToString(), fecha = row["fecha"].ToString(), tipo = row["tipo"].ToString(), label = row["id"].ToString(), operacion = row["operacion"].ToString(), categoria = row["categoria"].ToString() }); } //Ruta DataTable dtRuta = ds.Tables[1]; foreach (DataRow row in dtRuta.Rows) { ruta.ruta.Add(new GeoPos() { lat = decimal.Parse(row["lat"].ToString()), lng = decimal.Parse(row["lng"].ToString()), label = row["id"].ToString() }); } } return(ruta); }