/// <summary> /// Gets all the meta-data around a call, dispatched personnel, units, groups and responses /// </summary> /// <param name="callId">CallId to get data for</param> /// <returns></returns> public CallDataResult GetCallExtraData(int callId) { var result = new CallDataResult(); var call = _callsService.GetCallById(callId); var groups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var units = _unitsService.GetUnitsForDepartment(call.DepartmentId); var unitStates = _unitsService.GetUnitStatesForCall(call.DepartmentId, callId).OrderBy(x => x.UnitId).OrderBy(y => y.Timestamp).ToList(); var actionLogs = _actionLogsService.GetActionLogsForCall(call.DepartmentId, callId).OrderBy(x => x.UserId).OrderBy(y => y.Timestamp).ToList(); var names = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, true, true, true); var priority = _callsService.GetCallPrioritesById(call.DepartmentId, call.Priority, false); if (priority != null) { result.Priority = new CallPriorityDataResult(); result.Priority.Id = priority.DepartmentCallPriorityId; result.Priority.DepartmentId = priority.DepartmentId; result.Priority.Name = priority.Name; result.Priority.Color = priority.Color; result.Priority.Sort = priority.Sort; result.Priority.IsDeleted = priority.IsDeleted; result.Priority.IsDefault = priority.IsDefault; result.Priority.DispatchPersonnel = priority.DispatchPersonnel; result.Priority.DispatchUnits = priority.DispatchUnits; result.Priority.ForceNotifyAllPersonnel = priority.ForceNotifyAllPersonnel; result.Priority.Tone = priority.Tone; result.Priority.IsSystemPriority = priority.IsSystemPriority; } foreach (var actionLog in actionLogs) { var eventResult = new DispatchedEventResult(); eventResult.Id = actionLog.ActionLogId.ToString(); eventResult.Timestamp = actionLog.Timestamp; eventResult.Type = "User"; var name = names.FirstOrDefault(x => x.UserId == actionLog.UserId); if (name != null) { eventResult.Name = name.Name; if (name.DepartmentGroupId.HasValue) { eventResult.GroupId = name.DepartmentGroupId.Value; eventResult.Group = name.DepartmentGroupName; } } else { eventResult.Name = "Unknown User"; } eventResult.StatusId = actionLog.ActionTypeId; eventResult.Location = actionLog.GeoLocationData; eventResult.Note = actionLog.Note; result.Activity.Add(eventResult); } foreach (var unitLog in unitStates) { var eventResult = new DispatchedEventResult(); eventResult.Id = unitLog.UnitStateId.ToString(); eventResult.Timestamp = unitLog.Timestamp; eventResult.Type = "Unit"; eventResult.Name = unitLog.Unit.Name; var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unitLog.Unit.StationGroupId); if (group != null) { eventResult.GroupId = group.DepartmentGroupId; eventResult.Group = group.Name; } eventResult.StatusId = eventResult.StatusId; eventResult.Location = eventResult.Location; eventResult.Note = eventResult.Note; result.Activity.Add(eventResult); } foreach (var dispatch in call.Dispatches) { var eventResult = new DispatchedEventResult(); eventResult.Id = dispatch.UserId; if (dispatch.LastDispatchedOn.HasValue) { eventResult.Timestamp = dispatch.LastDispatchedOn.Value; } eventResult.Type = "User"; var name = names.FirstOrDefault(x => x.UserId == dispatch.UserId); if (name != null) { eventResult.Name = name.Name; if (name.DepartmentGroupId.HasValue) { eventResult.GroupId = name.DepartmentGroupId.Value; eventResult.Group = name.DepartmentGroupName; } } else { eventResult.Name = "Unknown User"; } result.Dispatches.Add(eventResult); } if (call.GroupDispatches != null && call.GroupDispatches.Any()) { foreach (var groupDispatch in call.GroupDispatches) { var eventResult = new DispatchedEventResult(); eventResult.Id = groupDispatch.DepartmentGroupId.ToString(); if (groupDispatch.LastDispatchedOn.HasValue) { eventResult.Timestamp = groupDispatch.LastDispatchedOn.Value; } eventResult.Type = "Group"; var name = groups.FirstOrDefault(x => x.DepartmentGroupId == groupDispatch.DepartmentGroupId); if (name != null) { eventResult.Name = name.Name; eventResult.GroupId = name.DepartmentGroupId; eventResult.Group = name.Name; } else { eventResult.Name = "Unknown Group"; } result.Dispatches.Add(eventResult); } } if (call.UnitDispatches != null && call.UnitDispatches.Any()) { foreach (var unitDispatch in call.UnitDispatches) { var eventResult = new DispatchedEventResult(); eventResult.Id = unitDispatch.UnitId.ToString(); if (unitDispatch.LastDispatchedOn.HasValue) { eventResult.Timestamp = unitDispatch.LastDispatchedOn.Value; } eventResult.Type = "Unit"; var unit = units.FirstOrDefault(x => x.UnitId == unitDispatch.UnitId); if (unit != null) { eventResult.Name = unit.Name; if (unit.StationGroupId.HasValue) { var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unit.StationGroupId.GetValueOrDefault()); if (group != null) { eventResult.GroupId = group.DepartmentGroupId; eventResult.Group = group.Name; } } } else { eventResult.Name = "Unknown Unit"; } result.Dispatches.Add(eventResult); } } return(result); }