我有一个存储库,我有这个方法来获取一些数据。这是代码:
public List<HeatmapViewModel> GetStops()
{
using (var ctx = new GoogleMapTutorialEntities())
{
List<HeatmapViewModel> items = new List<HeatmapViewModel>();
#region firstitem_calculation
var firstitem = ctx.Loggings.Where(x => x.Datatype == 2).AsEnumerable().Select(
x => new Logging
{
Longitude2 = x.Longitude2,
Latitude2 = x.Latitude2,
CurDateTime = x.CurDateTime
}).FirstOrDefault();
var midnight = new DateTime(firstitem.CurDateTime.Year, firstitem.CurDateTime.Month, firstitem.CurDateTime.Day, 00, 00, 00);
TimeSpan difference = (firstitem.CurDateTime - midnight);
var difference_after_midnight = (int) difference.TotalMinutes;
items.Add( new HeatmapViewModel
{
FirstStartDifference = difference_after_midnight
});
#endregion
return items;
}
}
我需要在控制器中调用此方法,在此方法中:
public JsonResult GetStops()
{
}
我怎么能这样做?
答案 0 :(得分:3)
YourRepositoryName repo = new YourRepositoryName();
var _data = repo.GetStops();
答案 1 :(得分:1)
public JsonResult GetStops()
{
var repo = new TheRepository();
var listOfHeatMapVm = repo.GetStops();
//Convert the list of HeatMapVm to Json result here.
return Json(listOfHeatMapVm);
}