public async Task <ActionResult <List <PersonnelStatusResult> > > GetPersonnelStatusesForLink(int linkId) { var link = await _departmentLinksService.GetLinkByIdAsync(linkId); if (link.DepartmentId != DepartmentId && link.LinkedDepartmentId != DepartmentId) { return(new List <PersonnelStatusResult>()); } var results = new List <PersonnelStatusResult>(); var actionLogs = await _actionLogsService.GetAllActionLogsForDepartmentAsync(link.DepartmentId); var userStates = await _userStateService.GetLatestStatesForDepartmentAsync(link.DepartmentId); var users = await _departmentsService.GetAllUsersForDepartmentAsync(link.DepartmentId); Department department = await _departmentsService.GetDepartmentByIdAsync(link.DepartmentId, false); foreach (var u in users) { 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 PersonnelStatusResult(); s.Uid = u.UserId.ToString(); if (log != null) { s.Atp = log.ActionTypeId; s.Atm = log.Timestamp.TimeConverter(department); if (log.DestinationId.HasValue) { if (log.ActionTypeId == (int)ActionTypes.RespondingToScene) { s.Did = log.DestinationId.Value.ToString(); } else if (log.ActionTypeId == (int)ActionTypes.RespondingToStation) { s.Did = log.DestinationId.Value.ToString(); } else if (log.ActionTypeId == (int)ActionTypes.AvailableStation) { s.Did = log.DestinationId.Value.ToString(); } } } else { s.Atp = (int)ActionTypes.StandingBy; s.Atm = DateTime.UtcNow.TimeConverter(department); } if (state != null) { s.Ste = state.State; s.Stm = state.Timestamp.TimeConverter(department); } else { s.Ste = (int)UserStateTypes.Available; s.Stm = DateTime.UtcNow.TimeConverter(department); } results.Add(s); } return(Ok(results)); }
public async Task <ActionResult <List <StationResult> > > GetStationResources() { var result = new List <StationResult>(); var unitStatuses = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId); var actionLogs = await _actionLogsService.GetAllActionLogsForDepartmentAsync(DepartmentId); var userStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId); var stations = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId); var userGroups = await _departmentGroupsService.GetAllDepartmentGroupsForDepartmentAsync(DepartmentId); var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId); var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId); Department department = await _departmentsService.GetDepartmentByIdAsync(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(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)); }