public async Task <JsonResult> GetPositionByDate(string vehicleId, DateTime start, DateTime?end) { var id = Guid.Parse(vehicleId); // var endPeriod = DateTime.Now; var endPeriod = end?.ToUniversalTime() ?? start.Date.AddDays(1).AddTicks(-1).ToUniversalTime(); var vehicle = await ObjectContext.Vehicles.FindAsync(id).ConfigureAwait(false); var user = await ObjectContext.UserAccounts .FirstOrDefaultAsync(x => x.UserName == User.Identity.Name).ConfigureAwait(false); var positions = await _positionService .GetVehiclePositionsByPeriodAsync(id, start.ToUniversalTime(), endPeriod, user?.TimeZoneInfo) .ConfigureAwait(false); if (!positions.Any()) { return(Json(new List <TargetViewModel>(), JsonRequestBehavior.AllowGet)); } var gpsCollection = positions.OrderBy(x => x.Timestamp) .Select(x => new { Latitude = x.Lat, Longitude = x.Long, GpsStatement = x.Timestamp.ToString("O") }); var positionReport = new ActivitiesReport(); var result = positionReport.BuildDailyReport(positions.OrderBy(x => x.Timestamp).ToList(), start, vehicle.VehicleName); var distance = result.Where(x => x.MotionStatus == "Moving").Sum(x => x.Distance); return(Json( new { Vehiclename = vehicle?.VehicleName, Distance = Math.Round(distance, 2), Periods = result, GpsCollection = gpsCollection.Distinct() }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// /// </summary> /// <returns></returns> public async Task <JsonResult> AllVehiclesWithLastPosition() { var report = new ActivitiesReport(); var user = User.Identity; var positions = await _positionService.GetLastVehiclePositionAsync(user.Name).ConfigureAwait(false); return(Json(positions, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Report(ToDoListVM toDoListVM) { ActivitiesReport activities = new ActivitiesReport(); var readTask = await GetActivities(); byte[] abytes = activities.PrepareReport(readTask); return(File(abytes, "application/pdf", $"ReportActivities{DateTime.Now.ToString("MMddyyyy")}.pdf")); }
/// <summary> /// /// </summary> /// <param name="vehicleId"></param> /// <returns></returns> public async Task <JsonResult> GetCurrentDayPosition(string vehicleId) { var id = Guid.Parse(vehicleId); //var start = var endPeriod = DateTime.Now.ToUniversalTime(); var startPeriod = DateTime.Now.Date.ToUniversalTime(); var vehicle = await _vehicleService.GetVehicleByIdAsync(id).ConfigureAwait(false); var positions = await _positionService.GetVehiclePositionsByPeriodAsync(id, startPeriod, endPeriod).ConfigureAwait(false); if (!positions.Any()) { return(Json(new List <TargetViewModel>(), JsonRequestBehavior.AllowGet)); } var gpsCollection = positions.Select(x => new { Latitude = x.Lat, Longitude = x.Long, GpsStatement = x.Timestamp.ToString("O") }); var positionReport = new ActivitiesReport(); return(Json(new { Periods = positionReport.BuildDailyReport(positions, startPeriod, vehicle.VehicleName), GpsCollection = gpsCollection }, JsonRequestBehavior.AllowGet)); }