//[Test] public void should_be_able_to_send_call() { Call call = new Call(); call.DepartmentId = 1; call.Name = "Priority 1E Cardiac Arrest D12"; call.NatureOfCall = "RP reports a person lying on the street not breathing."; call.Notes = "RP doesn't know how to do CPR, can't roll over patient"; call.MapPage = "22T"; call.GeoLocationData = "39.27710789298309,-119.77201511943328"; call.Dispatches = new Collection <CallDispatch>(); call.LoggedOn = DateTime.Now; call.ReportingUserId = TestData.Users.TestUser1Id; CallDispatch cd = new CallDispatch(); cd.UserId = TestData.Users.TestUser1Id; call.Dispatches.Add(cd); CallDispatch cd1 = new CallDispatch(); cd1.UserId = TestData.Users.TestUser2Id; call.Dispatches.Add(cd1); _communicationService.SendCall(call, cd, null, 1, null); _smsServiceMock.Verify(m => m.SendCall(call, cd, null, 1, null, null)); _emailServiceMock.Verify(m => m.SendCall(call, cd, null)); //_pushServiceMock.Verify(m => m.PushCall(It.IsAny<StandardPushCall>(), Users.TestUser1Id)); }
public void should_be_able_to_get_a_call() { Call call = new Call(); call.DepartmentId = 1; call.Name = "Priority 1E Cardiac Arrest D12"; call.NatureOfCall = "RP reports a person lying on the street not breathing."; call.Notes = "RP doesn't know how to do CPR, can't roll over patient"; call.MapPage = "22T"; call.GeoLocationData = "39.27710789298309,-119.77201511943328"; call.Dispatches = new Collection <CallDispatch>(); call.LoggedOn = DateTime.Now; call.ReportingUserId = TestData.Users.TestUser1Id; CallDispatch cd = new CallDispatch(); cd.UserId = TestData.Users.TestUser2Id; call.Dispatches.Add(cd); CallDispatch cd1 = new CallDispatch(); cd1.UserId = TestData.Users.TestUser3Id; call.Dispatches.Add(cd1); _callsService.SaveCall(call); var call2 = _callsService.GetCallById(call.CallId); call2.Should().NotBeNull(); call2.CallId.Should().NotBe(0); call2.Dispatches.Should().NotBeNull(); call2.Dispatches.Count.Should().Be(2); call2.Should().BeSameAs(call); }
public Call GenerateCall(CallEmail email, string managingUser, List<IdentityUser> users, Department department, List<Call> activeCalls, List<Unit> units, int priority) { if (email == null) return null; if (String.IsNullOrEmpty(email.Body)) return null; if (String.IsNullOrEmpty(email.Subject)) return null; Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Body; c.Name = "Call Email Import"; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection<CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; c.Address = email.Subject.Trim(); foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return c; }
public void should_be_null_for_no_protocol() { Call call = new Call(); call.DepartmentId = 1; call.Name = "Priority 1E Cardiac Arrest D12"; call.NatureOfCall = "RP reports a person lying on the street not breathing."; call.Notes = "RP doesn't know how to do CPR, can't roll over patient"; call.MapPage = "22T"; call.GeoLocationData = "39.27710789298309,-119.77201511943328"; call.Dispatches = new Collection <CallDispatch>(); call.LoggedOn = DateTime.Now; call.ReportingUserId = TestData.Users.TestUser1Id; CallDispatch cd = new CallDispatch(); cd.UserId = TestData.Users.TestUser2Id; call.Dispatches.Add(cd); CallDispatch cd1 = new CallDispatch(); cd1.UserId = TestData.Users.TestUser3Id; call.Dispatches.Add(cd1); var triggers = _protocolService.DetermineActiveTriggers(null, call); triggers.Should().BeNull(); }
private Call CreateNewCallFromCall(Call call) { Call newCall = new Call(); newCall.Number = call.Number; newCall.DepartmentId = call.DepartmentId; newCall.ReportingUserId = call.ReportingUserId; newCall.Priority = call.Priority; newCall.IsCritical = call.IsCritical; newCall.Type = call.Type; newCall.IncidentNumber = call.IncidentNumber; newCall.Name = call.Name; newCall.NatureOfCall = call.NatureOfCall; newCall.MapPage = call.MapPage; newCall.Notes = call.Notes; newCall.CompletedNotes = call.CompletedNotes; newCall.Address = call.Address; newCall.GeoLocationData = call.GeoLocationData; newCall.LoggedOn = call.LoggedOn; newCall.ClosedByUserId = call.ClosedByUserId; newCall.ClosedOn = call.ClosedOn; newCall.State = call.State; newCall.IsDeleted = call.IsDeleted; newCall.CallSource = call.CallSource; newCall.SourceIdentifier = call.SourceIdentifier; newCall.State = call.State; if (call.Dispatches != null && call.Dispatches.Any()) { newCall.Dispatches = new List <CallDispatch>(); foreach (var callDispatch in call.Dispatches) { var cd = new CallDispatch(); cd.UserId = callDispatch.UserId; newCall.Dispatches.Add(cd); } } if (call.Attachments != null && call.Attachments.Any()) { newCall.Attachments = new List <CallAttachment>(); foreach (var callAttahment in call.Attachments) { var ca = new CallAttachment(); ca.CallAttachmentType = callAttahment.CallAttachmentType; ca.Data = callAttahment.Data; ca.FileName = callAttahment.FileName; newCall.Attachments.Add(ca); } } return(newCall); }
public Call GenerateCall(InboundMessage email, string managingUser, List <string> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.HtmlBody)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } if (!(email.Subject.Contains("300") && email.Subject.Contains("ALERT"))) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.HtmlBody; c.NatureOfCall = email.Subject + " " + email.HtmlBody; c.Name = email.Subject; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new List <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageID; // Disabling for now. -SJ //if (email.DispatchAudio != null) //{ // c.Attachments = new Collection<CallAttachment>(); // CallAttachment ca = new CallAttachment(); // ca.FileName = email.DispatchAudioFileName; // ca.Data = email.DispatchAudio; // ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio; // c.Attachments.Add(ca); //} foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } if (!email.Subject.ToLower().Contains("page")) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Subject + " " + email.Body; c.Name = email.Subject; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (email.DispatchAudio != null) { c.Attachments = new Collection <CallAttachment>(); CallAttachment ca = new CallAttachment(); ca.FileName = email.DispatchAudioFileName; ca.Data = email.DispatchAudio; ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio; c.Attachments.Add(ca); } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public void should_have_value_for_prioritystartend_trigger() { DispatchProtocol procotol = new DispatchProtocol(); procotol.DepartmentId = 1; procotol.Name = ""; procotol.Code = ""; procotol.IsDisabled = false; procotol.Description = ""; procotol.ProtocolText = ""; procotol.CreatedOn = DateTime.UtcNow; procotol.CreatedByUserId = TestData.Users.TestUser1Id; procotol.UpdatedOn = DateTime.UtcNow; procotol.MinimumWeight = 10; procotol.UpdatedByUserId = TestData.Users.TestUser1Id; procotol.Triggers = new List <DispatchProtocolTrigger>(); DispatchProtocolTrigger trigger1 = new DispatchProtocolTrigger(); trigger1.Type = (int)ProtocolTriggerTypes.CallPriorty; trigger1.StartsOn = DateTime.UtcNow.AddDays(-1); trigger1.EndsOn = DateTime.UtcNow.AddDays(1); trigger1.Priority = (int)CallPriority.Emergency; procotol.Triggers.Add(trigger1); Call call = new Call(); call.DepartmentId = 1; call.Name = "Priority 1E Cardiac Arrest D12"; call.NatureOfCall = "RP reports a person lying on the street not breathing."; call.Notes = "RP doesn't know how to do CPR, can't roll over patient"; call.MapPage = "22T"; call.GeoLocationData = "39.27710789298309,-119.77201511943328"; call.Dispatches = new Collection <CallDispatch>(); call.LoggedOn = DateTime.Now; call.ReportingUserId = TestData.Users.TestUser1Id; call.Priority = (int)CallPriority.Emergency; CallDispatch cd = new CallDispatch(); cd.UserId = TestData.Users.TestUser2Id; call.Dispatches.Add(cd); CallDispatch cd1 = new CallDispatch(); cd1.UserId = TestData.Users.TestUser3Id; call.Dispatches.Add(cd1); var triggers = _protocolService.DetermineActiveTriggers(procotol, call); triggers.Should().NotBeNullOrEmpty(); triggers.Should().HaveCount(1); }
public Call GenerateCall(InboundMessage email, string managingUser, List <string> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.HtmlBody)) { return(null); } Call c = new Call(); c.Notes = email.HtmlBody; string[] data = email.HtmlBody.Split(char.Parse(";")); c.IncidentNumber = data[0].Replace("Inc# ", "").Trim(); c.Type = data[1].Trim(); try { int end = data[6].IndexOf(">Map"); c.GeoLocationData = data[6].Substring(37, end - 38); } catch { } c.NatureOfCall = data[1].Trim() + " " + data[7]; c.Address = data[2].Trim(); c.Name = data[1].Trim() + " " + data[7]; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new List <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageID; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(InboundMessage email, string managingUser, List <string> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.HtmlBody)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } string[] data = email.HtmlBody.Split(char.Parse("/")); Call c = new Call(); c.Notes = email.Subject + " " + email.HtmlBody; c.NatureOfCall = email.HtmlBody; c.Name = email.Subject; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new List <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageID; if (data != null && data.Length > 0) { c.Name = data[2]; c.Address = data[3]; } foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u; c.Dispatches.Add(cd); } return(c); }
public void should_be_null_for_disabled_protocol() { DispatchProtocol procotol = new DispatchProtocol(); procotol.DepartmentId = 1; procotol.Name = ""; procotol.Code = ""; procotol.IsDisabled = true; procotol.Description = ""; procotol.ProtocolText = ""; procotol.CreatedOn = DateTime.UtcNow; procotol.CreatedByUserId = TestData.Users.TestUser1Id; procotol.UpdatedOn = DateTime.UtcNow; procotol.MinimumWeight = 10; procotol.UpdatedByUserId = TestData.Users.TestUser1Id; Call call = new Call(); call.DepartmentId = 1; call.Name = "Priority 1E Cardiac Arrest D12"; call.NatureOfCall = "RP reports a person lying on the street not breathing."; call.Notes = "RP doesn't know how to do CPR, can't roll over patient"; call.MapPage = "22T"; call.GeoLocationData = "39.27710789298309,-119.77201511943328"; call.Dispatches = new Collection <CallDispatch>(); call.LoggedOn = DateTime.Now; call.ReportingUserId = TestData.Users.TestUser1Id; CallDispatch cd = new CallDispatch(); cd.UserId = TestData.Users.TestUser2Id; call.Dispatches.Add(cd); CallDispatch cd1 = new CallDispatch(); cd1.UserId = TestData.Users.TestUser3Id; call.Dispatches.Add(cd1); var triggers = _protocolService.DetermineActiveTriggers(procotol, call); triggers.Should().BeNull(); }
public Call GenerateCall(InboundMessage email, string managingUser, List <string> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.HtmlBody)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.HtmlBody; c.NatureOfCall = email.HtmlBody; c.Name = "Call Email Import"; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new List <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageID; c.Address = email.Subject.Trim(); foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u; c.Dispatches.Add(cd); } return(c); }
public async Task <bool> SendCallAsync(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null) { if (Config.SystemBehaviorConfig.DoNotBroadcast && !Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId)) { return(false); } if (profile == null) { profile = await _userProfileService.GetProfileByUserIdAsync(dispatch.UserId); } if (profile != null && profile.SendSms) { if (String.IsNullOrWhiteSpace(address)) { if (!String.IsNullOrWhiteSpace(call.Address)) { address = call.Address; } else if (!string.IsNullOrEmpty(call.GeoLocationData)) { try { string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { address = await _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])); } } catch { } } } if (Config.SystemBehaviorConfig.DepartmentsToForceSmsGateway.Contains(departmentId)) { string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall); text = StringHelpers.StripHtmlTagsCharArray(text); text = text + " " + address; if (call.Protocols != null && call.Protocols.Any()) { string protocols = String.Empty; foreach (var protocol in call.Protocols) { if (!String.IsNullOrWhiteSpace(protocol.Data)) { if (String.IsNullOrWhiteSpace(protocols)) { protocols = protocol.Data; } else { protocols = protocol + "," + protocol.Data; } } } if (!String.IsNullOrWhiteSpace(protocols)) { text = text + " (" + protocols + ")"; } } if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl)) { text = text + " " + call.ShortenedAudioUrl; } //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl)) //{ // text = text + " " + call.ShortenedCallUrl; //} _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, true, true); if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally) { SendCallViaEmailSmsGateway(call, address, profile); } } else if (Carriers.DirectSendCarriers.Contains((MobileCarriers)profile.MobileCarrier)) { string text = HtmlToTextHelper.ConvertHtml(call.NatureOfCall); text = StringHelpers.StripHtmlTagsCharArray(text); text = text + " " + address; if (call.Protocols != null && call.Protocols.Any()) { string protocols = String.Empty; foreach (var protocol in call.Protocols) { if (!String.IsNullOrWhiteSpace(protocol.Data)) { if (String.IsNullOrWhiteSpace(protocols)) { protocols = protocol.Data; } else { protocols = protocol + "," + protocol.Data; } } } if (!String.IsNullOrWhiteSpace(protocols)) { text = text + " (" + protocols + ")"; } } if (!String.IsNullOrWhiteSpace(call.ShortenedAudioUrl)) { text = text + " " + call.ShortenedAudioUrl; } //else if (!String.IsNullOrWhiteSpace(call.ShortenedCallUrl)) //{ // text = text + " " + call.ShortenedCallUrl; //} _textMessageProvider.SendTextMessage(profile.GetPhoneNumber(), FormatTextForMessage(call.Name, text), departmentNumber, (MobileCarriers)profile.MobileCarrier, departmentId, false, true); if (Config.SystemBehaviorConfig.SendCallsToSmsEmailGatewayAdditionally) { SendCallViaEmailSmsGateway(call, address, profile); } } else { SendCallViaEmailSmsGateway(call, address, profile); } } return(true); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (!email.Subject.Contains("Parkland County Incident") && !email.Subject.Contains("Incident Message")) { return(null); } var c = new Call(); c.Notes = email.Body; try { var data = new List <string>(); string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); if (rawData != null && rawData.Any()) { foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s)) { data.Add(s); } } if (data.Count > 0) { c.Name = data[1].Trim().Replace("Type: ", ""); try { var location = data.FirstOrDefault(x => x.StartsWith("Location:")); if (!String.IsNullOrWhiteSpace(location)) { c.Address = location.Replace("//", "").Replace("Business Name:", ""); } var coordinates = data.FirstOrDefault(x => x.Contains("(") && x.Contains(")")); if (!String.IsNullOrWhiteSpace(coordinates)) { coordinates = coordinates.Replace("Common Place:", ""); coordinates = coordinates.Trim(); c.GeoLocationData = coordinates.Replace("(", "").Replace(")", ""); } } catch { } } } else { c.Name = "Call Import Type: Unknown"; } } catch { c.Name = "Call Import Type: Unknown"; } c.NatureOfCall = email.Body; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body) && String.IsNullOrWhiteSpace(email.TextBody)) { return(null); } string body = String.Empty; if (!String.IsNullOrWhiteSpace(email.TextBody)) { body = email.TextBody; } else { body = email.Body; } var c = new Call(); c.Notes = email.TextBody; if (String.IsNullOrWhiteSpace(c.Notes)) { c.Notes = email.Body; } string[] data = body.Split(char.Parse(",")); if (data == null || data.Length <= 2) { return(null); } c.IncidentNumber = data[0].Replace("(", "").Replace(")", "").Trim(); c.Type = data[1].Trim(); string address = String.Empty; string coordinates = String.Empty; int gpsCount = 0; for (int i = 2; i < data.Length; i++) { if (data[i].Contains("//")) { break; } decimal myDec; if (!decimal.TryParse(data[i].Trim(), out myDec)) { if (String.IsNullOrWhiteSpace(address)) { address = data[i].Trim(); } else { address += string.Format(", {0}", data[i].Trim()); } } else { if (gpsCount >= 2) { break; } if (String.IsNullOrWhiteSpace(coordinates)) { coordinates = data[i].Trim(); } else { coordinates += string.Format(",{0}", data[i].Trim()); } gpsCount++; } } if (!String.IsNullOrWhiteSpace(address)) { c.Address = address.Trim(); } if (!String.IsNullOrWhiteSpace(coordinates)) { c.GeoLocationData = coordinates.Trim(); } c.NatureOfCall = data[data.Length - 1].Replace("//", "").Trim(); c.Name = string.Format("{0}-{1}", c.IncidentNumber, c.Type); c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public async Task <ActionResult> IncomingMessage([FromQuery] TwilioMessage request) { if (request == null || string.IsNullOrWhiteSpace(request.To) || string.IsNullOrWhiteSpace(request.From) || string.IsNullOrWhiteSpace(request.Body)) { return(BadRequest()); } var response = new MessagingResponse(); var textMessage = new TextMessage(); textMessage.To = request.To.Replace("+", ""); textMessage.Msisdn = request.From.Replace("+", ""); textMessage.MessageId = request.MessageSid; textMessage.Timestamp = DateTime.UtcNow.ToLongDateString(); textMessage.Data = request.Body; textMessage.Text = request.Body; var messageEvent = new InboundMessageEvent(); messageEvent.MessageType = (int)InboundMessageTypes.TextMessage; messageEvent.RecievedOn = DateTime.UtcNow; messageEvent.Type = typeof(InboundMessageEvent).FullName; messageEvent.Data = JsonConvert.SerializeObject(textMessage); messageEvent.Processed = false; messageEvent.CustomerId = ""; try { var departmentId = await _departmentSettingsService.GetDepartmentIdByTextToCallNumberAsync(textMessage.To); if (departmentId.HasValue) { var department = await _departmentsService.GetDepartmentByIdAsync(departmentId.Value); var textToCallEnabled = await _departmentSettingsService.GetDepartmentIsTextCallImportEnabledAsync(departmentId.Value); var textCommandEnabled = await _departmentSettingsService.GetDepartmentIsTextCommandEnabledAsync(departmentId.Value); var dispatchNumbers = await _departmentSettingsService.GetTextToCallSourceNumbersForDepartmentAsync(departmentId.Value); var authroized = await _limitsService.CanDepartmentProvisionNumberAsync(departmentId.Value); var customStates = await _customStateService.GetAllActiveCustomStatesForDepartmentAsync(departmentId.Value); messageEvent.CustomerId = departmentId.Value.ToString(); if (authroized) { bool isDispatchSource = false; if (!String.IsNullOrWhiteSpace(dispatchNumbers)) { isDispatchSource = _numbersService.DoesNumberMatchAnyPattern(dispatchNumbers.Split(Char.Parse(",")).ToList(), textMessage.Msisdn); } // If we don't have dispatchNumbers and Text Command isn't enabled it's a dispatch text if (!isDispatchSource && !textCommandEnabled) { isDispatchSource = true; } if (isDispatchSource && textToCallEnabled) { var c = new Call(); c.Notes = textMessage.Text; c.NatureOfCall = textMessage.Text; c.LoggedOn = DateTime.UtcNow; c.Name = string.Format("TTC {0}", c.LoggedOn.TimeConverter(department).ToString("g")); c.Priority = (int)CallPriority.High; c.ReportingUserId = department.ManagingUserId; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = textMessage.MessageId; c.DepartmentId = departmentId.Value; var users = await _departmentsService.GetAllUsersForDepartmentAsync(departmentId.Value, true); foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } var savedCall = await _callsService.SaveCallAsync(c); var cqi = new CallQueueItem(); cqi.Call = savedCall; cqi.Profiles = await _userProfileService.GetSelectedUserProfilesAsync(users.Select(x => x.UserId).ToList()); cqi.DepartmentTextNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(cqi.Call.DepartmentId); _queueService.EnqueueCallBroadcastAsync(cqi); messageEvent.Processed = true; } if (!isDispatchSource && textCommandEnabled) { var profile = await _userProfileService.GetProfileByMobileNumberAsync(textMessage.Msisdn); if (profile != null) { var payload = _textCommandService.DetermineType(textMessage.Text); var customActions = customStates.FirstOrDefault(x => x.Type == (int)CustomStateTypes.Personnel); var customStaffing = customStates.FirstOrDefault(x => x.Type == (int)CustomStateTypes.Staffing); switch (payload.Type) { case TextCommandTypes.None: response.Message("Resgrid (https://resgrid.com) Automated Text System. Unknown command, text help for supported commands."); break; case TextCommandTypes.Help: messageEvent.Processed = true; var help = new StringBuilder(); help.Append("Resgrid Text Commands" + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); help.Append("These are the commands you can text to alter your status and staffing. Text help for help." + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); help.Append("Core Commands" + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); help.Append("STOP: To turn off all text messages" + Environment.NewLine); help.Append("HELP: This help text" + Environment.NewLine); help.Append("CALLS: List active calls" + Environment.NewLine); help.Append("C[CallId]: Get Call Detail i.e. C1445" + Environment.NewLine); help.Append("UNITS: List unit statuses" + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); help.Append("Status or Action Commands" + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); if (customActions != null && customActions.IsDeleted == false && customActions.GetActiveDetails() != null && customActions.GetActiveDetails().Any()) { var activeDetails = customActions.GetActiveDetails(); for (int i = 0; i < activeDetails.Count; i++) { help.Append($"{activeDetails[i].ButtonText.Trim().Replace(" ", "").Replace("-", "").Replace(":", "")} or {i + 1}: {activeDetails[i].ButtonText}" + Environment.NewLine); } } else { help.Append("responding or 1: Responding" + Environment.NewLine); help.Append("notresponding or 2: Not Responding" + Environment.NewLine); help.Append("onscene or 3: On Scene" + Environment.NewLine); help.Append("available or 4: Available" + Environment.NewLine); } help.Append("---------------------" + Environment.NewLine); help.Append("Staffing Commands" + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); if (customStaffing != null && customStaffing.IsDeleted == false && customStaffing.GetActiveDetails() != null && customStaffing.GetActiveDetails().Any()) { var activeDetails = customStaffing.GetActiveDetails(); for (int i = 0; i < activeDetails.Count; i++) { help.Append($"{activeDetails[i].ButtonText.Trim().Replace(" ", "").Replace("-", "").Replace(":", "")} or S{i + 1}: {activeDetails[i].ButtonText}" + Environment.NewLine); } } else { help.Append("available or s1: Available Staffing" + Environment.NewLine); help.Append("delayed or s2: Delayed Staffing" + Environment.NewLine); help.Append("unavailable or s3: Unavailable Staffing" + Environment.NewLine); help.Append("committed or s4: Committed Staffing" + Environment.NewLine); help.Append("onshift or s4: On Shift Staffing" + Environment.NewLine); } response.Message(help.ToString()); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", help.ToString(), department.DepartmentId, textMessage.To, profile); break; case TextCommandTypes.Action: messageEvent.Processed = true; await _actionLogsService.SetUserActionAsync(profile.UserId, department.DepartmentId, (int)payload.GetActionType()); response.Message(string.Format("Resgrid received your text command. Status changed to: {0}", payload.GetActionType())); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Status", string.Format("Resgrid recieved your text command. Status changed to: {0}", payload.GetActionType()), department.DepartmentId, textMessage.To, profile); break; case TextCommandTypes.Staffing: messageEvent.Processed = true; await _userStateService.CreateUserState(profile.UserId, department.DepartmentId, (int)payload.GetStaffingType()); response.Message(string.Format("Resgrid received your text command. Staffing level changed to: {0}", payload.GetStaffingType())); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Staffing", string.Format("Resgrid recieved your text command. Staffing level changed to: {0}", payload.GetStaffingType()), department.DepartmentId, textMessage.To, profile); break; case TextCommandTypes.Stop: messageEvent.Processed = true; await _userProfileService.DisableTextMessagesForUserAsync(profile.UserId); response.Message("Text messages are now turned off for this user, to enable again log in to Resgrid and update your profile."); break; case TextCommandTypes.CustomAction: messageEvent.Processed = true; await _actionLogsService.SetUserActionAsync(profile.UserId, department.DepartmentId, payload.GetCustomActionType()); if (customActions != null && customActions.IsDeleted == false && customActions.GetActiveDetails() != null && customActions.GetActiveDetails().Any() && customActions.GetActiveDetails().FirstOrDefault(x => x.CustomStateDetailId == payload.GetCustomActionType()) != null) { var detail = customActions.GetActiveDetails().FirstOrDefault(x => x.CustomStateDetailId == payload.GetCustomActionType()); response.Message(string.Format("Resgrid received your text command. Status changed to: {0}", detail.ButtonText)); } else { response.Message("Resgrid received your text command and updated your status"); } break; case TextCommandTypes.CustomStaffing: messageEvent.Processed = true; await _userStateService.CreateUserState(profile.UserId, department.DepartmentId, payload.GetCustomStaffingType()); if (customStaffing != null && customStaffing.IsDeleted == false && customStaffing.GetActiveDetails() != null && customStaffing.GetActiveDetails().Any() && customStaffing.GetActiveDetails().FirstOrDefault(x => x.CustomStateDetailId == payload.GetCustomStaffingType()) != null) { var detail = customStaffing.GetActiveDetails().FirstOrDefault(x => x.CustomStateDetailId == payload.GetCustomStaffingType()); response.Message(string.Format("Resgrid received your text command. Staffing changed to: {0}", detail.ButtonText)); } else { response.Message("Resgrid received your text command and updated your staffing"); } break; case TextCommandTypes.MyStatus: messageEvent.Processed = true; var userStatus = await _actionLogsService.GetLastActionLogForUserAsync(profile.UserId); var userStaffing = await _userStateService.GetLastUserStateByUserIdAsync(profile.UserId); var customStatusLevel = await _customStateService.GetCustomPersonnelStatusAsync(department.DepartmentId, userStatus); var customStaffingLevel = await _customStateService.GetCustomPersonnelStaffingAsync(department.DepartmentId, userStaffing); response.Message($"Hello {profile.FullName.AsFirstNameLastName} at {DateTime.UtcNow.TimeConverterToString(department)} your current status is {customStatusLevel.ButtonText} and your current staffing is {customStaffingLevel.ButtonText}."); break; case TextCommandTypes.Calls: messageEvent.Processed = true; var activeCalls = await _callsService.GetActiveCallsByDepartmentAsync(department.DepartmentId); var activeCallText = new StringBuilder(); activeCallText.Append($"Active Calls for {department.Name}" + Environment.NewLine); activeCallText.Append("---------------------" + Environment.NewLine); foreach (var activeCall in activeCalls) { activeCallText.Append($"CallId: {activeCall.CallId} Name: {activeCall.Name} Nature:{activeCall.NatureOfCall}" + Environment.NewLine); } response.Message(activeCallText.ToString()); break; case TextCommandTypes.Units: messageEvent.Processed = true; var unitStatus = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(department.DepartmentId); var unitStatusesText = new StringBuilder(); unitStatusesText.Append($"Unit Statuses for {department.Name}" + Environment.NewLine); unitStatusesText.Append("---------------------" + Environment.NewLine); foreach (var unit in unitStatus) { var unitState = await _customStateService.GetCustomUnitStateAsync(unit); unitStatusesText.Append($"{unit.Unit.Name} is {unitState.ButtonText}" + Environment.NewLine); } response.Message(unitStatusesText.ToString()); break; case TextCommandTypes.CallDetail: messageEvent.Processed = true; var call = await _callsService.GetCallByIdAsync(int.Parse(payload.Data)); var callText = new StringBuilder(); callText.Append($"Call Information for {call.Name}" + Environment.NewLine); callText.Append("---------------------" + Environment.NewLine); callText.Append($"Id: {call.CallId}" + Environment.NewLine); callText.Append($"Number: {call.Number}" + Environment.NewLine); callText.Append($"Logged: {call.LoggedOn.TimeConverterToString(department)}" + Environment.NewLine); callText.Append("-----Nature-----" + Environment.NewLine); callText.Append(call.NatureOfCall + Environment.NewLine); callText.Append("-----Address-----" + Environment.NewLine); if (!String.IsNullOrWhiteSpace(call.Address)) { callText.Append(call.Address + Environment.NewLine); } else if (!string.IsNullOrEmpty(call.GeoLocationData)) { try { string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { callText.Append(_geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])) + Environment.NewLine); } } catch { } } response.Message(callText.ToString()); break; } } } } } else if (textMessage.To == "17753765253") // Resgrid master text number { var profile = await _userProfileService.GetProfileByMobileNumberAsync(textMessage.Msisdn); var payload = _textCommandService.DetermineType(textMessage.Text); switch (payload.Type) { case TextCommandTypes.None: response.Message("Resgrid (https://resgrid.com) Automated Text System. Unknown command, text help for supported commands."); break; case TextCommandTypes.Help: messageEvent.Processed = true; var help = new StringBuilder(); help.Append("Resgrid Text Commands" + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); help.Append("This is the Resgrid system for first responders (https://resgrid.com) automated text system. Your department isn't signed up for inbound text messages, but you can send the following commands." + Environment.NewLine); help.Append("---------------------" + Environment.NewLine); help.Append("STOP: To turn off all text messages" + Environment.NewLine); help.Append("HELP: This help text" + Environment.NewLine); response.Message(help.ToString()); break; case TextCommandTypes.Stop: messageEvent.Processed = true; await _userProfileService.DisableTextMessagesForUserAsync(profile.UserId); response.Message("Text messages are now turned off for this user, to enable again log in to Resgrid and update your profile."); break; } } } catch (Exception ex) { Framework.Logging.LogException(ex); } finally { await _numbersService.SaveInboundMessageEventAsync(messageEvent); } //Ok(); //var response = new TwilioResponse(); //return Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter()); return(Ok(new StringContent(response.ToString(), Encoding.UTF8, "application/xml"))); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body) && String.IsNullOrWhiteSpace(email.TextBody)) { return(null); } string body = String.Empty; if (!String.IsNullOrWhiteSpace(email.TextBody)) { body = email.TextBody; } else { body = email.Body; } body = body.Replace("-- Confidentiality Notice --", ""); body = body.Replace( "This email message, including all the attachments, is for the sole use of the intended recipient(s) and contains confidential information. Unauthorized use or disclosure is prohibited.", ""); body = body.Replace( "If you are not the intended recipient, you may not use, disclose, copy or disseminate this information.", ""); body = body.Replace( "If you are not the intended recipient, please contact the sender immediately by reply email and destroy all copies of the original message,", ""); body = body.Replace( "including attachments.", ""); body = body.Trim(); var c = new Call(); c.Notes = email.TextBody; if (String.IsNullOrWhiteSpace(c.Notes)) { c.Notes = email.Body; } string[] data = body.Split(char.Parse(":")); c.IncidentNumber = data[1].Replace(" L", "").Trim(); c.Type = data[3].Replace(" X", "").Trim().Replace("/", ""); c.Address = data[2].Replace(" T", "").Trim().Replace("/", ""); c.NatureOfCall = data[4].Trim(); c.Name = c.Type + " " + c.NatureOfCall; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.TextBody)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } if (!email.Subject.ToLower().Contains("active")) { return(null); } Call c = new Call(); // For 7966 if (department == null || department.DepartmentId != 7966) { c.Notes = email.TextBody; } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; string[] lines = email.TextBody.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); var sb = new StringBuilder(); sb.Append("<p>"); foreach (var line in lines) { var trimmedLine = line.Trim(); if (!String.IsNullOrWhiteSpace(trimmedLine)) { if (trimmedLine.ToLower().StartsWith("call:")) { c.Name = trimmedLine.Replace("CALL:", "").Trim(); sb.Append(trimmedLine + "</br>"); if (department != null && department.DepartmentId == 7966) { string[] typePrioline = c.Name.Split(new[] { " " }, StringSplitOptions.None); c.Type = typePrioline[0].Trim(); c.Priority = ParseCallPriority(typePrioline[0].Trim(), priority, activePriorities); } } else if (trimmedLine.ToLower().StartsWith("addr:")) { //c.GeoLocationData = trimmedLine.Replace("ADDR:", "").Trim(); sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("addr1:")) { c.Address = trimmedLine.Replace("ADDR1:", "").Trim(); sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("id:")) { c.IncidentNumber = trimmedLine.Replace("ID:", "").Trim(); c.ExternalIdentifier = c.IncidentNumber; if (department != null && department.DepartmentId == 7966) { c.ReferenceNumber = ParseIncidentNumber(trimmedLine); } sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("map:")) { c.GeoLocationData = trimmedLine.Replace("MAP:", "").Replace("http://www.google.com/maps/place/", "").Trim(); } else if (trimmedLine.ToLower().StartsWith("date/time:")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("date/time:")) { sb.Append(trimmedLine + "</br>"); } else if (trimmedLine.ToLower().StartsWith("narr:")) { sb.Append(trimmedLine.Replace("NARR:", "").Trim() + "</br>"); } } } sb.Append("</p>"); c.NatureOfCall = sb.ToString(); foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } // Search for an active call if (activeCalls != null && activeCalls.Any()) { var activeCall = activeCalls.FirstOrDefault(x => x.IncidentNumber == c.IncidentNumber); if (activeCall != null) { if (department == null || department.DepartmentId != 7966) { activeCall.Notes = c.Notes; } else { c.NatureOfCall = sb.ToString(); } activeCall.LastDispatchedOn = DateTime.UtcNow; return(activeCall); } } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } //if (String.IsNullOrEmpty(email.Subject)) // return null; Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.NatureOfCall = email.Body; c.Name = "Call Email Import"; c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); if (rawData != null && rawData.Any()) { foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s) && s.StartsWith("La", StringComparison.InvariantCultureIgnoreCase)) { string[] geoData = s.Split(new string[] { " " }, StringSplitOptions.None); if (geoData != null && geoData.Length == 2) { var latDMS = geoData[0].Replace(" grader ", ",").Replace("La = ", "").Replace("'N", "").Trim(); var lonDMS = geoData[1].Replace(" grader ", ",").Replace("Lo = ", "").Replace("'E", "").Trim(); if (!String.IsNullOrWhiteSpace(latDMS) && !String.IsNullOrWhiteSpace(lonDMS)) { string[] latValues = latDMS.Split(new string[] { "," }, StringSplitOptions.None); string[] lonValues = lonDMS.Split(new string[] { "," }, StringSplitOptions.None); double lat = 0; if (latValues != null && latValues.Length == 3) { lat = LocationHelpers.ConvertDegreesToDecimal(latValues[0].Trim(), latValues[1].Trim(), latValues[2].Trim()); } double lon = 0; if (lonValues != null && lonValues.Length == 3) { lon = LocationHelpers.ConvertDegreesToDecimal(lonValues[0].Trim(), lonValues[1].Trim(), lonValues[2].Trim()); } if (lat != 0 && lon != 0) { c.GeoLocationData = $"{lat},{lon}"; } } } } } } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { //ID | TYPE | PRIORITY | ADDRESS | MAPPAGE | NATURE | NOTES if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } Call c = new Call(); c.Notes = email.Body; string[] data = email.Body.Split(char.Parse("|")); if (data.Any() && data.Length >= 5) { if (!string.IsNullOrEmpty(data[0])) { c.IncidentNumber = data[0].Trim(); } if (!string.IsNullOrEmpty(data[1])) { c.Type = data[1].Trim(); } if (string.IsNullOrEmpty(data[2])) { int prio; if (int.TryParse(data[2], out prio)) { c.Priority = prio; } else { c.Priority = priority; } } else { c.Priority = priority; } if (!string.IsNullOrEmpty(data[4])) { c.MapPage = data[4]; } c.NatureOfCall = data[5]; c.Address = data[3]; StringBuilder title = new StringBuilder(); title.Append("Email Call "); title.Append(((CallPriority)c.Priority).ToString()); title.Append(" "); if (!string.IsNullOrEmpty(c.Type)) { title.Append(c.Type); title.Append(" "); } if (!string.IsNullOrEmpty(c.IncidentNumber)) { title.Append(c.IncidentNumber); title.Append(" "); } c.Name = title.ToString(); } else { c.Name = email.Subject; c.NatureOfCall = email.Body; c.Notes = "WARNING: FALLBACK RESGRID EMAIL IMPORT! THIS EMAIL MAY NOT BE THE CORRECT FORMAT FOR THE RESGRID EMAIL TEMPLATE. CONTACT SUPPORT IF THE EMAIL AND TEMPLATE ARE CORRECT." + email.Body; } c.LoggedOn = DateTime.UtcNow; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority, List <DepartmentCallPriority> activePriorities) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } Call c = new Call(); c.Notes = email.Body; c.Name = email.Subject; int nonEmptyLineCount = 0; string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); foreach (var line in rawData) { if (line != null && !String.IsNullOrWhiteSpace(line)) { nonEmptyLineCount++; switch (nonEmptyLineCount) { case 1: //c.Name = line.Trim(); c.NatureOfCall = line.Trim(); break; case 2: // Address //c.Name = $"{c.Name} {line}"; c.NatureOfCall = c.NatureOfCall + " " + line; break; case 3: // Map and Radio Channel break; case 4: // Cross Street break; case 5: // Cross Street 2 break; } } } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public HttpResponseMessage SaveCall([FromBody] NewCallInput newCallInput) { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } var call = new Call { DepartmentId = DepartmentId, ReportingUserId = UserId, Priority = (int)Enum.Parse(typeof(CallPriority), newCallInput.Pri), Name = newCallInput.Nme, NatureOfCall = newCallInput.Noc }; if (!string.IsNullOrWhiteSpace(newCallInput.CNme)) { call.ContactName = newCallInput.CNme; } if (!string.IsNullOrWhiteSpace(newCallInput.CNum)) { call.ContactName = newCallInput.CNum; } if (!string.IsNullOrWhiteSpace(newCallInput.Cid)) { call.IncidentNumber = newCallInput.Cid; } if (!string.IsNullOrWhiteSpace(newCallInput.Add)) { call.Address = newCallInput.Add; } if (!string.IsNullOrWhiteSpace(newCallInput.W3W)) { call.W3W = newCallInput.W3W; } //if (call.Address.Equals("Current Coordinates", StringComparison.InvariantCultureIgnoreCase)) // call.Address = ""; if (!string.IsNullOrWhiteSpace(newCallInput.Not)) { call.Notes = newCallInput.Not; } if (!string.IsNullOrWhiteSpace(newCallInput.Geo)) { call.GeoLocationData = newCallInput.Geo; } if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.Address)) { call.GeoLocationData = _geoLocationProvider.GetLatLonFromAddress(call.Address); } if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.W3W)) { var coords = _geoLocationProvider.GetCoordinatesFromW3W(call.W3W); if (coords != null) { call.GeoLocationData = $"{coords.Latitude},{coords.Longitude}"; } } call.LoggedOn = DateTime.UtcNow; if (!String.IsNullOrWhiteSpace(newCallInput.Typ) && newCallInput.Typ != "No Type") { var callTypes = _callsService.GetCallTypesForDepartment(DepartmentId); var type = callTypes.FirstOrDefault(x => x.Type == newCallInput.Typ); if (type != null) { call.Type = type.Type; } } var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); call.Dispatches = new Collection <CallDispatch>(); call.GroupDispatches = new List <CallDispatchGroup>(); call.RoleDispatches = new List <CallDispatchRole>(); if (string.IsNullOrWhiteSpace(newCallInput.Dis) || newCallInput.Dis == "0") { // Use case, existing clients and non-ionic2 app this will be null dispatch all users. Or we've specified everyone (0). foreach (var u in users) { var cd = new CallDispatch { UserId = u.UserId }; call.Dispatches.Add(cd); } } else { var dispatch = newCallInput.Dis.Split(char.Parse("|")); try { var usersToDispatch = dispatch.Where(x => x.StartsWith("P:")).Select(y => y.Replace("P:", "")); foreach (var user in usersToDispatch) { var cd = new CallDispatch { UserId = user }; call.Dispatches.Add(cd); } } catch (Exception ex) { Logging.LogException(ex); } try { var groupsToDispatch = dispatch.Where(x => x.StartsWith("G:")).Select(y => int.Parse(y.Replace("G:", ""))); foreach (var group in groupsToDispatch) { var cd = new CallDispatchGroup { DepartmentGroupId = group }; call.GroupDispatches.Add(cd); } } catch (Exception ex) { Logging.LogException(ex); } try { var rolesToDispatch = dispatch.Where(x => x.StartsWith("R:")).Select(y => int.Parse(y.Replace("R:", ""))); foreach (var role in rolesToDispatch) { var cd = new CallDispatchRole { RoleId = role }; call.RoleDispatches.Add(cd); } } catch (Exception ex) { Logging.LogException(ex); } } var savedCall = _callsService.SaveCall(call); OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler(); handler.Handle(new CallAddedEvent() { DepartmentId = DepartmentId, Call = savedCall }); var profiles = new List <string>(); if (call.Dispatches != null && call.Dispatches.Any()) { profiles.AddRange(call.Dispatches.Select(x => x.UserId).ToList()); } if (call.GroupDispatches != null && call.GroupDispatches.Any()) { foreach (var groupDispatch in call.GroupDispatches) { var group = _departmentGroupsService.GetGroupById(groupDispatch.DepartmentGroupId); if (group != null && group.Members != null) { profiles.AddRange(group.Members.Select(x => x.UserId)); } } } if (call.RoleDispatches != null && call.RoleDispatches.Any()) { foreach (var roleDispatch in call.RoleDispatches) { var members = _personnelRolesService.GetAllMembersOfRole(roleDispatch.RoleId); if (members != null) { profiles.AddRange(members.Select(x => x.UserId).ToList()); } } } var cqi = new CallQueueItem(); cqi.Call = savedCall; cqi.Profiles = _userProfileService.GetSelectedUserProfiles(profiles); _queueService.EnqueueCallBroadcast(cqi); return(Request.CreateResponse(HttpStatusCode.Created)); }
/// <summary> /// Adds a new call into Resgrid and Dispatches the call /// </summary> /// <param name="callInput">Call data to add into the system</param> /// <returns></returns> public async Task <AddCallInput> AddCall([FromBody] AddCallInput callInput) { try { var call = new Call { DepartmentId = DepartmentId, ReportingUserId = UserId, Priority = callInput.Priority, Name = callInput.Name, NatureOfCall = callInput.NatureOfCall, Number = callInput.Number, IsCritical = callInput.IsCritical, IncidentNumber = callInput.IncidentNumber, MapPage = callInput.MapPage, Notes = callInput.Notes, CompletedNotes = callInput.CompletedNotes, Address = callInput.Address, GeoLocationData = callInput.GeoLocationData, LoggedOn = callInput.LoggedOn, ClosedByUserId = callInput.ClosedByUserId, ClosedOn = callInput.ClosedOn, State = callInput.State, IsDeleted = callInput.IsDeleted, CallSource = callInput.CallSource, DispatchCount = callInput.DispatchCount, LastDispatchedOn = callInput.LastDispatchedOn, SourceIdentifier = callInput.SourceIdentifier, W3W = callInput.W3W, ContactName = callInput.ContactName, ContactNumber = callInput.ContactNumber, Public = callInput.Public, ExternalIdentifier = callInput.ExternalIdentifier, ReferenceNumber = callInput.ReferenceNumber }; if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.Address)) { call.GeoLocationData = _geoLocationProvider.GetLatLonFromAddress(call.Address); } if (string.IsNullOrWhiteSpace(call.GeoLocationData) && !string.IsNullOrWhiteSpace(call.W3W)) { var coords = await _geoLocationProvider.GetCoordinatesFromW3WAsync(call.W3W); if (coords != null) { call.GeoLocationData = $"{coords.Latitude},{coords.Longitude}"; } } call.LoggedOn = DateTime.UtcNow; if (!String.IsNullOrWhiteSpace(callInput.Type) && callInput.Type != "No Type") { var callTypes = await _callsService.GetCallTypesForDepartmentAsync(DepartmentId); var type = callTypes.FirstOrDefault(x => x.Type == callInput.Type); if (type != null) { call.Type = type.Type; } } call.Dispatches = new List <CallDispatch>(); call.GroupDispatches = new List <CallDispatchGroup>(); call.RoleDispatches = new List <CallDispatchRole>(); List <string> groupUserIds = new List <string>(); var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId); if (callInput.AllCall) { foreach (var u in users) { var cd = new CallDispatch { UserId = u.UserId }; call.Dispatches.Add(cd); } } else { if (callInput.GroupCodesToDispatch != null && callInput.GroupCodesToDispatch.Count > 0) { var allGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId); foreach (var groupCode in callInput.GroupCodesToDispatch) { var groupsToDispatch = allGroups.FirstOrDefault(x => x.DispatchEmail == groupCode); if (groupsToDispatch != null) { var cd = new CallDispatchGroup { DepartmentGroupId = groupsToDispatch.DepartmentGroupId }; call.GroupDispatches.Add(cd); if (groupsToDispatch.Members != null && groupsToDispatch.Members.Any()) { foreach (var departmentGroupMember in groupsToDispatch.Members) { if (!groupUserIds.Contains(departmentGroupMember.UserId)) { groupUserIds.Add(departmentGroupMember.UserId); } } } } } } } if (callInput.Attachments != null && callInput.Attachments.Any()) { call.Attachments = new List <CallAttachment>(); foreach (var attachment in callInput.Attachments) { var newAttachment = new CallAttachment(); newAttachment.Data = attachment.Data; newAttachment.Timestamp = DateTime.UtcNow; newAttachment.FileName = attachment.FileName; newAttachment.Size = attachment.Size; newAttachment.CallAttachmentType = attachment.CallAttachmentType; call.Attachments.Add(newAttachment); } } var savedCall = _callsService.SaveCall(call); OutboundEventProvider.CallAddedTopicHandler handler = new OutboundEventProvider.CallAddedTopicHandler(); handler.Handle(new CallAddedEvent() { DepartmentId = DepartmentId, Call = savedCall }); var cqi = new CallQueueItem(); cqi.Call = savedCall; if (cqi.Call.Dispatches != null && cqi.Call.Dispatches.Any()) { cqi.Profiles = await _userProfileService.GetSelectedUserProfilesAsync(cqi.Call.Dispatches.Select(x => x.UserId).ToList()); } else { if (groupUserIds.Any()) { cqi.Profiles = await _userProfileService.GetSelectedUserProfilesAsync(groupUserIds); } } _queueService.EnqueueCallBroadcast(cqi); callInput.CallId = savedCall.CallId; callInput.Number = savedCall.Number; } catch (Exception ex) { Logging.LogException(ex); throw ex; } return(callInput); }
public void SendCall(Call call, CallDispatch dispatch, string departmentNumber, int departmentId, UserProfile profile = null, string address = null) { if (profile == null) { profile = _userProfileService.GetProfileByUserId(dispatch.UserId); } // Send a Push Notification if (profile == null || profile.SendPush) { var spc = new StandardPushCall(); spc.CallId = call.CallId; spc.Title = string.Format("Call {0}", call.Name); spc.Priority = call.Priority; spc.ActiveCallCount = 1; if (call.CallPriority != null && !String.IsNullOrWhiteSpace(call.CallPriority.Color)) { spc.Color = call.CallPriority.Color; } else { spc.Color = "#000000"; } string subTitle = String.Empty; if (String.IsNullOrWhiteSpace(address) && !String.IsNullOrWhiteSpace(call.Address)) { subTitle = call.Address; } else if (!String.IsNullOrWhiteSpace(address)) { subTitle = address; } else if (!string.IsNullOrEmpty(call.GeoLocationData)) { try { string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { subTitle = _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])); } } catch { } } if (!string.IsNullOrEmpty(subTitle)) { spc.SubTitle = subTitle.Truncate(200); } else { if (!string.IsNullOrEmpty(call.NatureOfCall)) { spc.SubTitle = call.NatureOfCall.Truncate(200); } } if (!String.IsNullOrWhiteSpace(spc.SubTitle)) { spc.SubTitle = StringHelpers.StripHtmlTagsCharArray(spc.SubTitle); } spc.Title = StringHelpers.StripHtmlTagsCharArray(spc.Title); try { #pragma warning disable 4014 Task.Run(async() => { await _pushService.PushCall(spc, dispatch.UserId, profile, call.CallPriority); }).ConfigureAwait(false); #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } // Send an SMS Message if (profile == null || profile.SendSms) { try { #pragma warning disable 4014 Task.Run(() => { _smsService.SendCall(call, dispatch, departmentNumber, departmentId, profile); }).ConfigureAwait(false); #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } // Send an Email if (profile == null || profile.SendEmail) { try { #pragma warning disable 4014 Task.Run(() => { _emailService.SendCall(call, dispatch, profile); }).ConfigureAwait(false); #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } // Initiate a Telephone Call if (profile == null || profile.VoiceForCall) { try { #pragma warning disable 4014 if (!Config.SystemBehaviorConfig.DoNotBroadcast) { Task.Run(() => { _outboundVoiceProvider.CommunicateCall(departmentNumber, profile, call); }).ConfigureAwait(false); } #pragma warning restore 4014 } catch (Exception ex) { Logging.LogException(ex); } } }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.Body; c.Name = email.Subject; string[] data = email.Body.Split(char.Parse(",")); if (data.Length >= 1) { int tryPriority; if (int.TryParse(data[0], out tryPriority)) { c.Priority = tryPriority; } } else { c.Priority = (int)CallPriority.High; } if (data.Length >= 2) { if (data[1].Length > 3) { c.NatureOfCall = data[1]; } } else { c.NatureOfCall = email.Body; } if (data.Length >= 3) { if (data[2].Length > 3) { string address = String.Empty; if (!data[2].Contains("United Kingdom")) { address = data[2] + "United Kingdom"; } c.Address = address; } } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (email.DispatchAudio != null) { c.Attachments = new Collection <CallAttachment>(); CallAttachment ca = new CallAttachment(); ca.FileName = email.DispatchAudioFileName; ca.Data = email.DispatchAudio; ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio; c.Attachments.Add(ca); } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body) && String.IsNullOrEmpty(email.TextBody)) { return(null); } string emailBody = email.Body; if (String.IsNullOrWhiteSpace(email.Body)) { emailBody = email.TextBody; } if (emailBody.Contains("CLOSE: Inc#")) { return(null); } Call c = new Call(); c.Notes = emailBody; string[] data = emailBody.Split(char.Parse(";")); if (data == null || data.Length <= 2) { return(null); } var incidentNumber = data.FirstOrDefault(x => x.Contains("Inc#")); if (incidentNumber != null) { c.IncidentNumber = incidentNumber.Replace("Inc# ", "").Trim(); } c.Type = data[0].Trim(); try { var mapSection = data.FirstOrDefault(x => x.Contains("?q=")); if (mapSection != null) { int start = mapSection.IndexOf("?q="); int end = mapSection.IndexOf(">Map"); c.GeoLocationData = mapSection.Substring(start + 3, (end - start - 4)); } } catch { } c.NatureOfCall = data[0].Trim() + " " + data[2].Trim() + " " + data[3].Trim(); c.NatureOfCall = c.NatureOfCall.Trim(); c.Address = data[1].Trim(); c.Name = data[0].Trim(); c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; var mapPage = data.FirstOrDefault(x => x.Contains("Map:")); if (mapPage != null) { c.MapPage = mapPage.Replace("Map: ", "").Trim(); } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public void SendCall(Call call, CallDispatch dispatch, UserProfile profile = null) { if (Config.SystemBehaviorConfig.DoNotBroadcast) { return; } if (profile == null) { profile = _userProfileService.GetProfileByUserId(dispatch.UserId); } string emailAddress = String.Empty; if (dispatch.User != null && dispatch.User != null) { emailAddress = dispatch.User.Email; } else { //Logging.LogError(string.Format("Send Call Email (Missing User Membership): {0} User: {1}", call.CallId, dispatch.UserId)); var user = _usersService.GetUserById(dispatch.UserId, false); if (user != null && user != null) { emailAddress = user.Email; } } string subject = string.Empty; string priority = string.Empty; string address = string.Empty; if (call.IsCritical) { subject = string.Format("Resgrid CRITICAL Call: P{0} {1}", call.Priority, call.Name); priority = string.Format("{0} CRITICAL", ((CallPriority)call.Priority).ToString()); } else { subject = string.Format("Resgrid Call: P{0} {1}", call.Priority, call.Name); priority = string.Format("{0}", ((CallPriority)call.Priority).ToString()); } string coordinates = "No Coordinates Supplied"; if (!string.IsNullOrEmpty(call.GeoLocationData)) { coordinates = call.GeoLocationData; string[] points = call.GeoLocationData.Split(char.Parse(",")); if (points != null && points.Length == 2) { try { address = _geoLocationProvider.GetAproxAddressFromLatLong(double.Parse(points[0]), double.Parse(points[1])); } catch (Exception) { } } } if (!string.IsNullOrEmpty(call.Address) && string.IsNullOrWhiteSpace(address)) { address = call.Address; } else { address = "No Address Supplied"; } string dispatchedOn = String.Empty; if (call.Department != null) { dispatchedOn = call.LoggedOn.FormatForDepartment(call.Department); } else { dispatchedOn = call.LoggedOn.ToString("G") + " UTC"; } if (profile != null && profile.SendEmail && !String.IsNullOrWhiteSpace(emailAddress)) { _emailProvider.SendCallMail(emailAddress, subject, call.Name, priority, call.NatureOfCall, call.MapPage, address, dispatchedOn, call.CallId, dispatch.UserId, coordinates, call.ShortenedAudioUrl); } }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } string[] data = email.Body.Split(char.Parse("|")); Call c = new Call(); c.Notes = email.Subject + " " + email.Body; if (data != null && data.Length >= 4) { c.NatureOfCall = data[3]; } else { c.NatureOfCall = email.Subject + " " + email.Body; } if (data != null && data.Length >= 1) { c.Name = data[0]; } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; if (data != null && data.Length > 3) { var geoData = data[2].Replace("[LONGLAT:", "").Replace("] - 1:", ""); if (!String.IsNullOrWhiteSpace(geoData)) { var geoDataArray = geoData.Split(char.Parse(",")); if (geoDataArray != null && geoDataArray.Length == 2) { c.GeoLocationData = $"{geoDataArray[1]}.{geoDataArray[0]}"; } } } foreach (var u in users) { CallDispatch cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } return(c); }
public Call GenerateCall(CallEmail email, string managingUser, List <IdentityUser> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.Body)) { return(null); } if (!email.Subject.Contains("Parkland County Incident") && !email.Subject.Contains("Incident Message")) { return(null); } bool is2ndPage = false; string priorityChar = null; DateTime callTimeUtc = DateTime.UtcNow; var c = new Call(); c.Notes = email.Body; try { var data = new List <string>(); string[] rawData = email.Body.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); if (rawData != null && rawData.Any()) { foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s)) { data.Add(s); } } if (data.Count > 0) { c.Name = data[1].Trim().Replace("Type: ", ""); var priorityString = c.Name.Substring(0, c.Name.IndexOf(char.Parse("-"))).Trim(); priorityChar = Regex.Replace(priorityString, @"\d", "").Trim(); TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(department.TimeZone); callTimeUtc = new DateTimeOffset(DateTime.Parse(data[0].Replace("Date:", "").Trim()), timeZone.BaseUtcOffset).UtcDateTime; is2ndPage = c.Notes.Contains("WCT2ndPage"); try { var location = data.FirstOrDefault(x => x.StartsWith("Location:")); if (!String.IsNullOrWhiteSpace(location)) { c.Address = location.Replace("//", "").Replace("Business Name:", ""); } var coordinates = data.FirstOrDefault(x => x.Contains("(") && x.Contains(")")); if (!String.IsNullOrWhiteSpace(coordinates)) { coordinates = coordinates.Replace("Common Place:", ""); coordinates = coordinates.Trim(); c.GeoLocationData = coordinates.Replace("(", "").Replace(")", ""); } } catch { } } } else { c.Name = "Call Import Type: Unknown"; } } catch { c.Name = "Call Import Type: Unknown"; } c.NatureOfCall = email.Body; c.LoggedOn = callTimeUtc; c.Priority = PriorityMapping(priorityChar, is2ndPage, priority); c.ReportingUserId = managingUser; c.Dispatches = new Collection <CallDispatch>(); c.UnitDispatches = new Collection <CallDispatchUnit>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageId; foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } if (units != null && units.Any()) { foreach (var unit in units) { var ud = new CallDispatchUnit(); ud.UnitId = unit.UnitId; ud.LastDispatchedOn = DateTime.UtcNow; c.UnitDispatches.Add(ud); } } // Search for an active call if (activeCalls != null && activeCalls.Any()) { var activeCall = activeCalls.FirstOrDefault(x => x.Name == c.Name && x.LoggedOn == c.LoggedOn); if (activeCall != null) { activeCall.Priority = c.Priority; activeCall.Notes = c.Notes; activeCall.LastDispatchedOn = DateTime.UtcNow; activeCall.DispatchCount++; return(activeCall); } } return(c); }
public Call GenerateCall(InboundMessage email, string managingUser, List <string> users, Department department, List <Call> activeCalls, List <Unit> units, int priority) { if (email == null) { return(null); } if (String.IsNullOrEmpty(email.HtmlBody)) { return(null); } if (String.IsNullOrEmpty(email.Subject)) { return(null); } if (!email.Subject.Contains("Perform Page")) { return(null); } Call c = new Call(); c.Notes = email.Subject + " " + email.HtmlBody; c.NatureOfCall = email.HtmlBody; List <string> data = new List <string>(); string[] rawData = email.HtmlBody.Split(new string[] { "\r\n", "\r\n\r\n" }, StringSplitOptions.None); foreach (string s in rawData) { if (!string.IsNullOrWhiteSpace(s)) { data.Add(s); } } if (data.Count >= 1) { c.Name = data[0]; } else { c.Name = email.Subject; } if (data.Count == 5) { string firstLine = string.Empty; if (data[1].ToUpper().Contains("AND")) { string[] firstLineParts = data[1].Split(new string[] { "AND" }, StringSplitOptions.None); if (!string.IsNullOrWhiteSpace(firstLineParts[0])) { firstLine = firstLineParts[0]; } } else if (data[1].ToUpper().Contains("/")) { string[] firstLineParts = data[1].Split(new string[] { "/" }, StringSplitOptions.None); if (!string.IsNullOrWhiteSpace(firstLineParts[0])) { firstLine = firstLineParts[0]; } } else { firstLine = data[1]; } c.Address = string.Format("{0} {1}", firstLine, data[2]); } else if (data.Count == 6) { c.Address = string.Format("{0} {1}", data[2], data[3]); } c.LoggedOn = DateTime.UtcNow; c.Priority = priority; c.ReportingUserId = managingUser; c.Dispatches = new List <CallDispatch>(); c.CallSource = (int)CallSources.EmailImport; c.SourceIdentifier = email.MessageID; //if (email.DispatchAudio != null) //{ // c.Attachments = new Collection<CallAttachment>(); // CallAttachment ca = new CallAttachment(); // ca.FileName = email.DispatchAudioFileName; // ca.Data = email.DispatchAudio; // ca.CallAttachmentType = (int)CallAttachmentTypes.DispatchAudio; // c.Attachments.Add(ca); //} foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u; c.Dispatches.Add(cd); } return(c); }