public IActionResult GetUnitEvents(int unitId) { var unitEvents = new List <UnitEventJson>(); if (!_authorizationService.CanUserViewUnit(UserId, unitId)) { Unauthorized(); } var department = _departmentsService.GetDepartmentById(DepartmentId, false); var events = _unitsService.GetAllStatesForUnit(unitId); foreach (var e in events) { var unitEvent = new UnitEventJson(); unitEvent.EventId = e.UnitStateId; unitEvent.UnitId = e.UnitId; unitEvent.UnitName = e.Unit.Name; unitEvent.State = StringHelpers.GetDescription(((UnitStateTypes)e.State)); unitEvent.Timestamp = e.Timestamp.TimeConverterToString(department); unitEvent.Note = e.Note; if (((UnitStateTypes)e.State) == UnitStateTypes.Enroute) { if (e.DestinationId.HasValue) { var station = _departmentGroupsService.GetGroupById(e.DestinationId.Value, false); if (station != null) { unitEvent.DestinationName = station.Name; } else { unitEvent.DestinationName = "Station"; } } else { unitEvent.DestinationName = "Station"; } } else if (((UnitStateTypes)e.State) == UnitStateTypes.Responding || ((UnitStateTypes)e.State) == UnitStateTypes.Committed || ((UnitStateTypes)e.State) == UnitStateTypes.OnScene || ((UnitStateTypes)e.State) == UnitStateTypes.Staging || ((UnitStateTypes)e.State) == UnitStateTypes.Released || ((UnitStateTypes)e.State) == UnitStateTypes.Cancelled) { if (e.DestinationId.HasValue) { var call = _callsService.GetCallById(e.DestinationId.Value, false); if (call != null) { unitEvent.DestinationName = call.Name; } else { unitEvent.DestinationName = "Scene"; } } } if (e.LocalTimestamp.HasValue) { unitEvent.LocalTimestamp = e.LocalTimestamp.Value.ToString(); } if (e.Latitude.HasValue) { unitEvent.Latitude = e.Latitude.Value.ToString(); } if (e.Longitude.HasValue) { unitEvent.Longitude = e.Longitude.Value.ToString(); } if (e.Accuracy.HasValue) { unitEvent.Accuracy = e.Accuracy.Value.ToString(); } if (e.Altitude.HasValue) { unitEvent.Altitude = e.Altitude.Value.ToString(); } if (e.AltitudeAccuracy.HasValue) { unitEvent.AltitudeAccuracy = e.AltitudeAccuracy.Value.ToString(); } if (e.Speed.HasValue) { unitEvent.Speed = e.Speed.Value.ToString(); } if (e.Heading.HasValue) { unitEvent.Heading = e.Heading.Value.ToString(); } unitEvents.Add(unitEvent); } return(Json(unitEvents)); }
public IActionResult GenerateReport(IFormCollection form) { var eventIds = new List <int>(); foreach (var key in form.Keys) { if (key.ToString().StartsWith("selectEvent_")) { var eventId = int.Parse(key.ToString().Replace("selectEvent_", "")); eventIds.Add(eventId); } } var model = new UnitEventsReportView(); model.Rows = new List <UnitEventJson>(); model.Department = _departmentsService.GetDepartmentById(DepartmentId, false); foreach (var eventId in eventIds) { var eventJson = new UnitEventJson(); var eventRecord = _unitsService.GetUnitStateById(eventId); model.RunOn = DateTime.UtcNow.TimeConverter(model.Department); eventJson.UnitName = eventRecord.Unit.Name; eventJson.State = StringHelpers.GetDescription(((UnitStateTypes)eventRecord.State)); eventJson.Timestamp = eventRecord.Timestamp.TimeConverterToString(model.Department).ToString(); eventJson.Note = eventRecord.Note; if (((UnitStateTypes)eventRecord.State) == UnitStateTypes.Enroute) { if (eventRecord.DestinationId.HasValue) { var station = _departmentGroupsService.GetGroupById(eventRecord.DestinationId.Value, false); if (station != null) { eventJson.DestinationName = station.Name; } else { eventJson.DestinationName = "Station"; } } else { eventJson.DestinationName = "Station"; } } else if (((UnitStateTypes)eventRecord.State) == UnitStateTypes.Responding || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Committed || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.OnScene || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Staging || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Released || ((UnitStateTypes)eventRecord.State) == UnitStateTypes.Cancelled) { if (eventRecord.DestinationId.HasValue) { var call = _callsService.GetCallById(eventRecord.DestinationId.Value, false); if (call != null) { eventJson.DestinationName = call.Name; } else { eventJson.DestinationName = "Scene"; } } } if (eventRecord.LocalTimestamp.HasValue) { eventJson.LocalTimestamp = eventRecord.LocalTimestamp.Value.ToString(); } if (eventRecord.Latitude.HasValue) { eventJson.Latitude = eventRecord.Latitude.Value.ToString(); } if (eventRecord.Longitude.HasValue) { eventJson.Longitude = eventRecord.Longitude.Value.ToString(); } model.Rows.Add(eventJson); } return(View("~/Areas/User/Views/Reports/UnitEventsReport.cshtml", model)); }