public IActionResult Index() { var model = new UnitsIndexView(); model.Department = _departmentsService.GetDepartmentById(DepartmentId); model.CanUserAddUnit = _limitsService.CanDepartentAddNewUnit(DepartmentId); model.Groups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); model.Units = _unitsService.GetUnitsForDepartment(DepartmentId); model.States = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); model.UnitStatuses = _customStateService.GetAllActiveUnitStatesForDepartment(DepartmentId); model.UnitCustomStates = new Dictionary <int, CustomState>(); foreach (var unit in model.Units) { var type = _unitsService.GetUnitTypeByName(DepartmentId, unit.Type); if (type != null && type.CustomStatesId.HasValue) { var customStates = _customStateService.GetCustomSateById(type.CustomStatesId.Value); if (customStates != null) { model.UnitCustomStates.Add(unit.UnitId, customStates); } } } return(View(model)); }
public List <UnitStatusResult> GetUnitStatusesForLink(int linkId) { var results = new List <UnitStatusResult>(); var link = _departmentLinksService.GetLinkById(linkId); if (link.DepartmentId != DepartmentId && link.LinkedDepartmentId != DepartmentId) { return(new List <UnitStatusResult>()); } var units = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(link.DepartmentId); var department = _departmentsService.GetDepartmentById(link.DepartmentId, false); foreach (var u in units) { var unitStatus = new UnitStatusResult(); unitStatus.Uid = u.UnitId; unitStatus.Typ = u.State; unitStatus.Tmp = u.Timestamp.TimeConverter(department); if (u.DestinationId.HasValue) { unitStatus.Did = u.DestinationId.Value; } results.Add(unitStatus); } return(results); }
public List <UnitStatusResult> GetUnitStatuses() { var results = new List <UnitStatusResult>(); var units = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); var department = _departmentsService.GetDepartmentById(DepartmentId, false); /* * Parallel.ForEach(units, u => * { * var unitStatus = new UnitStatusResult(); * unitStatus.Uid = u.UnitId; * unitStatus.Typ = u.State; * unitStatus.Tmp = u.Timestamp.TimeConverter(department); * * if (u.DestinationId.HasValue) * unitStatus.Did = u.DestinationId.Value; * * results.Add(unitStatus); * }); */ foreach (var u in units) { var unitStatus = new UnitStatusResult(); unitStatus.Uid = u.UnitId; unitStatus.Typ = u.State; unitStatus.Tmp = u.Timestamp.TimeConverter(department); if (u.DestinationId.HasValue) { unitStatus.Did = u.DestinationId.Value; } results.Add(unitStatus); } return(results); }
public IActionResult GetUnitsList() { List <UnitForListJson> unitsJson = new List <UnitForListJson>(); var units = _unitsService.GetUnitsForDepartment(DepartmentId); var states = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); var department = _departmentsService.GetDepartmentById(DepartmentId, false); foreach (var unit in units) { var unitJson = new UnitForListJson(); unitJson.Name = unit.Name; unitJson.Type = unit.Type; unitJson.UnitId = unit.UnitId; if (unit.StationGroup != null) { unitJson.Station = unit.StationGroup.Name; } var state = states.FirstOrDefault(x => x.UnitId == unit.UnitId); if (state != null) { var customState = CustomStatesHelper.GetCustomUnitState(state); unitJson.StateId = state.State; unitJson.State = customState.ButtonText; unitJson.StateColor = customState.ButtonColor; unitJson.TextColor = customState.TextColor; unitJson.Timestamp = state.Timestamp.TimeConverterToString(department); } unitsJson.Add(unitJson); } return(Json(unitsJson)); }
public List <StationResult> GetStationResources() { var result = new List <StationResult>(); var unitStatuses = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); var actionLogs = _actionLogsService.GetActionLogsForDepartment(DepartmentId); var userStates = _userStateService.GetLatestStatesForDepartment(DepartmentId); var stations = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var userGroups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId); var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); var units = _unitsService.GetUnitsForDepartment(DepartmentId); Department department = _departmentsService.GetDepartmentById(DepartmentId, false); Parallel.ForEach(users, u => { var log = (from l in actionLogs where l.UserId == u.UserId select l).FirstOrDefault(); var state = (from l in userStates where l.UserId == u.UserId select l).FirstOrDefault(); var s = new StationResult(); s.Id = u.UserId.ToString(); s.Typ = 1; if (log != null) { s.Sts = log.ActionTypeId; s.Stm = log.Timestamp.TimeConverter(department); if (log.DestinationId.HasValue) { if (log.ActionTypeId == (int)ActionTypes.RespondingToStation) { s.Did = log.DestinationId.GetValueOrDefault(); var group = stations.First(x => x.DepartmentGroupId == log.DestinationId.Value); s.Dnm = group.Name; } else if (log.ActionTypeId == (int)ActionTypes.AvailableStation) { s.Did = log.DestinationId.GetValueOrDefault(); var group = stations.First(x => x.DepartmentGroupId == log.DestinationId.Value); s.Dnm = group.Name; } } } else { s.Sts = (int)ActionTypes.StandingBy; s.Stm = DateTime.UtcNow.TimeConverter(department); } if (s.Did == 0) { if (userGroups.ContainsKey(u.UserId)) { var homeGroup = userGroups[u.UserId]; if (homeGroup != null && homeGroup.Type.HasValue && ((DepartmentGroupTypes)homeGroup.Type) == DepartmentGroupTypes.Station) { s.Did = homeGroup.DepartmentGroupId; s.Dnm = homeGroup.Name; } } } if (state != null) { s.Ste = state.State; s.Stt = state.Timestamp.TimeConverter(department); } else { s.Ste = (int)UserStateTypes.Available; s.Stt = DateTime.UtcNow.TimeConverter(department); } if (!String.IsNullOrWhiteSpace(s.Dnm)) { result.Add(s); } }); Parallel.ForEach(unitStatuses, unit => { var unitResult = new StationResult(); var savedUnit = units.FirstOrDefault(x => x.UnitId == unit.UnitId); if (savedUnit != null) { unitResult.Id = savedUnit.UnitId.ToString(); //unitResult.Nme = savedUnit.Name; unitResult.Typ = 2; unitResult.Sts = unit.State; unitResult.Stm = unit.Timestamp.TimeConverter(department); if (savedUnit.StationGroupId.HasValue) { unitResult.Did = savedUnit.StationGroupId.Value; unitResult.Dnm = stations.First(x => x.DepartmentGroupId == savedUnit.StationGroupId.Value).Name; result.Add(unitResult); } } }); return(result); }
public UnitAppPayloadResult GetCommandAppCoreData() { var results = new UnitAppPayloadResult(); results.Personnel = new List <PersonnelInfoResult>(); results.Groups = new List <GroupInfoResult>(); results.Units = new List <UnitInfoResult>(); results.Roles = new List <RoleInfoResult>(); results.Statuses = new List <CustomStatusesResult>(); results.Calls = new List <CallResult>(); results.UnitStatuses = new List <UnitStatusCoreResult>(); results.UnitRoles = new List <UnitRoleResult>(); var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); var groups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId); var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId); var allRoles = _personnelRolesService.GetRolesForDepartment(DepartmentId); var allProfiles = _userProfileService.GetAllProfilesForDepartment(DepartmentId); var allGroups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var units = _unitsService.GetUnitsForDepartment(DepartmentId); var unitTypes = _unitsService.GetUnitTypesForDepartment(DepartmentId); foreach (var user in users) { //var profile = _userProfileService.GetProfileByUserId(user.UserId); //var group = _departmentGroupsService.GetGroupForUser(user.UserId); UserProfile profile = null; if (allProfiles.ContainsKey(user.UserId)) { profile = allProfiles[user.UserId]; } DepartmentGroup group = null; if (groups.ContainsKey(user.UserId)) { group = groups[user.UserId]; } //var roles = _personnelRolesService.GetRolesForUser(user.UserId); List <PersonnelRole> roles = null; if (rolesForUsersInDepartment.ContainsKey(user.UserId)) { roles = rolesForUsersInDepartment[user.UserId]; } var result = new PersonnelInfoResult(); if (profile != null) { result.Fnm = profile.FirstName; result.Lnm = profile.LastName; result.Id = profile.IdentificationNumber; result.Mnu = profile.MobileNumber; } else { result.Fnm = "Unknown"; result.Lnm = "Check Profile"; result.Id = ""; result.Mnu = ""; } result.Eml = user.Email; result.Did = 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) { if (role != null) { result.Roles.Add(role.Name); } } } results.Personnel.Add(result); } results.Rights = new DepartmentRightsResult(); var currentUser = _usersService.GetUserByName(UserName); if (currentUser == null) { throw HttpStatusCode.Unauthorized.AsException(); } var department = _departmentsService.GetDepartmentById(DepartmentId, false); results.Rights.Adm = department.IsUserAnAdmin(currentUser.UserId); results.Rights.Grps = new List <GroupRight>(); var currentGroup = _departmentGroupsService.GetGroupForUser(currentUser.UserId, DepartmentId); if (currentGroup != null) { var groupRight = new GroupRight(); groupRight.Gid = currentGroup.DepartmentGroupId; groupRight.Adm = currentGroup.IsUserGroupAdmin(currentUser.UserId); results.Rights.Grps.Add(groupRight); } foreach (var group in allGroups) { var groupInfo = new GroupInfoResult(); groupInfo.Gid = group.DepartmentGroupId; groupInfo.Nme = group.Name; if (group.Type.HasValue) { groupInfo.Typ = group.Type.Value; } if (group.Address != null) { groupInfo.Add = group.Address.FormatAddress(); } results.Groups.Add(groupInfo); } foreach (var unit in units) { var unitResult = new UnitInfoResult(); unitResult.Uid = unit.UnitId; unitResult.Did = DepartmentId; unitResult.Nme = unit.Name; unitResult.Typ = unit.Type; if (!string.IsNullOrWhiteSpace(unit.Type)) { var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type); if (unitType != null) { unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault(); } } else { unitResult.Cid = 0; } if (unit.StationGroup != null) { unitResult.Sid = unit.StationGroup.DepartmentGroupId; unitResult.Snm = unit.StationGroup.Name; } results.Units.Add(unitResult); // Add unit roles for this unit var roles = _unitsService.GetRolesForUnit(unit.UnitId); foreach (var role in roles) { var roleResult = new UnitRoleResult(); roleResult.Name = role.Name; roleResult.UnitId = role.UnitId; roleResult.UnitRoleId = role.UnitRoleId; results.UnitRoles.Add(roleResult); } } var unitStatuses = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); foreach (var us in unitStatuses) { var unitStatus = new UnitStatusCoreResult(); unitStatus.UnitId = us.UnitId; unitStatus.StateType = (UnitStateTypes)us.State; unitStatus.StateTypeId = us.State; unitStatus.Type = us.Unit.Type; unitStatus.Timestamp = us.Timestamp.TimeConverter(department); unitStatus.Name = us.Unit.Name; if (us.DestinationId.HasValue) { unitStatus.DestinationId = us.DestinationId.Value; } results.UnitStatuses.Add(unitStatus); } foreach (var role in allRoles) { var roleResult = new RoleInfoResult(); roleResult.Rid = role.PersonnelRoleId; roleResult.Nme = role.Name; results.Roles.Add(roleResult); } var customStates = _customStateService.GetAllActiveCustomStatesForDepartment(DepartmentId); foreach (var customState in customStates) { if (customState.IsDeleted) { continue; } foreach (var stateDetail in customState.GetActiveDetails()) { if (stateDetail.IsDeleted) { continue; } var customStateResult = new CustomStatusesResult(); customStateResult.Id = stateDetail.CustomStateDetailId; customStateResult.Type = customState.Type; customStateResult.StateId = stateDetail.CustomStateId; customStateResult.Text = stateDetail.ButtonText; customStateResult.BColor = stateDetail.ButtonColor; customStateResult.Color = stateDetail.TextColor; customStateResult.Gps = stateDetail.GpsRequired; customStateResult.Note = stateDetail.NoteType; customStateResult.Detail = stateDetail.DetailType; results.Statuses.Add(customStateResult); } } var calls = _callsService.GetActiveCallsByDepartment(DepartmentId).OrderByDescending(x => x.LoggedOn); if (calls != null && calls.Any()) { foreach (var c in calls) { 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; 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.Add = c.Address; call.Geo = c.GeoLocationData; call.Lon = c.LoggedOn.TimeConverter(department); call.Ste = c.State; call.Num = c.Number; results.Calls.Add(call); } } else { // This is a hack due to a bug in the current units app! -SJ 1-31-2016 var call = new CallResult(); call.Cid = 0; call.Pri = 0; call.Ctl = false; call.Nme = "No Call"; call.Noc = ""; call.Map = ""; call.Not = ""; call.Add = ""; call.Geo = ""; call.Lon = DateTime.UtcNow; call.Ste = 0; call.Num = ""; results.Calls.Add(call); } return(results); }
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 GetMapData(MapSettingsInput input) { MapDataJson dataJson = new MapDataJson(); var calls = _callsService.GetActiveCallsByDepartment(DepartmentId); var department = _departmentsService.GetDepartmentById(DepartmentId, false); var stations = _departmentGroupsService.GetAllStationGroupsForDepartment(DepartmentId); var lastUserActionlogs = _actionLogsService.GetActionLogsForDepartment(DepartmentId); var personnelNames = _departmentsService.GetAllPersonnelNamesForDepartment(DepartmentId); var unitStates = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); var userLocationPermission = _permissionsService.GetPermisionByDepartmentType(DepartmentId, PermissionTypes.CanSeePersonnelLocations); if (userLocationPermission != null) { var userGroup = _departmentGroupsService.GetGroupForUser(UserId, DepartmentId); int?groupId = null; if (userGroup != null) { groupId = userGroup.DepartmentGroupId; } var roles = _personnelRolesService.GetRolesForUser(UserId, DepartmentId); var allowedUsers = _permissionsService.GetAllowedUsers(userLocationPermission, DepartmentId, groupId, ClaimsAuthorizationHelper.IsUserDepartmentAdmin(), ClaimsAuthorizationHelper.IsUserDepartmentAdmin(), roles); lastUserActionlogs.RemoveAll(x => !allowedUsers.Contains(x.UserId)); } if (input.ShowDistricts) { foreach (var station in stations) { if (!String.IsNullOrWhiteSpace(station.Geofence)) { GeofenceJson geofence = new GeofenceJson(); geofence.Name = station.Name; geofence.Color = station.GeofenceColor; geofence.Fence = station.Geofence; dataJson.Geofences.Add(geofence); } } } if (input.ShowStations) { foreach (var station in stations) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Station"; info.Title = station.Name; info.InfoWindowContent = station.Name; if (station.Address != null) { string coordinates = _geoLocationProvider.GetLatLonFromAddress(string.Format("{0} {1} {2} {3}", station.Address.Address1, station.Address.City, station.Address.State, station.Address.PostalCode)); if (!String.IsNullOrEmpty(coordinates)) { info.Latitude = double.Parse(coordinates.Split(char.Parse(","))[0]); info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]); dataJson.Markers.Add(info); } } else if (!String.IsNullOrWhiteSpace(station.Latitude) && !String.IsNullOrWhiteSpace(station.Longitude)) { info.Latitude = double.Parse(station.Latitude); info.Longitude = double.Parse(station.Longitude); dataJson.Markers.Add(info); } } } if (input.ShowCalls) { foreach (var call in calls) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Call"; info.Title = call.Name; info.InfoWindowContent = call.NatureOfCall; if (!String.IsNullOrEmpty(call.GeoLocationData)) { try { info.Latitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[0]); info.Longitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[1]); dataJson.Markers.Add(info); } catch { } } else if (!String.IsNullOrEmpty(call.Address)) { string coordinates = _geoLocationProvider.GetLatLonFromAddress(call.Address); if (!String.IsNullOrEmpty(coordinates)) { info.Latitude = double.Parse(coordinates.Split(char.Parse(","))[0]); info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]); } dataJson.Markers.Add(info); } } } if (input.ShowUnits) { foreach (var unit in unitStates) { if (unit.Latitude.HasValue && unit.Latitude.Value != 0 && unit.Longitude.HasValue && unit.Longitude.Value != 0) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Engine_Responding"; info.Title = unit.Unit.Name; info.InfoWindowContent = ""; info.Latitude = double.Parse(unit.Latitude.Value.ToString()); info.Longitude = double.Parse(unit.Longitude.Value.ToString()); dataJson.Markers.Add(info); } } } if (input.ShowPersonnel) { foreach (var person in lastUserActionlogs) { if (!String.IsNullOrWhiteSpace(person.GeoLocationData)) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Person"; var name = personnelNames.FirstOrDefault(x => x.UserId == person.UserId); if (name != null) { info.Title = name.Name; info.InfoWindowContent = ""; } else { info.Title = ""; info.InfoWindowContent = ""; } var infos = person.GeoLocationData.Split(char.Parse(",")); if (infos != null && infos.Length == 2) { info.Latitude = double.Parse(infos[0]); info.Longitude = double.Parse(infos[1]); dataJson.Markers.Add(info); } } } } if (input.ShowPOIs) { var poiTypes = _mappingService.GetPOITypesForDepartment(DepartmentId); foreach (var poiType in poiTypes) { foreach (var poi in poiType.Pois) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = poiType.Image; info.Marker = poiType.Marker; info.Title = poiType.Name; info.InfoWindowContent = ""; info.Latitude = poi.Latitude; info.Longitude = poi.Longitude; info.Color = poiType.Color; dataJson.Pois.Add(info); } } } return(Json(dataJson)); }
public List <UnitViewModel> GetUnitStatuses() { var units = _unitsService.GetUnitsForDepartment(DepartmentId); var unitStates = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); var unitViewModels = new List <UnitViewModel>(); var sortedUnits = from u in units let station = u.StationGroup let stationName = station == null ? "" : station.Name orderby stationName, u.Name ascending select new { Unit = u, Station = station, StationName = stationName }; foreach (var unit in sortedUnits) { var stateFound = unitStates.FirstOrDefault(x => x.UnitId == unit.Unit.UnitId); var state = "Unknown"; var stateCss = ""; var stateStyle = ""; int? destinationId = 0; decimal?latitude = 0; decimal?longitude = 0; DateTime?timestamp = null; if (stateFound != null) { var customState = CustomStatesHelper.GetCustomUnitState(stateFound); if (customState != null) { state = customState.ButtonText; stateCss = customState.ButtonColor; stateStyle = customState.ButtonColor; } else { state = stateFound.ToStateDisplayText(); stateCss = stateFound.ToStateCss(); } destinationId = stateFound.DestinationId; latitude = stateFound.Latitude; longitude = stateFound.Longitude; timestamp = stateFound.Timestamp; } int groupId = 0; if (unit.Station != null) { groupId = unit.Station.DepartmentGroupId; } var unitViewModel = new UnitViewModel { Name = unit.Unit.Name, Type = unit.Unit.Type, State = state, StateCss = stateCss, StateStyle = stateStyle, Timestamp = timestamp, DestinationId = destinationId, Latitude = latitude, Longitude = longitude, GroupId = groupId, GroupName = unit.StationName }; unitViewModels.Add(unitViewModel); } return(unitViewModels); }
public NewCallPayloadResult GetNewCallData() { var results = new NewCallPayloadResult(); results.Personnel = new List <PersonnelInfoResult>(); results.Groups = new List <GroupInfoResult>(); results.Units = new List <UnitInfoResult>(); results.Roles = new List <RoleInfoResult>(); results.Statuses = new List <CustomStatusesResult>(); results.UnitStatuses = new List <UnitStatusCoreResult>(); results.UnitRoles = new List <UnitRoleResult>(); results.Priorities = new List <CallPriorityResult>(); results.CallTypes = new List <CallTypeResult>(); var department = _departmentsService.GetDepartmentById(DepartmentId, false); var users = _departmentsService.GetAllUsersForDepartment(DepartmentId); var groups = _departmentGroupsService.GetAllDepartmentGroupsForDepartment(DepartmentId); var rolesForUsersInDepartment = _personnelRolesService.GetAllRolesForUsersInDepartment(DepartmentId); var allRoles = _personnelRolesService.GetRolesForDepartment(DepartmentId); var allProfiles = _userProfileService.GetAllProfilesForDepartment(DepartmentId); var allGroups = _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); var units = _unitsService.GetUnitsForDepartment(DepartmentId); var unitTypes = _unitsService.GetUnitTypesForDepartment(DepartmentId); var callPriorites = _callsService.GetCallPrioritesForDepartment(DepartmentId); var callTypes = _callsService.GetCallTypesForDepartment(DepartmentId); foreach (var user in users) { //var profile = _userProfileService.GetProfileByUserId(user.UserId); //var group = _departmentGroupsService.GetGroupForUser(user.UserId); UserProfile profile = null; if (allProfiles.ContainsKey(user.UserId)) { profile = allProfiles[user.UserId]; } DepartmentGroup group = null; if (groups.ContainsKey(user.UserId)) { group = groups[user.UserId]; } //var roles = _personnelRolesService.GetRolesForUser(user.UserId); List <PersonnelRole> roles = null; if (rolesForUsersInDepartment.ContainsKey(user.UserId)) { roles = rolesForUsersInDepartment[user.UserId]; } var result = new PersonnelInfoResult(); if (profile != null) { result.Fnm = profile.FirstName; result.Lnm = profile.LastName; result.Id = profile.IdentificationNumber; result.Mnu = profile.MobileNumber; } else { result.Fnm = "Unknown"; result.Lnm = "Check Profile"; result.Id = ""; result.Mnu = ""; } result.Eml = user.Email; result.Did = 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) { if (role != null) { result.Roles.Add(role.Name); } } } results.Personnel.Add(result); } foreach (var group in allGroups) { var groupInfo = new GroupInfoResult(); groupInfo.Gid = group.DepartmentGroupId; groupInfo.Nme = group.Name; if (group.Type.HasValue) { groupInfo.Typ = group.Type.Value; } if (group.Address != null) { groupInfo.Add = group.Address.FormatAddress(); } results.Groups.Add(groupInfo); } foreach (var unit in units) { var unitResult = new UnitInfoResult(); unitResult.Uid = unit.UnitId; unitResult.Did = DepartmentId; unitResult.Nme = unit.Name; unitResult.Typ = unit.Type; if (!string.IsNullOrWhiteSpace(unit.Type)) { var unitType = unitTypes.FirstOrDefault(x => x.Type == unit.Type); if (unitType != null) { unitResult.Cid = unitType.CustomStatesId.GetValueOrDefault(); } } else { unitResult.Cid = 0; } if (unit.StationGroup != null) { unitResult.Sid = unit.StationGroup.DepartmentGroupId; unitResult.Snm = unit.StationGroup.Name; } results.Units.Add(unitResult); // Add unit roles for this unit var roles = _unitsService.GetRolesForUnit(unit.UnitId); foreach (var role in roles) { var roleResult = new UnitRoleResult(); roleResult.Name = role.Name; roleResult.UnitId = role.UnitId; roleResult.UnitRoleId = role.UnitRoleId; results.UnitRoles.Add(roleResult); } } var unitStatuses = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(DepartmentId); foreach (var us in unitStatuses) { var unitStatus = new UnitStatusCoreResult(); unitStatus.UnitId = us.UnitId; unitStatus.StateType = (UnitStateTypes)us.State; unitStatus.StateTypeId = us.State; unitStatus.Type = us.Unit.Type; unitStatus.Timestamp = us.Timestamp.TimeConverter(department); unitStatus.Name = us.Unit.Name; unitStatus.Note = us.Note; if (us.DestinationId.HasValue) { unitStatus.DestinationId = us.DestinationId.Value; } if (us.LocalTimestamp.HasValue) { unitStatus.LocalTimestamp = us.LocalTimestamp.Value; } if (us.Latitude.HasValue) { unitStatus.Latitude = us.Latitude.Value; } if (us.Longitude.HasValue) { unitStatus.Longitude = us.Longitude.Value; } results.UnitStatuses.Add(unitStatus); } foreach (var role in allRoles) { var roleResult = new RoleInfoResult(); roleResult.Rid = role.PersonnelRoleId; roleResult.Nme = role.Name; results.Roles.Add(roleResult); } var customStates = _customStateService.GetAllActiveCustomStatesForDepartment(DepartmentId); foreach (var customState in customStates) { if (customState.IsDeleted) { continue; } foreach (var stateDetail in customState.GetActiveDetails()) { if (stateDetail.IsDeleted) { continue; } var customStateResult = new CustomStatusesResult(); customStateResult.Id = stateDetail.CustomStateDetailId; customStateResult.Type = customState.Type; customStateResult.StateId = stateDetail.CustomStateId; customStateResult.Text = stateDetail.ButtonText; customStateResult.BColor = stateDetail.ButtonColor; customStateResult.Color = stateDetail.TextColor; customStateResult.Gps = stateDetail.GpsRequired; customStateResult.Note = stateDetail.NoteType; customStateResult.Detail = stateDetail.DetailType; results.Statuses.Add(customStateResult); } } foreach (var priority in callPriorites) { var priorityResult = new CallPriorityResult(); priorityResult.Id = priority.DepartmentCallPriorityId; priorityResult.DepartmentId = priority.DepartmentId; priorityResult.Name = priority.Name; priorityResult.Color = priority.Color; priorityResult.Sort = priority.Sort; priorityResult.IsDeleted = priority.IsDeleted; priorityResult.IsDefault = priority.IsDefault; results.Priorities.Add(priorityResult); } if (callTypes != null && callTypes.Any()) { foreach (var callType in callTypes) { var type = new CallTypeResult(); type.Id = callType.CallTypeId; type.Name = callType.Type; results.CallTypes.Add(type); } } return(results); }
public bool ValidateNotificationForProcessing(ProcessedNotification notification, DepartmentNotification setting) { //dynamic dynamicData = JsonConvert.DeserializeObject(notification.Data); NotificationItem dynamicData = ObjectSerialization.Deserialize <NotificationItem>(notification.Data); switch (notification.Type) { case EventTypes.UnitStatusChanged: if (!String.IsNullOrWhiteSpace(setting.BeforeData) && !String.IsNullOrWhiteSpace(setting.CurrentData)) { if (setting.BeforeData.Contains("-1") && setting.CurrentData.Contains("-1")) { return(true); } bool beforeAny = setting.BeforeData.Contains("-1"); bool currentAny = setting.CurrentData.Contains("-1"); UnitState beforeState = null; UnitState currentState = null; currentState = _unitsService.GetUnitStateById((int)dynamicData.StateId); if (!beforeAny) { beforeState = _unitsService.GetLastUnitStateBeforeId(currentState.UnitId, currentState.UnitStateId); } if ((currentAny || currentState.State == int.Parse(setting.CurrentData)) && (beforeAny || beforeState.State == int.Parse(setting.BeforeData))) { return(true); } } else { return(false); } break; case EventTypes.PersonnelStaffingChanged: if (!String.IsNullOrWhiteSpace(setting.BeforeData) && !String.IsNullOrWhiteSpace(setting.CurrentData)) { if (setting.BeforeData.Contains("-1") && setting.CurrentData.Contains("-1")) { return(true); } bool beforeAny = setting.BeforeData.Contains("-1"); bool currentAny = setting.CurrentData.Contains("-1"); UserState beforeState = null; UserState currentState = null; currentState = _userStateService.GetUserStateById((int)dynamicData.StateId); if (!beforeAny) { beforeState = _userStateService.GetPerviousUserState(currentState.UserId, currentState.UserStateId); } if ((currentAny || currentState.State == int.Parse(setting.CurrentData)) && (beforeAny || beforeState.State == int.Parse(setting.BeforeData))) { return(true); } } else { return(false); } break; case EventTypes.PersonnelStatusChanged: if (!String.IsNullOrWhiteSpace(setting.BeforeData) && !String.IsNullOrWhiteSpace(setting.CurrentData)) { if (setting.BeforeData.Contains("-1") && setting.CurrentData.Contains("-1")) { return(true); } bool beforeAny = setting.BeforeData.Contains("-1"); bool currentAny = setting.CurrentData.Contains("-1"); ActionLog beforeState = null; ActionLog currentState = null; currentState = _actionLogsService.GetActionlogById((int)dynamicData.StateId); if (!beforeAny) { beforeState = _actionLogsService.GetPreviousActionLog(currentState.UserId, currentState.ActionLogId); } if ((currentAny || currentState.ActionTypeId == int.Parse(setting.CurrentData)) && (beforeAny || beforeState.ActionTypeId == int.Parse(setting.BeforeData))) { return(true); } } else { return(false); } break; case EventTypes.RolesInGroupAvailabilityAlert: if (!String.IsNullOrWhiteSpace(setting.CurrentData) && !String.IsNullOrWhiteSpace(setting.Data)) { int count = 0; var userStateChanged = _userStateService.GetUserStateById((int)dynamicData.StateId); var usersInRole = _personnelRolesService.GetAllMembersOfRole(int.Parse(setting.Data)); var group = _departmentGroupsService.GetGroupForUser(userStateChanged.UserId, notification.DepartmentId); if (group == null || group.Members == null || !group.Members.Any()) { return(false); } var acceptableStaffingLevels = setting.CurrentData.Split(char.Parse(",")); if (usersInRole != null && !usersInRole.Any()) { return(false); } var staffingLevels = _userStateService.GetLatestStatesForDepartment(setting.DepartmentId); if (staffingLevels != null && staffingLevels.Any()) { foreach (var user in usersInRole) { var currentState = staffingLevels.FirstOrDefault(x => x.UserId == user.UserId); if (currentState != null && acceptableStaffingLevels.Any(x => x == currentState.State.ToString()) && group.Members.Any(x => x.UserId == user.UserId)) { count++; } } if (count <= setting.LowerLimit) { notification.PersonnelRoleTargeted = int.Parse(setting.Data); return(true); } } else { return(false); } } else { return(false); } break; case EventTypes.RolesInDepartmentAvailabilityAlert: if (!String.IsNullOrWhiteSpace(setting.CurrentData) && !String.IsNullOrWhiteSpace(setting.Data)) { int count = 0; var usersInRole = _personnelRolesService.GetAllMembersOfRole(int.Parse(setting.Data)); var acceptableStaffingLevels = setting.CurrentData.Split(char.Parse(",")); if (usersInRole != null && !usersInRole.Any()) { return(false); } var staffingLevels = _userStateService.GetLatestStatesForDepartment(setting.DepartmentId); if (staffingLevels != null && staffingLevels.Any()) { foreach (var user in usersInRole) { var currentState = staffingLevels.FirstOrDefault(x => x.UserId == user.UserId); if (currentState != null && acceptableStaffingLevels.Any(x => x == currentState.State.ToString())) { count++; } } if (count <= setting.LowerLimit) { notification.PersonnelRoleTargeted = int.Parse(setting.Data); return(true); } } else { return(false); } } else { return(false); } break; case EventTypes.UnitTypesInGroupAvailabilityAlert: if (!String.IsNullOrWhiteSpace(setting.CurrentData) && !String.IsNullOrWhiteSpace(setting.Data)) { int count = 0; var currentUnitState = _unitsService.GetUnitStateById((int)dynamicData.StateId); var unitsForType = _unitsService.GetAllUnitsForType(setting.DepartmentId, setting.Data); var unitForEvent = _unitsService.GetUnitById(currentUnitState.UnitId); if (unitForEvent?.StationGroupId == null) { return(false); } var acceptableUnitStates = setting.CurrentData.Split(char.Parse(",")); var unitsInGroup = _unitsService.GetAllUnitsForGroup(unitForEvent.StationGroupId.Value); if (unitsForType != null && !unitsForType.Any()) { return(false); } var staffingLevels = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(setting.DepartmentId); foreach (var unit in unitsForType) { var currentState = staffingLevels.FirstOrDefault(x => x.UnitId == unit.UnitId); if (currentState != null && acceptableUnitStates.Any(x => x == currentState.State.ToString()) && unitsInGroup.Any(x => x.UnitId == unit.UnitId)) { count++; } } if (count <= setting.LowerLimit) { notification.UnitTypeTargeted = setting.Data; return(true); } } else { return(false); } break; case EventTypes.UnitTypesInDepartmentAvailabilityAlert: if (!String.IsNullOrWhiteSpace(setting.CurrentData) && !String.IsNullOrWhiteSpace(setting.Data)) { int count = 0; var unitsForType = _unitsService.GetAllUnitsForType(setting.DepartmentId, setting.Data); var acceptableUnitStates = setting.CurrentData.Split(char.Parse(",")); if (unitsForType != null && !unitsForType.Any()) { return(false); } var staffingLevels = _unitsService.GetAllLatestStatusForUnitsByDepartmentId(setting.DepartmentId); foreach (var unit in unitsForType) { var currentState = staffingLevels.FirstOrDefault(x => x.UnitId == unit.UnitId); if (currentState != null && acceptableUnitStates.Any(x => x == currentState.State.ToString())) { count++; } } if (count <= setting.LowerLimit) { notification.UnitTypeTargeted = setting.Data; return(true); } } else { return(false); } break; default: return(true); } return(false); }