public async Task <IActionResult> GetUnitsList() { List <UnitForListJson> unitsJson = new List <UnitForListJson>(); var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId); var states = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId); var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false); var groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId); foreach (var unit in units) { var unitJson = new UnitForListJson(); unitJson.Name = unit.Name; unitJson.Type = unit.Type; unitJson.UnitId = unit.UnitId; if (unit.StationGroupId.HasValue) { var group = groups.FirstOrDefault(x => x.DepartmentGroupId == unit.StationGroupId.Value); if (group != null) { unitJson.Station = group.Name; } } var state = states.FirstOrDefault(x => x.UnitId == unit.UnitId); if (state != null) { var customState = await 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 async Task <IActionResult> GetUnitsList(int linkId) { var link = await _departmentLinksService.GetLinkByIdAsync(linkId); if (link.DepartmentId != DepartmentId && link.LinkedDepartmentId != DepartmentId) { Unauthorized(); } List <UnitForListJson> unitsJson = new List <UnitForListJson>(); var units = await _unitsService.GetUnitsForDepartmentAsync(link.DepartmentId); var states = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(link.DepartmentId); var department = await _departmentsService.GetDepartmentByIdAsync(link.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 = await 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 static PersonnelViewModel Create(string name, ActionLog actionLog, UserState userState, Department department, DepartmentGroup respondingToDepartment, DepartmentGroup group, List <PersonnelRole> roles, string callNumber) { DateTime updateDate = TimeConverterHelper.TimeConverter(DateTime.UtcNow, department); string status = ""; string statusCss = ""; string state = ""; string stateCss = ""; string stateStyle = ""; string statusStyle = ""; double?latitude = null; double?longitude = null; int statusValue = 0; double eta = 0; int destinationType = 0; if (userState != null) { if (userState.State <= 25) { if (userState.State == 0) { state = "Available"; stateCss = "label-default"; } else if (userState.State == 1) { state = "Delayed"; stateCss = "label-warning"; } else if (userState.State == 2) { state = "Unavailable"; stateCss = "label-danger"; } else if (userState.State == 3) { state = "Committed"; stateCss = "label-info"; } else if (userState.State == 4) { state = "On Shift"; stateCss = "label-info"; } } else { var customState = CustomStatesHelper.GetCustomState(department.DepartmentId, userState.State); if (customState != null) { state = customState.ButtonText; stateCss = "label-default"; stateStyle = string.Format("color:{0};background-color:{1};", customState.TextColor, customState.ButtonColor); } else { state = "Unknown"; stateCss = "label-default"; } } } else { state = "Available"; stateCss = "label-default"; } if (actionLog == null) { status = "Standing By"; statusCss = "label-default"; } else { updateDate = TimeConverterHelper.TimeConverter(actionLog.Timestamp, department); eta = actionLog.Eta; destinationType = actionLog.DestinationType.GetValueOrDefault(); statusValue = actionLog.ActionTypeId; if (actionLog.ActionTypeId <= 25) { if (actionLog.ActionTypeId == 1) { status = "Not Responding"; statusCss = "label-danger"; } else if (actionLog.ActionTypeId == 2) { status = "Responding"; statusCss = "label-success"; if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } } else if (actionLog.ActionTypeId == 0) { status = "Standing By"; statusCss = "label-default"; } else if (actionLog.ActionTypeId == 3) { status = "On Scene"; statusCss = "label-inverse"; } else if (actionLog.ActionTypeId == 4) { if (respondingToDepartment == null) { status = "Available Station"; } else { status = string.Format("Available at {0}", respondingToDepartment.Name); } statusCss = "label-default"; } else if (actionLog.ActionTypeId == 5) { statusCss = "label-success"; if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } if (respondingToDepartment == null) { status = "Responding to Station"; } else { status = string.Format("Responding to {0}", respondingToDepartment.Name); } } else if (actionLog.ActionTypeId == 6) { statusCss = "label-success"; if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } if (!actionLog.DestinationId.HasValue) { status = "Responding to Call"; } else { if (!String.IsNullOrWhiteSpace(callNumber)) { status = string.Format("Responding to Call {0}", callNumber); } else { status = string.Format("Responding to Call {0}", actionLog.DestinationId); } } } } else { var customStatus = CustomStatesHelper.GetCustomState(department.DepartmentId, actionLog.ActionTypeId); if (customStatus != null) { status = customStatus.ButtonText; statusCss = "label-default"; statusStyle = string.Format("color:{0};background-color:{1};", customStatus.TextColor, customStatus.ButtonColor); if (!String.IsNullOrWhiteSpace(actionLog.GeoLocationData)) { var cords = actionLog.GetCoordinates(); latitude = cords.Latitude; longitude = cords.Longitude; } } else { status = "Unknown"; statusCss = "label-default"; } } } string groupName = ""; int groupId = 0; if (group != null) { groupName = group.Name; groupId = group.DepartmentGroupId; } var newRoles = new StringBuilder(); foreach (var role in roles) { if (newRoles.Length > 0) { newRoles.Append(", " + role.Name); } else { newRoles.Append(role.Name); } } return(new PersonnelViewModel { Name = name, Status = status, StatusCss = statusCss, State = state, StateCss = stateCss, UpdatedDate = updateDate, Group = groupName, Roles = newRoles.ToString(), GroupId = groupId, StateStyle = stateStyle, StatusStyle = statusStyle, Latitude = latitude, Longitude = longitude, StatusValue = statusValue, Eta = eta, DestinationType = destinationType }); }
public async Task <ActionResult <List <UnitViewModel> > > GetUnitStatuses() { var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId); var unitStates = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(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 = await 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 IActionResult GetUnitsForCallGrid(string callLat, string callLong) { 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); if (String.IsNullOrWhiteSpace(callLat) || String.IsNullOrWhiteSpace(callLong)) { unitJson.Eta = "N/A"; } else { var location = _unitsService.GetLatestUnitLocation(state.UnitId, state.Timestamp); if (location != null) { var eta = _geoService.GetEtaInSeconds($"{location.Latitude},{location.Longitude}", String.Format("{0},{1}", callLat, callLong)); if (eta > 0) { unitJson.Eta = $"{Math.Round(eta / 60, MidpointRounding.AwayFromZero)}m"; } else { unitJson.Eta = "N/A"; } } else if (!String.IsNullOrWhiteSpace(state.GeoLocationData)) { var eta = _geoService.GetEtaInSeconds(state.GeoLocationData, String.Format("{0},{1}", callLat, callLong)); if (eta > 0) { unitJson.Eta = $"{Math.Round(eta / 60, MidpointRounding.AwayFromZero)}m"; } else { unitJson.Eta = "N/A"; } } else { unitJson.Eta = "N/A"; } } } unitsJson.Add(unitJson); } return(Json(unitsJson)); }
public async Task <ActionResult <List <PersonnelForCallResult> > > GetPersonnelForCallGrid() { var result = new List <PersonnelForCallResult>(); var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId); //.GetAllUsersForDepartmentUnlimitedMinusDisabled(DepartmentId); var personnelNames = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(DepartmentId); var lastUserActionlogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId); var userStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId); var personnelSortOrder = await _departmentSettingsService.GetDepartmentPersonnelSortOrderAsync(DepartmentId); var personnelStatusSortOrder = await _departmentSettingsService.GetDepartmentPersonnelListStatusSortOrderAsync(DepartmentId); foreach (var user in users) { PersonnelForCallResult person = new PersonnelForCallResult(); person.UserId = user.UserId; person.Name = await UserHelper.GetFullNameForUser(personnelNames, user.UserName, user.UserId); var group = await _departmentGroupsService.GetGroupForUserAsync(user.UserId, DepartmentId); if (group != null) { person.Group = group.Name; } var roles = await _personnelRolesService.GetRolesForUserAsync(user.UserId, DepartmentId); person.Roles = new List <string>(); foreach (var role in roles) { person.Roles.Add(role.Name); } var currentStaffing = userStates.FirstOrDefault(x => x.UserId == user.UserId); if (currentStaffing != null) { var staffing = await CustomStatesHelper.GetCustomPersonnelStaffing(DepartmentId, currentStaffing); if (staffing != null) { person.Staffing = staffing.ButtonText; person.StaffingColor = staffing.ButtonClassToColor(); } } else { person.Staffing = "Available"; person.StaffingColor = "#000"; } var currentStatus = lastUserActionlogs.FirstOrDefault(x => x.UserId == user.UserId); if (currentStatus != null) { var status = await CustomStatesHelper.GetCustomPersonnelStatus(DepartmentId, currentStatus); if (status != null) { person.Status = status.ButtonText; person.StatusColor = status.ButtonClassToColor(); } } else { person.Status = "Standing By"; person.StatusColor = "#000"; } person.Eta = "N/A"; if (currentStatus != null) { if (personnelStatusSortOrder != null && personnelStatusSortOrder.Any()) { var statusSorting = personnelStatusSortOrder.FirstOrDefault(x => x.StatusId == currentStatus.ActionTypeId); if (statusSorting != null) { person.Weight = statusSorting.Weight; } else { person.Weight = 9000; } } else { person.Weight = 9000; } } else { person.Weight = 9000; } result.Add(person); } switch (personnelSortOrder) { case PersonnelSortOrders.Default: result = result.OrderBy(x => x.Weight).ToList(); break; case PersonnelSortOrders.FirstName: result = result.OrderBy(x => x.Weight).ThenBy(x => x.FirstName).ToList(); break; case PersonnelSortOrders.LastName: result = result.OrderBy(x => x.Weight).ThenBy(x => x.LastName).ToList(); break; case PersonnelSortOrders.Group: result = result.OrderBy(x => x.Weight).ThenBy(x => x.GroupId).ToList(); break; default: result = result.OrderBy(x => x.Weight).ToList(); break; } return(Ok(result)); }