public async Task <bool> SendTroubleAlert(TroubleAlertEvent troubleAlertEvent, Unit unit, Call call, string callAddress, string unitAddress, string personnelNames, UserProfile profile) { if (Config.SystemBehaviorConfig.DoNotBroadcast && !Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(unit.DepartmentId)) { return(false); } string emailAddress = string.Empty; if (profile.User != null && profile.User != null) { emailAddress = profile.User.Email; } else { //Logging.LogError(string.Format("Send Call Email (Missing User Membership): {0} User: {1}", call.CallId, dispatch.UserId)); var user = _usersService.GetUserById(profile.UserId, false); if (user != null && user != null) { emailAddress = user.Email; } } string subject = $"TROUBLE ALERT for {unit.Name} located at {unitAddress}"; string dispatchedOn = String.Empty; if (call.Department != null) { dispatchedOn = troubleAlertEvent.TimeStamp.Value.FormatForDepartment(call.Department); } else { dispatchedOn = troubleAlertEvent.TimeStamp.Value.ToString("G") + " UTC"; } string gpsLocation = "No Unit GPS Location"; if (!String.IsNullOrWhiteSpace(troubleAlertEvent.Latitude) && !String.IsNullOrWhiteSpace(troubleAlertEvent.Longitude)) { gpsLocation = $"{troubleAlertEvent.Latitude},{troubleAlertEvent.Longitude}"; } if (profile != null && profile.SendEmail && !String.IsNullOrWhiteSpace(emailAddress)) { await _emailProvider.SendTroubleAlertMail(emailAddress, unit.Name, gpsLocation, "", callAddress, unitAddress, "", call.Name); return(true); } return(false); }