public bool CanUserViewCall(string userId, int callId) { var department = _departmentsService.GetDepartmentByUserId(userId); var call = _callsService.GetCallById(callId, false); if (department == null || call == null) { return(false); } if (call.DepartmentId != department.DepartmentId) { return(false); } return(true); }
public void PopulateQueue() { if (!_isLocked) { _isLocked = true; Task t1 = new Task(() => { try { if (Config.SystemBehaviorConfig.IsAzure) { _queue.Enqueue(new CallQueueItem()); } else { _callsService = Bootstrapper.GetKernel().Resolve <ICallsService>(); _queueService = Bootstrapper.GetKernel().Resolve <IQueueService>(); _userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); var items = _queueService.Dequeue(QueueTypes.CallBroadcast); foreach (var i in items) { var cqi = new CallQueueItem(); cqi.QueueItem = i; cqi.Call = _callsService.GetCallById(int.Parse(i.SourceId)); cqi.Profiles = _userProfileService.GetSelectedUserProfiles(cqi.Call.Dispatches.Select(x => x.UserId).ToList()); _queue.Enqueue(cqi); } } } catch (Exception ex) { Logging.LogException(ex); } finally { _isLocked = false; _cleared = false; _callsService = null; _queueService = null; _userProfileService = null; } }); t1.Start(); } }
public IActionResult LiveRouting(int callId) { StationRoutingView model = new StationRoutingView(); var call = _callsService.GetCallById(callId); if (call.DepartmentId != DepartmentId) { Unauthorized(); } string endLat = ""; string endLon = ""; var callCocationParts = call.GeoLocationData.Split(char.Parse(",")); endLat = callCocationParts[0]; endLon = callCocationParts[1]; model.EndLat = endLat; model.EndLon = endLon; return(View(model)); }
public CallResult GetCall(int callId) { var c = _callsService.GetCallById(callId); var department = _departmentsService.GetDepartmentById(DepartmentId, false); //var types = _callsService.GetCallTypesForDepartment(DepartmentId); var call = new CallResult(); call.Cid = c.CallId; call.Pri = c.Priority; call.Ctl = c.IsCritical; call.Nme = c.Name; call.Noc = c.NatureOfCall; call.Map = c.MapPage; call.Not = c.Notes; call.Eid = c.ExternalIdentifier; call.Rnm = c.ContactName; call.Rci = c.ContactNumber; call.Rid = c.ReferenceNumber; call.Typ = c.Type; if (c.CallNotes != null) { call.Nts = c.CallNotes.Count(); } else { call.Nts = 0; } if (c.Attachments != null) { call.Aud = c.Attachments.Count(x => x.CallAttachmentType == (int)CallAttachmentTypes.DispatchAudio); call.Img = c.Attachments.Count(x => x.CallAttachmentType == (int)CallAttachmentTypes.Image); call.Fls = c.Attachments.Count(x => x.CallAttachmentType == (int)CallAttachmentTypes.File); if (call.Aud > 0) { var audio = c.Attachments.FirstOrDefault(x => x.CallAttachmentType == (int)CallAttachmentTypes.DispatchAudio); if (audio != null) { call.Aid = SymmetricEncryption.Encrypt(audio.CallAttachmentId.ToString(), Config.SystemBehaviorConfig.ExternalAudioUrlParamPasshprase); } } } else { call.Aud = 0; call.Img = 0; call.Fls = 0; } if (String.IsNullOrWhiteSpace(c.Address) && !String.IsNullOrWhiteSpace(c.GeoLocationData)) { var geo = c.GeoLocationData.Split(char.Parse(",")); if (geo.Length == 2) { call.Add = _geoLocationProvider.GetAddressFromLatLong(double.Parse(geo[0]), double.Parse(geo[1])); } } else { call.Add = c.Address; } call.Geo = c.GeoLocationData; call.Lon = c.LoggedOn.TimeConverter(department); call.Utc = c.LoggedOn; call.Ste = c.State; call.Num = c.Number; if (!String.IsNullOrWhiteSpace(c.W3W)) { call.w3w = c.W3W; } return(call); }
public HttpResponseMessage IncomingMessage([FromUri] TwilioMessage request) { if (request == null || string.IsNullOrWhiteSpace(request.To) || string.IsNullOrWhiteSpace(request.From) || string.IsNullOrWhiteSpace(request.Body)) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } var response = new TwilioResponse(); 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 = _departmentSettingsService.GetDepartmentIdByTextToCallNumber(textMessage.To); if (departmentId.HasValue) { var department = _departmentsService.GetDepartmentById(departmentId.Value); var textToCallEnabled = _departmentSettingsService.GetDepartmentIsTextCallImportEnabled(departmentId.Value); var textCommandEnabled = _departmentSettingsService.GetDepartmentIsTextCommandEnabled(departmentId.Value); var dispatchNumbers = _departmentSettingsService.GetTextToCallSourceNumbersForDepartment(departmentId.Value); var authroized = _limitsService.CanDepartmentProvisionNumber(departmentId.Value); var customStates = _customStateService.GetAllActiveCustomStatesForDepartment(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 = _departmentsService.GetAllUsersForDepartment(departmentId.Value, true); foreach (var u in users) { var cd = new CallDispatch(); cd.UserId = u.UserId; c.Dispatches.Add(cd); } var savedCall = _callsService.SaveCall(c); var cqi = new CallQueueItem(); cqi.Call = savedCall; cqi.Profiles = _userProfileService.GetSelectedUserProfiles(users.Select(x => x.UserId).ToList()); cqi.DepartmentTextNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(cqi.Call.DepartmentId); _queueService.EnqueueCallBroadcast(cqi); messageEvent.Processed = true; } if (!isDispatchSource && textCommandEnabled) { var profile = _userProfileService.FindProfileByMobileNumber(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; _actionLogsService.SetUserAction(profile.UserId, department.DepartmentId, (int)payload.GetActionType()); response.Message(string.Format("Resgrid recieved 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; _userStateService.CreateUserState(profile.UserId, department.DepartmentId, (int)payload.GetStaffingType()); response.Message(string.Format("Resgrid recieved 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; _userProfileService.DisableTextMessagesForUser(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; _actionLogsService.SetUserAction(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 recieved your text command. Status changed to: {0}", detail.ButtonText)); } else { response.Message("Resgrid recieved your text command and updated your status"); } break; case TextCommandTypes.CustomStaffing: messageEvent.Processed = true; _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 recieved your text command. Staffing changed to: {0}", detail.ButtonText)); } else { response.Message("Resgrid recieved your text command and updated your staffing"); } break; case TextCommandTypes.MyStatus: messageEvent.Processed = true; var userStatus = _actionLogsService.GetLastActionLogForUser(profile.UserId); var userStaffing = _userStateService.GetLastUserStateByUserId(profile.UserId); var customStatusLevel = _customStateService.GetCustomPersonnelStatus(department.DepartmentId, userStatus); var customStaffingLevel = _customStateService.GetCustomPersonnelStaffing(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 = _callsService.GetActiveCallsByDepartment(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 = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(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 = _customStateService.GetCustomUnitState(unit); unitStatusesText.Append($"{unit.Unit.Name} is {unitState.ButtonText}" + Environment.NewLine); } response.Message(unitStatusesText.ToString()); break; case TextCommandTypes.CallDetail: messageEvent.Processed = true; var call = _callsService.GetCallById(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 = _userProfileService.FindProfileByMobileNumber(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; _userProfileService.DisableTextMessagesForUser(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 { _numbersService.SaveInboundMessageEvent(messageEvent); } //return Request.CreateResponse(HttpStatusCode.OK); //var response = new TwilioResponse(); return(Request.CreateResponse(HttpStatusCode.OK, response.Element, new XmlMediaTypeFormatter())); }
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)); }
public IActionResult NewLog(NewLogView model, IFormCollection form, ICollection <IFormFile> files) { PopulateLogViewModel(model); if (model.LogType == LogTypes.Work && String.IsNullOrWhiteSpace(form["nonUnitPersonnel"])) { model.ErrorMessage = "You need to specify at least 1 person to be part of the work log."; return(View(model)); } try { try { if (files != null && files.Any()) { foreach (var file in files) { if (file != null && !String.IsNullOrWhiteSpace(file.FileName)) { string extension = Path.GetExtension(file.FileName); if (!String.IsNullOrWhiteSpace(extension)) { extension = extension.ToLower(); } if (extension != ".jpg" && extension != ".jpeg" && extension != ".png" && extension != ".gif" && extension != ".pdf" && extension != ".doc" && extension != ".docx" && extension != ".ppt" && extension != ".pptx" && extension != ".pps" && extension != ".ppsx" && extension != ".odt" && extension != ".xls" && extension != ".xlsx" && extension != ".txt" && extension != ".rtf") { model.ErrorMessage = string.Format("File type ({0}) is not importable.", extension); } if (file.Length > 10000000) { model.ErrorMessage = "Document is too large, must be smaller then 10MB."; } } } } } catch { } if (!String.IsNullOrWhiteSpace(model.ErrorMessage)) { return(View(model)); } // Get all unit blocks in the report List <int> unitsInReport = (from object key in form.Keys where key.ToString().StartsWith("unit_personnel_") select int.Parse(key.ToString().Replace("unit_personnel_", ""))).ToList(); model.Log.LoggedByUserId = UserId; model.Log.DepartmentId = model.Department.DepartmentId; model.Log.Narrative = System.Net.WebUtility.HtmlDecode(model.Log.Narrative); model.Log.Cause = System.Net.WebUtility.HtmlDecode(model.Log.Cause); model.Log.InitialReport = System.Net.WebUtility.HtmlDecode(model.Log.InitialReport); model.Log.LogType = (int)model.LogType; if (model.Log.StationGroupId == 0) { model.Log.StationGroupId = null; } model.Log.Units = new Collection <LogUnit>(); model.Log.Users = new Collection <LogUser>(); if (String.IsNullOrWhiteSpace(model.Log.InvestigatedByUserId)) { model.Log.InvestigatedByUserId = null; } if (model.Log.StationGroupId.HasValue && model.Log.StationGroupId.Value == 0) { model.Log.StationGroupId = null; } if (model.LogType == LogTypes.Run) { if (model.CallId == 0) { model.Call.DepartmentId = DepartmentId; model.Call.ReportingUserId = UserId; model.Call.Priority = (int)model.CallPriority; if (model.Call.Type == "No Type") { model.Call.Type = null; } model.Call = _callsService.SaveCall(model.Call); model.Log.CallId = model.Call.CallId; model.Log.StartedOn = model.Call.LoggedOn; } else { var call = _callsService.GetCallById(model.CallId); call.Priority = (int)model.CallPriority; call.NatureOfCall = model.Call.NatureOfCall; call.Address = model.Call.Address; call.LoggedOn = model.Call.LoggedOn; call.Name = model.Call.Name; model.Call = _callsService.SaveCall(call); model.Log.CallId = model.Call.CallId; } } if (model.LogType == LogTypes.Work) { var startedOn = form["Log.StartedOn"]; var endedOn = form["Log.EndedOn"]; if (!String.IsNullOrWhiteSpace(startedOn)) { model.Log.StartedOn = DateTime.Parse(startedOn); } if (!String.IsNullOrWhiteSpace(endedOn)) { model.Log.EndedOn = DateTime.Parse(endedOn); } } if (model.LogType == LogTypes.Meeting) { var startedOn = form["Log.StartedOn"]; var endedOn = form["Log.EndedOn"]; if (!String.IsNullOrWhiteSpace(startedOn)) { model.Log.StartedOn = DateTime.Parse(startedOn); } if (!String.IsNullOrWhiteSpace(endedOn)) { model.Log.EndedOn = DateTime.Parse(endedOn); } } if (model.LogType == LogTypes.Coroner) { var startedOn = form["coronerDate"]; var caseNumber = form["caseNumber"]; var coronerInstructors = form["coronerInstructors"]; var coronerDestination = form["coronerDestination"]; var coronerOthers = form["coronerOthers"]; if (!String.IsNullOrWhiteSpace(startedOn)) { model.Log.StartedOn = DateTime.Parse(startedOn); } if (!String.IsNullOrWhiteSpace(caseNumber)) { model.Log.ExternalId = caseNumber; } if (!String.IsNullOrWhiteSpace(coronerInstructors)) { model.Log.Instructors = coronerInstructors; } if (!String.IsNullOrWhiteSpace(coronerDestination)) { model.Log.Location = coronerDestination; } if (!String.IsNullOrWhiteSpace(coronerOthers)) { model.Log.OtherPersonnel = coronerOthers; } } foreach (var i in unitsInReport) { var unit = new LogUnit(); unit.UnitId = i; if (!string.IsNullOrWhiteSpace(form["unit_dispatchtime_" + i])) { unit.Dispatched = DateTime.Parse(form["unit_dispatchtime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_enroutetime_" + i])) { unit.Enroute = DateTime.Parse(form["unit_enroutetime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_onscenetime_" + i])) { unit.OnScene = DateTime.Parse(form["unit_onscenetime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_releasedtime_" + i])) { unit.Released = DateTime.Parse(form["unit_releasedtime_" + i]); } if (!string.IsNullOrWhiteSpace(form["unit_inquarterstime_" + i])) { unit.InQuarters = DateTime.Parse(form["unit_inquarterstime_" + i]); } model.Log.Units.Add(unit); if (!string.IsNullOrWhiteSpace(form["unit_personnel_" + i])) { var personnelIds = form["unit_personnel_" + i].ToString().Split(char.Parse(",")); foreach (var personnelId in personnelIds) { var logUser = new LogUser(); logUser.UserId = personnelId; logUser.UnitId = i; model.Log.Users.Add(logUser); } } } if (!string.IsNullOrWhiteSpace(form["nonUnitPersonnel"])) { var personnelIds = form["nonUnitPersonnel"].ToString().Split(char.Parse(",")); foreach (var personnelId in personnelIds) { var logUser = new LogUser(); logUser.UserId = personnelId; model.Log.Users.Add(logUser); } } var savedLog = _workLogsService.SaveLog(model.Log); try { if (files != null) { foreach (var file in files) { if (file != null && file.Length > 0) { LogAttachment attachment = new LogAttachment(); attachment.LogId = savedLog.LogId; attachment.Type = file.ContentType; attachment.FileName = file.FileName; byte[] uploadedFile = new byte[file.OpenReadStream().Length]; file.OpenReadStream().Read(uploadedFile, 0, uploadedFile.Length); attachment.Data = uploadedFile; attachment.UserId = UserId; attachment.Timestamp = DateTime.UtcNow; _workLogsService.SaveLogAttachment(attachment); } } } } catch { } _eventAggregator.SendMessage <LogAddedEvent>(new LogAddedEvent() { DepartmentId = DepartmentId, Log = model.Log }); } catch (Exception ex) { Logging.LogException(ex); model.ErrorMessage = "We encountered an error trying to save your log. Please check your form to ensure it's properly filled out and try again."; return(View(model)); } return(RedirectToAction("Index")); }
public double GetPersonnelEtaInSeconds(ActionLog log) { if (log == null || String.IsNullOrWhiteSpace(log.GeoLocationData)) { return(-1); } if (log.DestinationId.HasValue) { RouteInformation route = null; if (log.DestinationType.GetValueOrDefault() == 1 || log.ActionTypeId == (int)ActionTypes.RespondingToStation) // Department Group { var group = _departmentGroupsService.GetGroupById(log.DestinationId.Value, false); if (group != null && group.AddressId.HasValue) { Address address = null; if (group.Address != null) { address = group.Address; } else { address = _addressService.GetAddressById(group.AddressId.Value); } route = _geoLocationProvider.GetRoute(log.GeoLocationData, address.FormatAddress()); } else if (group != null && !String.IsNullOrWhiteSpace(group.Latitude) && !String.IsNullOrWhiteSpace(group.Longitude)) { route = _geoLocationProvider.GetRoute(log.GeoLocationData, string.Format("{0},{1}", group.Latitude, group.Longitude)); } } else if (log.DestinationType.GetValueOrDefault() == 2 || log.ActionTypeId == (int)ActionTypes.RespondingToScene) // Call { var call = _callsService.GetCallById(log.DestinationId.Value, false); if (!String.IsNullOrWhiteSpace(call.GeoLocationData)) { route = _geoLocationProvider.GetRoute(log.GeoLocationData, call.GeoLocationData); } else { route = _geoLocationProvider.GetRoute(log.GeoLocationData, call.GeoLocationData); } } if (route != null) { var timeDiff = route.ProcessedOn - log.Timestamp; var time = route.Seconds - timeDiff.Seconds; if (time < 0) { return(0); } return(time); } } return(-1); }