Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> GetUserStatusTable()
        {
            var model = new UserStatusTableModel();

            model.Department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);

            model.LastUserActionlogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId);

            model.UserStates       = new List <UserState>();
            model.DepartmentGroups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(DepartmentId);

            model.Stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(DepartmentId);

            model.UsersGroup = await _departmentGroupsService.GetGroupForUserAsync(UserId, DepartmentId);

            model.States = await _customStateService.GetActivePersonnelStateForDepartmentAsync(DepartmentId);

            model.StaffingLevels = await _customStateService.GetActiveStaffingLevelsForDepartmentAsync(DepartmentId);

            var personnelSortOrder = await _departmentSettingsService.GetDepartmentPersonnelSortOrderAsync(DepartmentId);

            var personnelStatusSortOrder = await _departmentSettingsService.GetDepartmentPersonnelListStatusSortOrderAsync(DepartmentId);

            var userStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId);

            var allUsers = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, false, false, false);

            model.ExcludedUsers = await _departmentsService.GetAllDisabledOrHiddenUsersAsync(DepartmentId);

            List <string> groupedUserIds = new List <string>();

            foreach (var dg in model.DepartmentGroups)
            {
                UserStatusGroup group = new UserStatusGroup();
                group.Group = dg;

                var membersToProcess = from member in dg.Members
                                       where !(model.ExcludedUsers.Any(item2 => item2 == member.UserId))
                                       select member;

                foreach (var u in membersToProcess)
                {
                    if (allUsers.Any(x => x.UserId == u.UserId))
                    {
                        groupedUserIds.Add(u.UserId);
                        var userInfo = allUsers.FirstOrDefault(x => x.UserId == u.UserId);

                        UserState state = userStates.FirstOrDefault(x => x.UserId == u.UserId);

                        if (state == null)
                        {
                            state               = new UserState();
                            state.UserId        = u.UserId;
                            state.AutoGenerated = true;
                            state.Timestamp     = DateTime.UtcNow;
                            state.State         = (int)UserStateTypes.Available;
                        }

                        if (!model.DepartmentUserStates.ContainsKey(u.UserId))
                        {
                            model.DepartmentUserStates.Add(u.UserId, state);
                        }

                        var al = model.LastUserActionlogs.FirstOrDefault(x => x.UserId == u.UserId);

                        UserStatus userStatus = new UserStatus();
                        userStatus.UserInfo        = userInfo;
                        userStatus.CurrentStatus   = al;
                        userStatus.CurrentStaffing = state;

                        if (al != null)
                        {
                            if (personnelStatusSortOrder != null && personnelStatusSortOrder.Any())
                            {
                                var statusSorting = personnelStatusSortOrder.FirstOrDefault(x => x.StatusId == al.ActionTypeId);
                                if (statusSorting != null)
                                {
                                    userStatus.Weight = statusSorting.Weight;
                                }
                                else
                                {
                                    userStatus.Weight = 9000;
                                }
                            }
                            else
                            {
                                userStatus.Weight = 9000;
                            }
                        }
                        else
                        {
                            userStatus.Weight = 9000;
                        }

                        group.UserStatuses.Add(userStatus);
                    }
                }

                switch (personnelSortOrder)
                {
                case PersonnelSortOrders.Default:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ToList();
                    break;

                case PersonnelSortOrders.FirstName:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.FirstName).ToList();
                    break;

                case PersonnelSortOrders.LastName:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.LastName).ToList();
                    break;

                default:
                    group.UserStatuses = group.UserStatuses.OrderBy(x => x.Weight).ToList();
                    break;
                }

                model.UserStatusGroups.Add(group);

                var allGroupMembers = new List <DepartmentGroupMember>(dg.Members);
            }

            var ungroupedUsers = from u in allUsers
                                 where !(groupedUserIds.Contains(u.UserId)) && !(model.ExcludedUsers.Any(item2 => item2 == u.UserId))
                                 select u;

            UserStatusGroup unGroupedUsersGroup = new UserStatusGroup();

            unGroupedUsersGroup.Group = null;
            foreach (var u in ungroupedUsers)
            {
                model.UnGroupedUsers.Add(u.UserId);

                UserState state    = userStates.FirstOrDefault(x => x.UserId == u.UserId);
                var       userInfo = allUsers.FirstOrDefault(x => x.UserId == u.UserId);

                if (state == null)
                {
                    state               = new UserState();
                    state.UserId        = u.UserId;
                    state.AutoGenerated = true;
                    state.Timestamp     = DateTime.UtcNow;
                    state.State         = (int)UserStateTypes.Available;
                }

                var al = model.LastUserActionlogs.FirstOrDefault(x => x.UserId == u.UserId);

                UserStatus userStatus = new UserStatus();
                userStatus.UserInfo        = userInfo;
                userStatus.CurrentStatus   = al;
                userStatus.CurrentStaffing = state;

                if (al != null)
                {
                    if (personnelStatusSortOrder != null && personnelStatusSortOrder.Any())
                    {
                        var statusSorting = personnelStatusSortOrder.FirstOrDefault(x => x.StatusId == al.ActionTypeId);
                        if (statusSorting != null)
                        {
                            userStatus.Weight = statusSorting.Weight;
                        }
                        else
                        {
                            userStatus.Weight = 9000;
                        }
                    }
                    else
                    {
                        userStatus.Weight = 9000;
                    }
                }
                else
                {
                    userStatus.Weight = 9000;
                }

                unGroupedUsersGroup.UserStatuses.Add(userStatus);
            }

            switch (personnelSortOrder)
            {
            case PersonnelSortOrders.Default:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ToList();
                break;

            case PersonnelSortOrders.FirstName:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.FirstName).ToList();
                break;

            case PersonnelSortOrders.LastName:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ThenBy(x => x.UserInfo.LastName).ToList();
                break;

            default:
                unGroupedUsersGroup.UserStatuses = unGroupedUsersGroup.UserStatuses.OrderBy(x => x.Weight).ToList();
                break;
            }
            model.UserStatusGroups.Add(unGroupedUsersGroup);

            return(PartialView("_UserStatusTablePartial", model));
        }
Exemplo n.º 6
0
        public async Task <ActionResult <List <PersonnelStatusResult> > > GetPersonnelStatuses(string activeFilter)
        {
            var results = new List <PersonnelStatusResult>();

            string[] activeFilters = null;
            if (!String.IsNullOrWhiteSpace(activeFilter))
            {
                var filter = HttpUtility.UrlDecode(activeFilter);
                activeFilters = filter.Split(char.Parse("|"));
            }

            var filters = await GetFilterOptions();

            var actionLogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId);

            var userStates = await _userStateService.GetLatestStatesForDepartmentAsync(DepartmentId);

            //var users = await _departmentsService.GetAllUsersForDepartmentAsync(DepartmentId);

            var users = _usersService.GetUserGroupAndRolesByDepartmentId(DepartmentId, false, false, false);


            Department department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);

            //var allGroups = await _departmentGroupsService.GetAllDepartmentGroupsForDepartmentAsync(DepartmentId);
            //var allRoles = await _personnelRolesService.GetAllRolesForUsersInDepartmentAsync(DepartmentId);

            var personnelSortOrder = await _departmentSettingsService.GetDepartmentPersonnelSortOrderAsync(DepartmentId);

            var personnelStatusSortOrder = await _departmentSettingsService.GetDepartmentPersonnelListStatusSortOrderAsync(DepartmentId);

            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);
                }

                //DepartmentGroup userGroup = null;
                //if (allGroups.ContainsKey(u.UserId))
                //	userGroup = allGroups[u.UserId];

                //var roles = new List<PersonnelRole>();
                //if (allRoles.ContainsKey(u.UserId))
                //	roles = allRoles[u.UserId];

                if (u.DepartmentGroupId.HasValue)
                {
                    s.Gid = u.DepartmentGroupId.Value;
                }

                if (log != null)
                {
                    if (personnelStatusSortOrder != null && personnelStatusSortOrder.Any())
                    {
                        var statusSorting = personnelStatusSortOrder.FirstOrDefault(x => x.StatusId == log.ActionTypeId);
                        if (statusSorting != null)
                        {
                            s.Weight = statusSorting.Weight;
                        }
                        else
                        {
                            s.Weight = 9000;
                        }
                    }
                    else
                    {
                        s.Weight = 9000;
                    }
                }
                else
                {
                    s.Weight = 9000;
                }

                if (activeFilter != null && activeFilter.Any())
                {
                    foreach (var afilter in activeFilters)
                    {
                        var text = GetTextValue(afilter, filters);

                        if (afilter.Substring(0, 2) == "G:")
                        {
                            if (u.DepartmentGroupName != null && text == u.DepartmentGroupName)
                            {
                                results.Add(s);
                                break;
                            }
                        }
                        else if (afilter.Substring(0, 2) == "R:")
                        {
                            if (u.RoleNamesList.Any(x => x == text))
                            {
                                results.Add(s);
                                break;
                            }
                        }
                        else if (afilter.Substring(0, 2) == "U:")
                        {
                            if (s.Ste.ToString() == text || s.Ste.ToString() == text.Replace(" ", ""))
                            {
                                results.Add(s);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    results.Add(s);
                }
            }

            switch (personnelSortOrder)
            {
            case PersonnelSortOrders.Default:
                results = results.OrderBy(x => x.Weight).ToList();
                break;

            case PersonnelSortOrders.FirstName:
                results = results.OrderBy(x => x.Weight).ThenBy(x => users.First(y => y.UserId == x.Uid).FirstName).ToList();
                break;

            case PersonnelSortOrders.LastName:
                results = results.OrderBy(x => x.Weight).ThenBy(x => users.First(y => y.UserId == x.Uid).LastName).ToList();
                break;

            case PersonnelSortOrders.Group:
                results = results.OrderBy(x => x.Weight).ThenBy(x => x.Gid).ToList();
                break;

            default:
                results = results.OrderBy(x => x.Weight).ToList();
                break;
            }

            return(Ok(results));
        }
Exemplo n.º 7
0
        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));
        }