public async Task <IActionResult> GetInventoryList() { List <InventoryJson> inventoryJson = new List <InventoryJson>(); var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId); var items = await _inventoryService.GetAllTransactionsForDepartmentAsync(DepartmentId); var names = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(DepartmentId); //var groups = await _departmentGroupsService.GetAllGroupsForDepartment(DepartmentId); foreach (var item in items) { var inventory = new InventoryJson(); inventory.InventoryId = item.InventoryId; inventory.Type = item.Type.Type; inventory.Amount = item.Amount; inventory.Batch = item.Batch; inventory.Timestamp = item.TimeStamp.FormatForDepartment(department); if (item.Unit != null) { inventory.Unit = item.Unit.Name; } else { inventory.Unit = "No Unit"; } if (item.Group != null) { inventory.Group = item.Group.Name; } else { inventory.Group = "No Group"; } var name = names.FirstOrDefault(x => x.UserId == item.AddedByUserId); if (name != null) { inventory.UserName = name.Name; } else { inventory.UserName = "******"; } inventoryJson.Add(inventory); } return(Json(inventoryJson)); }
public async Task <ActionResult <List <UnitDetailResult> > > GetUnitDetail() { List <UnitDetailResult> result = new List <UnitDetailResult>(); var units = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId); var names = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(DepartmentId); foreach (var unit in units) { var unitResult = new UnitDetailResult(); unitResult.Roles = new List <UnitDetailRoleResult>(); unitResult.Id = unit.UnitId; unitResult.Name = unit.Unit.Name; unitResult.Type = unit.Unit.Type; unitResult.GroupId = unit.Unit.StationGroupId.GetValueOrDefault(); unitResult.VIN = unit.Unit.VIN; unitResult.PlateNumber = unit.Unit.PlateNumber; unitResult.Offroad = unit.Unit.FourWheel.GetValueOrDefault(); unitResult.SpecialPermit = unit.Unit.SpecialPermit.GetValueOrDefault(); unitResult.StatusId = unit.UnitStateId; if (unit.Roles != null && unit.Roles.Count() > 0) { foreach (var role in unit.Roles) { var roleResult = new UnitDetailRoleResult(); roleResult.RoleName = role.Role; roleResult.RoleId = role.UnitStateRoleId; roleResult.UserId = role.UserId; var name = names.FirstOrDefault(x => x.UserId == role.UserId); if (name != null) { roleResult.Name = name.Name; } else { roleResult.Name = "Unknown"; } unitResult.Roles.Add(roleResult); } } result.Add(unitResult); } return(Ok(result)); }
public async Task <IActionResult> GetMapData(MapSettingsInput input) { MapDataJson dataJson = new MapDataJson(); var calls = await _callsService.GetActiveCallsByDepartmentAsync(DepartmentId); var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false); var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(DepartmentId); var lastUserActionlogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId); var personnelNames = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(DepartmentId); var unitStates = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId); var userLocationPermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CanSeePersonnelLocations); if (userLocationPermission != null) { var userGroup = await _departmentGroupsService.GetGroupForUserAsync(UserId, DepartmentId); int?groupId = null; if (userGroup != null) { groupId = userGroup.DepartmentGroupId; } var roles = await _personnelRolesService.GetRolesForUserAsync(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) { try { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Station"; info.Title = station.Name; info.InfoWindowContent = station.Name; if (station.Address != null) { string coordinates = await _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); } } catch (Exception ex) { //Logging.LogException(ex); } } } 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 = await _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 = await _mappingService.GetPOITypesForDepartmentAsync(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 async Task <ActionResult <List <PersonnelViewModel> > > GetPersonnelStatuses() { var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false); var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(DepartmentId); var calls = await _callsService.GetActiveCallsByDepartmentAsync(DepartmentId); var allUsers = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId); var hideUnavailable = await _departmentSettingsService.GetBigBoardHideUnavailableDepartmentAsync(DepartmentId); //var lastUserActionlogs = await _actionLogsService.GetAllActionLogsForDepartmentAsync(DepartmentId); var lastUserActionlogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId); var departmentGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId); var lastUserStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId); var personnelNames = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(DepartmentId); var names = new Dictionary <string, string>(); var userStates = new List <UserState>(); foreach (var u in allUsers) { var state = lastUserStates.FirstOrDefault(x => x.UserId == u.UserId); if (state != null) { userStates.Add(state); } else { userStates.Add(await _userStateService.GetLastUserStateByUserIdAsync(u.UserId)); } var name = personnelNames.FirstOrDefault(x => x.UserId == u.UserId); if (name != null) { names.Add(u.UserId, name.Name); } } var personnelViewModels = new List <PersonnelViewModel>(); var sortedUngroupedUsers = from u in allUsers // let mu = Membership.GetUser(u.UserId) let userGroup = departmentGroups.FirstOrDefault(x => x.Members.Any(y => y.UserId == u.UserId)) let groupName = userGroup == null ? "" : userGroup.Name //let roles = _personnelRolesService.GetRolesForUserAsync(u.UserId, DepartmentId).Result //let name = (ProfileBase.Create(mu.UserName, true)).GetPropertyValue("Name").ToString() let name = names.ContainsKey(u.UserId) ? names[u.UserId] : "Unknown User" let weight = lastUserActionlogs.Where(x => x.UserId == u.UserId).FirstOrDefault().GetWeightForAction() orderby groupName, weight, name ascending select new { Name = name, User = u, Group = userGroup, Roles = new List <PersonnelRole>() }; foreach (var u in sortedUngroupedUsers) { //var mu = Membership.GetUser(u.User.UserId); var al = lastUserActionlogs.Where(x => x.UserId == u.User.UserId).FirstOrDefault(); var us = userStates.Where(x => x.UserId == u.User.UserId).FirstOrDefault(); // if setting is such, ignore unavailable users. if (hideUnavailable.HasValue && hideUnavailable.Value && us.State != (int)UserStateTypes.Unavailable) { continue; } u.Roles.AddRange(await _personnelRolesService.GetRolesForUserAsync(u.User.UserId, DepartmentId)); string callNumber = ""; if (al != null && al.ActionTypeId == (int)ActionTypes.RespondingToScene || (al != null && al.DestinationType.HasValue && al.DestinationType.Value == 2)) { if (al.DestinationId.HasValue) { var call = calls.FirstOrDefault(x => x.CallId == al.DestinationId.Value); if (call != null) { callNumber = call.Number; } } } var respondingToDepartment = stations.Where(s => al != null && s.DepartmentGroupId == al.DestinationId).FirstOrDefault(); var personnelViewModel = await PersonnelViewModel.Create(u.Name, al, us, department, respondingToDepartment, u.Group, u.Roles, callNumber); personnelViewModels.Add(personnelViewModel); } return(personnelViewModels); }
public async Task <IActionResult> Settings() { var model = new OrderSetttingsView(); var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId); var settings = await _resourceOrdersService.GetSettingsByDepartmentIdAsync(DepartmentId); if (settings != null) { model.Settings = settings; } else { model.Settings = new ResourceOrderSetting(); model.Settings.DefaultResourceOrderManagerUserId = department.ManagingUserId; model.Settings.Range = 500; } model.OrderVisibilities = model.Visibility.ToSelectListInt(); var staffingLevels = await _customStateService.GetActiveStaffingLevelsForDepartmentAsync(DepartmentId); if (staffingLevels == null) { model.StaffingLevels = model.UserStateTypes.ToSelectListInt(); } else { model.StaffingLevels = new SelectList(staffingLevels.GetActiveDetails(), "CustomStateDetailId", "ButtonText"); } model.SetUsers(await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId, false, true), await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(DepartmentId)); ViewBag.Users = new SelectList(model.Users, "Key", "Value"); return(View(model)); }
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)); }
public async Task <IActionResult> GetPersonnelList(int linkId) { var link = await _departmentLinksService.GetLinkByIdAsync(linkId); if (link.DepartmentId != DepartmentId && link.LinkedDepartmentId != DepartmentId) { Unauthorized(); } var department = await _departmentsService.GetDepartmentByIdAsync(link.DepartmentId); var allUsers = await _departmentsService.GetAllUsersForDepartmentAsync(link.DepartmentId); var lastUserActionlogs = await _actionLogsService.GetAllActionLogsForDepartmentAsync(link.DepartmentId); var departmentGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(link.DepartmentId); var lastUserStates = await _userStateService.GetLatestStatesForDepartmentAsync(link.DepartmentId); var personnelNames = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(link.DepartmentId); var calls = await _callsService.GetActiveCallsByDepartmentAsync(link.DepartmentId); var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(link.DepartmentId); var names = new Dictionary <string, string>(); var userStates = new List <UserState>(); foreach (var u in allUsers) { var state = lastUserStates.FirstOrDefault(x => x.UserId == u.UserId); if (state != null) { userStates.Add(state); } else { userStates.Add(await _userStateService.GetLastUserStateByUserIdAsync(u.UserId)); } var name = personnelNames.FirstOrDefault(x => x.UserId == u.UserId); if (name != null) { names.Add(u.UserId, name.Name); } else { names.Add(u.UserId, await UserHelper.GetFullNameForUser(u.UserId)); } } var personnelViewModels = new List <Models.BigBoardX.PersonnelViewModel>(); var sortedUngroupedUsers = from u in allUsers // let mu = Membership.GetUser(u.UserId) //let userGroup = await _departmentGroupsService.GetGroupForUserAsync(u.UserId, DepartmentId) //let groupName = userGroup == null ? "" : userGroup.Name //let roles = await _personnelRolesService.GetRolesForUserAsync(u.UserId, DepartmentId) //let name = (ProfileBase.Create(mu.UserName, true)).GetPropertyValue("Name").ToString() let name = names[u.UserId] let weight = lastUserActionlogs.Where(x => x.UserId == u.UserId).FirstOrDefault().GetWeightForAction() orderby weight, name ascending select new { Name = name, User = u, //Group = userGroup, Roles = new List <PersonnelRole>() }; foreach (var u in sortedUngroupedUsers) { //var mu = Membership.GetUser(u.User.UserId); var al = lastUserActionlogs.Where(x => x.UserId == u.User.UserId).FirstOrDefault(); var us = userStates.Where(x => x.UserId == u.User.UserId).FirstOrDefault(); u.Roles.AddRange(await _personnelRolesService.GetRolesForUserAsync(u.User.UserId, DepartmentId)); var group = await _departmentGroupsService.GetGroupForUserAsync(u.User.UserId, DepartmentId); string callNumber = ""; if (al != null && al.ActionTypeId == (int)ActionTypes.RespondingToScene || (al != null && al.DestinationType.HasValue && al.DestinationType.Value == 2)) { if (al.DestinationId.HasValue) { var call = calls.FirstOrDefault(x => x.CallId == al.DestinationId.Value); if (call != null) { callNumber = call.Number; } } } var respondingToDepartment = stations.Where(s => al != null && s.DepartmentGroupId == al.DestinationId).FirstOrDefault(); var personnelViewModel = await Models.BigBoardX.PersonnelViewModel.Create(u.Name, al, us, department, respondingToDepartment, group, u.Roles, callNumber); personnelViewModels.Add(personnelViewModel); } return(Json(personnelViewModels)); }