public IActionResult Profile() { var model = new ProfileView(); model.ApiUrl = _appOptionsAccessor.Value.ResgridApiUrl; model.Department = _departmentsService.GetDepartmentByUserId(UserId); model.ImageUrl = $"{model.ApiUrl}/api/v3/Avatars/Get?id={model.Department.DepartmentId}&type=1"; var profile = _departmentProfileService.GetOrInitializeDepartmentProfile(DepartmentId); if (profile != null) { model.Profile = profile; if (model.Profile.Address != null) { model.Address1 = model.Profile.Address.Address1; model.City = model.Profile.Address.City; model.Country = model.Profile.Address.Country; model.PostalCode = model.Profile.Address.PostalCode; model.State = model.Profile.Address.State; } } else { model.Profile = new DepartmentProfile(); } return(View(model)); }
public IActionResult Inbox() { MessagesInboxModel model = new MessagesInboxModel(); model.Department = _departmentsService.GetDepartmentByUserId(UserId); model.User = _usersService.GetUserById(UserId); model.Messages = _messageService.GetInboxMessagesByUserId(UserId); model.UnreadMessages = _messageService.GetUnreadMessagesCountByUserId(UserId); return(View(model)); }
public List <ScheduledTask> GetUpcomingScheduledTasksByUserId(string userId) { var upcomingTasks = new List <ScheduledTask>(); var tasks = (from st in GetAllScheduledTasks() where st.Active == true && st.UserId == userId select st).ToList(); var department = _departmentsService.GetDepartmentByUserId(userId); var runDate = TimeConverterHelper.TimeConverter(DateTime.UtcNow, department); foreach (var scheduledTask in tasks) { var log = _scheduledTaskLogRepository.GetLogForTaskAndDate(scheduledTask.ScheduledTaskId, DateTime.UtcNow); var runTime = scheduledTask.WhenShouldJobBeRun(runDate); if (runTime.HasValue) { if (scheduledTask.AddedOn.HasValue) { if (scheduledTask.AddedOn.Value < DateTime.UtcNow) { if (runTime.Value > runDate && log == null) { upcomingTasks.Add(scheduledTask); } else if (runTime.Value < runDate && log == null) { upcomingTasks.Add(scheduledTask); } } } else { if (runTime.Value > runDate && log == null) { upcomingTasks.Add(scheduledTask); } else if (runTime.Value < runDate && log == null) { upcomingTasks.Add(scheduledTask); } } } } return(upcomingTasks); }
public void PopulateQueue() { if (!_isLocked) { _isLocked = true; _departmentsService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>(); _scheduledTasksService = Bootstrapper.GetKernel().Resolve <IScheduledTasksService>(); _usersService = Bootstrapper.GetKernel().Resolve <IUsersService>(); Task t1 = new Task(() => { try { var allItems = _scheduledTasksService.GetUpcomingScheduledTaks(); // Filter only the past items and ones that are 5 minutes 30 seconds in the future var items = from st in allItems let department = _departmentsService.GetDepartmentByUserId(st.UserId) let email = _usersService.GetMembershipByUserId(st.UserId).Email let runTime = st.WhenShouldJobBeRun(TimeConverterHelper.TimeConverter(DateTime.UtcNow, department)) where st.TaskType == (int)TaskTypes.ReportDelivery && runTime.HasValue && runTime.Value >= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department) && runTime.Value <= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department).AddMinutes(5).AddSeconds(30) select new { ScheduledTask = st, Department = department, Email = email }; foreach (var i in items) { var qi = new ReportDeliveryQueueItem(); qi.ScheduledTask = i.ScheduledTask; qi.Department = i.Department; qi.Email = i.Email; _queue.Enqueue(qi); } } catch (Exception ex) { Logging.LogException(ex); } finally { _isLocked = false; _cleared = false; _departmentsService = null; _scheduledTasksService = null; _usersService = null; } }); t1.Start(); } }
private void PopulateLogViewModel(NewLogView model) { model.Department = _departmentsService.GetDepartmentByUserId(UserId); model.User = _usersService.GetUserById(UserId); model.Types = model.LogType.ToSelectList(); model.CallPriorities = model.CallPriority.ToSelectList(); model.Users.Add(String.Empty, "Not Applicable"); model.SetUsers(_departmentsService.GetAllUsersForDepartment(DepartmentId)); var groups = new List <DepartmentGroup>(); groups.Add(new DepartmentGroup { Name = "Not Applicable" }); groups.AddRange(_departmentGroupsService.GetAllStationGroupsForDepartment(DepartmentId)); model.Stations = groups; List <CallType> types = new List <CallType>(); types.Add(new CallType { CallTypeId = 0, Type = "No Type" }); types.AddRange(_callsService.GetCallTypesForDepartment(DepartmentId)); model.CallTypes = new SelectList(types, "Type", "Type"); }
public DeleteUserResults DeleteUser(int departmentId, string authroizingUserId, string userIdToDelete) { if (!_authorizationService.CanUserDeleteUser(departmentId, authroizingUserId, userIdToDelete)) { return(DeleteUserResults.UnAuthroized); } var department = _departmentsService.GetDepartmentByUserId(userIdToDelete); if (department.ManagingUserId == userIdToDelete) { return(DeleteUserResults.UserIsManagingDepartmentAdmin); } var member = _departmentsService.GetDepartmentMember(userIdToDelete, departmentId); member.IsDeleted = true; _departmentsService.SaveDepartmentMember(member); //_certificationService.DeleteAllCertificationsForUser(userIdToDelete); //_distributionListsService.RemoveUserFromAllLists(userIdToDelete); //_personnelRolesService.RemoveUserFromAllRoles(userIdToDelete); //_userStateService.DeleteStatesForUser(userIdToDelete); //_workLogsService.ClearInvestigationByLogsForUser(userIdToDelete); //_workLogsService.DeleteLogsForUser(userIdToDelete, department.ManagingUserId); //_messageService.DeleteMessagesForUser(userIdToDelete); ////_userProfileService.DeletProfileForUser(userIdToDelete); //_pushUriService.DeletePushUrisForUser(userIdToDelete); //_actionLogsService.DeleteActionLogsForUser(userIdToDelete); //_callsService.DeleteDispatchesForUserAndRemapCalls(department.ManagingUserId, userIdToDelete); //_departmentGroupsService.DeleteUserFromGroups(userIdToDelete); //_usersService.DeleteUser(userIdToDelete); return(DeleteUserResults.NoFailure); }
public void PopulateQueue() { Logging.LogTrace("StaffingJob: Entering PopulateQueue"); if (!_isLocked) { _isLocked = true; _departmentsService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>(); _scheduledTasksService = Bootstrapper.GetKernel().Resolve <IScheduledTasksService>(); var t1 = new Task(() => { try { var allItems = _scheduledTasksService.GetUpcomingScheduledTaks(); Logging.LogTrace(string.Format("StaffingJob: Analyzing {0} schedule tasks", allItems.Count)); // Filter only the past items and ones that are 5 minutes 30 seconds in the future var items = from st in allItems let department = _departmentsService.GetDepartmentByUserId(st.UserId) let runTime = st.WhenShouldJobBeRun(TimeConverterHelper.TimeConverter(DateTime.UtcNow, department)) where (st.TaskType == (int)TaskTypes.DepartmentStaffingReset || st.TaskType == (int)TaskTypes.UserStaffingLevel) && runTime.HasValue && runTime.Value >= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department) && runTime.Value <= TimeConverterHelper.TimeConverter(DateTime.UtcNow, department).AddMinutes(5).AddSeconds(30) select new { ScheduledTask = st, Department = department }; foreach (var i in items) { var qi = new StaffingScheduleQueueItem(); qi.ScheduledTask = i.ScheduledTask; qi.Department = i.Department; _queue.Enqueue(qi); } } catch (Exception ex) { Logging.LogException(ex); } finally { _isLocked = false; _cleared = false; _departmentsService = null; _scheduledTasksService = null; } }, TaskCreationOptions.LongRunning); t1.Start(); } }
public async Task <HttpResponseMessage> Receive() { var queryValues = Request.RequestUri.ParseQueryString(); var textMessage = new TextMessage(); //textMessage.Type = queryValues["type"]; textMessage.To = queryValues["To"].Replace("+", ""); textMessage.Msisdn = queryValues["From"].Replace("+", ""); //queryValues["SmsSid"]; textMessage.NetworkCode = queryValues["AccountSid"]; textMessage.MessageId = queryValues["MessageSid"]; textMessage.Timestamp = DateTime.UtcNow.ToLongDateString(); //textMessage.Concat = queryValues["concat"]; //textMessage.ConcatRef = queryValues["concat-ref"]; //textMessage.ConcatTotal = queryValues["concat-total"]; //textMessage.ConcatPart = queryValues["concat-part"]; textMessage.Data = queryValues["Body"]; //textMessage.Udh = queryValues["udh"]; textMessage.Text = queryValues["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 = ""; string response = ""; try { UserProfile profile = null; var departmentId = _departmentSettingsService.GetDepartmentIdByTextToCallNumber(textMessage.To); if (!departmentId.HasValue) { profile = _userProfileService.FindProfileByMobileNumber(textMessage.Msisdn); if (profile != null) { var department = _departmentsService.GetDepartmentByUserId(profile.UserId); if (department != null) { departmentId = department.DepartmentId; } } } 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) { 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: //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", "Resgrid (https://resgrid.com) Automated Text System. Unknown command, text help for supported commands.", department.DepartmentId, textMessage.To, profile); response = LaMLResponse.Message.Respond("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 = LaMLResponse.Message.Respond(help.ToString()); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", help.ToString(), department.DepartmentId, textMessage.To, profile); break; case TextCommandTypes.Action: messageEvent.Processed = true; var activeResponseCalls = _callsService.GetActiveCallsByDepartment(department.DepartmentId).Where(x => DateTime.Now == x.LoggedOn.Within(TimeSpan.FromMinutes(15))); if (activeResponseCalls != null && activeResponseCalls.Any()) { _actionLogsService.SetUserAction(profile.UserId, department.DepartmentId, (int)payload.GetActionType(), null, activeResponseCalls.First().CallId); response = LaMLResponse.Message.Respond(string.Format("Resgrid received your text command. Status changed to: {0} to call {1}", payload.GetActionType(), activeResponseCalls.First().Name)); } else { _actionLogsService.SetUserAction(profile.UserId, department.DepartmentId, (int)payload.GetActionType()); response = LaMLResponse.Message.Respond(string.Format("Resgrid received your text command. Status changed to: {0}", payload.GetActionType())); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", string.Format("Resgrid received 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 = LaMLResponse.Message.Respond(string.Format("Resgrid received your text command. Staffing level changed to: {0}", payload.GetStaffingType())); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", string.Format("Resgrid received 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 = LaMLResponse.Message.Respond("Text messages are now turned off for this user, to enable again log in to Resgrid and update your profile."); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", "Text messages are now turned off for this user, to enable again log in to Resgrid and update your profile.", department.DepartmentId, textMessage.To, profile); break; case TextCommandTypes.CustomAction: messageEvent.Processed = true; var activeResponseCalls2 = _callsService.GetActiveCallsByDepartment(department.DepartmentId).Where(x => DateTime.Now == x.LoggedOn.Within(TimeSpan.FromMinutes(15))); if (activeResponseCalls2 != null && activeResponseCalls2.Any()) { _actionLogsService.SetUserAction(profile.UserId, department.DepartmentId, payload.GetCustomActionType(), null, activeResponseCalls2.First().CallId); } else { _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()); if (activeResponseCalls2 != null && activeResponseCalls2.Any()) { response = LaMLResponse.Message.Respond(string.Format("Resgrid received your text command. Status changed to: {0} to call {1}", detail.ButtonText, activeResponseCalls2.First().Name)); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", string.Format("Resgrid received your text command. Status changed to: {0}", detail.ButtonText), department.DepartmentId, textMessage.To, profile); } else { response = LaMLResponse.Message.Respond(string.Format("Resgrid received your text command. Status changed to: {0}", detail.ButtonText)); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", string.Format("Resgrid received your text command. Status changed to: {0}", detail.ButtonText), department.DepartmentId, textMessage.To, profile); } } else { response = LaMLResponse.Message.Respond("Resgrid received your text command and updated your status"); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", "Resgrid received your text command and updated your status", department.DepartmentId, textMessage.To, profile); } 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 = LaMLResponse.Message.Respond(string.Format("Resgrid received your text command. Staffing changed to: {0}", detail.ButtonText)); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", string.Format("Resgrid received your text command. Staffing changed to: {0}", detail.ButtonText), department.DepartmentId, textMessage.To, profile); } else { response = LaMLResponse.Message.Respond("Resgrid received your text command and updated your staffing"); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", "Resgrid received your text command and updated your staffing", department.DepartmentId, textMessage.To, profile); } 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 = LaMLResponse.Message.Respond($"Hello {profile.FullName.AsFirstNameLastName} at {DateTime.UtcNow.TimeConverterToString(department)} your current status is {customStatusLevel.ButtonText} and your current staffing is {customStaffingLevel.ButtonText}."); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", $"Hello {profile.FullName.AsFirstNameLastName} at {DateTime.UtcNow.TimeConverterToString(department)} your current status is {customStatusLevel.ButtonText} and your current staffing is {customStaffingLevel.ButtonText}.", department.DepartmentId, textMessage.To, profile); break; case TextCommandTypes.Calls: messageEvent.Processed = true; var activeCalls = _callsService.GetActiveCallsByDepartment(department.DepartmentId); if (activeCalls.Count > 10) { activeCalls = activeCalls.Take(10).ToList(); } var activeCallText = new StringBuilder(); activeCallText.Append($"Top 10 Active Calls for {department.Name}" + Environment.NewLine); activeCallText.Append("---------------------" + Environment.NewLine); foreach (var activeCall in activeCalls) { activeCallText.Append($"CallId: {activeCall.CallId} Name: {activeCall.Name.Truncate(15)} Nature:{activeCall.NatureOfCall.Truncate(30)}" + Environment.NewLine); } response = LaMLResponse.Message.Respond(activeCallText.ToString()); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", activeCallText.ToString(), department.DepartmentId, textMessage.To, profile); 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 = LaMLResponse.Message.Respond(unitStatusesText.ToString()); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", unitStatusesText.ToString(), department.DepartmentId, textMessage.To, profile); 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 = LaMLResponse.Message.Respond(callText.ToString()); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", callText.ToString(), department.DepartmentId, textMessage.To, profile); break; } } } } else if (textMessage.To == Config.NumberProviderConfig.SignalWireResgridNumber.Replace("+", "")) // Resgrid master text number { var payload = _textCommandService.DetermineType(textMessage.Text); switch (payload.Type) { case TextCommandTypes.None: _communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", "Resgrid (https://resgrid.com) Automated Text System. Unknown command, text help for supported commands.", department.DepartmentId, textMessage.To, profile); 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 = LaMLResponse.Message.Respond(help.ToString()); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", help.ToString(), department.DepartmentId, textMessage.To, profile); break; case TextCommandTypes.Stop: messageEvent.Processed = true; _userProfileService.DisableTextMessagesForUser(profile.UserId); response = LaMLResponse.Message.Respond("Text messages are now turned off for this user, to enable again log in to Resgrid and update your profile."); //_communicationService.SendTextMessage(profile.UserId, "Resgrid TCI Help", "Text messages are now turned off for this user, to enable again log in to Resgrid and update your profile.", department.DepartmentId, textMessage.To, profile); break; } } } return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK, Content = new StringContent(response, Encoding.UTF8, "application/xml") }); } catch (Exception ex) { Framework.Logging.LogException(ex); } finally { _numbersService.SaveInboundMessageEvent(messageEvent); } return(new HttpResponseMessage(HttpStatusCode.OK)); }
public PersonnelInfoResult GetPersonnelInfo(string userId) { var result = new PersonnelInfoResult(); var user = _usersService.GetUserById(userId); if (user == null) { throw HttpStatusCode.NotFound.AsException(); } var department = _departmentsService.GetDepartmentByUserId(user.UserId); if (department == null) { throw HttpStatusCode.NotFound.AsException(); } if (department.DepartmentId != DepartmentId) { throw HttpStatusCode.Unauthorized.AsException(); } var profile = _userProfileService.GetProfileByUserId(user.UserId); var group = _departmentGroupsService.GetGroupForUser(user.UserId, DepartmentId); var roles = _personnelRolesService.GetRolesForUser(user.UserId, DepartmentId); if (profile != null) { result.Fnm = profile.FirstName; result.Lnm = profile.LastName; result.Id = profile.IdentificationNumber; result.Mnu = profile.MobileNumber; } else { result.Fnm = "Unknwon"; result.Lnm = "Check Profile"; result.Id = ""; result.Mnu = ""; } result.Eml = user.Email; result.Did = department.DepartmentId; result.Uid = user.UserId.ToString(); if (group != null) { result.Gid = group.DepartmentGroupId; result.Gnm = group.Name; } result.Roles = new List <string>(); if (roles != null && roles.Count > 0) { foreach (var role in roles) { result.Roles.Add(role.Name); } } var action = _actionLogsService.GetLastActionLogForUser(user.UserId, DepartmentId); var userState = _userStateService.GetLastUserStateByUserId(user.UserId); result.Ats = (int)ActionTypes.StandingBy; result.Stf = userState.State; result.Stm = userState.Timestamp.TimeConverter(department); if (action == null) { result.Stm = DateTime.UtcNow.TimeConverter(department); } else { result.Ats = action.ActionTypeId; result.Atm = action.Timestamp.TimeConverter(department); if (action.DestinationId.HasValue) { if (action.ActionTypeId == (int)ActionTypes.RespondingToScene) { result.Did = action.DestinationId.Value; } else if (action.ActionTypeId == (int)ActionTypes.RespondingToStation) { result.Did = action.DestinationId.Value; } else if (action.ActionTypeId == (int)ActionTypes.AvailableStation) { result.Did = action.DestinationId.Value; } } } return(result); }
public int GetDepartmentIdForType(NotificationItem ni) { switch ((EventTypes)ni.Type) { case EventTypes.PersonnelStaffingChanged: var state = _userStateService.GetUserStateById(ni.StateId); if (state != null) { var department = _departmentsService.GetDepartmentByUserId(state.UserId, true); if (department != null) { return(department.DepartmentId); } else { return(0); } } else { return(0); } case EventTypes.PersonnelStatusChanged: var status = _actionLogsService.GetActionlogById(ni.StateId); if (status != null) { var department = _departmentsService.GetDepartmentByUserId(status.UserId, true); if (department != null) { return(department.DepartmentId); } else { return(0); } } else { return(0); } case EventTypes.CalendarEventAdded: var cal = _calendarService.GetCalendarItemById(ni.ItemId); if (cal != null) { return(cal.DepartmentId); } else { return(0); } case EventTypes.CalendarEventUpcoming: var calUp = _calendarService.GetCalendarItemById(ni.ItemId); if (calUp != null) { return(calUp.DepartmentId); } else { return(0); } case EventTypes.CalendarEventUpdated: var calUpdate = _calendarService.GetCalendarItemById(ni.ItemId); if (calUpdate != null) { return(calUpdate.DepartmentId); } else { return(0); } case EventTypes.DocumentAdded: var docAdded = _documentsService.GetDocumentById(ni.ItemId); if (docAdded != null) { return(docAdded.DepartmentId); } else { return(0); } case EventTypes.LogAdded: var logAdded = _workLogsService.GetWorkLogById(ni.ItemId); if (logAdded != null) { return(logAdded.DepartmentId); } else { return(0); } case EventTypes.NoteAdded: var noteAdded = _notesService.GetNoteById(ni.ItemId); if (noteAdded != null) { return(noteAdded.DepartmentId); } else { return(0); } case EventTypes.ShiftCreated: var shiftCreated = _shiftsService.GetShiftById(ni.ItemId); if (shiftCreated != null) { return(shiftCreated.DepartmentId); } else { return(0); } case EventTypes.ShiftDaysAdded: var shiftDaysAdded = _shiftsService.GetShiftById(ni.ItemId); if (shiftDaysAdded != null) { return(shiftDaysAdded.DepartmentId); } else { return(0); } case EventTypes.ShiftUpdated: var shiftUpdated = _shiftsService.GetShiftById(ni.ItemId); if (shiftUpdated != null) { return(shiftUpdated.DepartmentId); } else { return(0); } case EventTypes.UnitAdded: var unitAdded = _unitsService.GetUnitById(ni.UnitId); if (unitAdded != null) { return(unitAdded.DepartmentId); } else { return(0); } case EventTypes.UnitStatusChanged: var unitStatusChanged = _unitsService.GetUnitStateById(ni.StateId); if (unitStatusChanged != null) { var unit = _unitsService.GetUnitById(unitStatusChanged.UnitId); if (unit != null) { return(unit.DepartmentId); } else { return(0); } } else { return(0); } } return(0); }
public bool CanUserManageInvite(string userId, int inviteId) { var department = _departmentsService.GetDepartmentByUserId(userId); var invite = _invitesService.GetInviteById(inviteId); if (department == null || invite == null) { return(false); } if (!department.IsUserAnAdmin(userId)) { return(false); } if (invite.DepartmentId != department.DepartmentId) { return(false); } return(true); }