Beispiel #1
0
        public async Task <Dictionary <int, Dictionary <int, int> > > GetShiftDayNeedsObjAsync(Shift shift, ShiftDay shiftDay)
        {
            //var shiftDay = await _shiftDaysRepository.GetShiftDayByIdAsync(shiftDayId);
            var shiftGroups = new Dictionary <int, Dictionary <int, int> >();

            if (shiftDay != null)
            {
                if (shiftDay.Shift.AssignmentType == (int)ShiftAssignmentTypes.Assigned)
                {
                    return(null);
                }

                //shiftDay.Shift.Groups = (await _shiftGroupsRepository.GetShiftGroupsByShiftIdAsync(shiftDay.ShiftId)).ToList();
                if (shiftDay.Shift.Groups == null || shiftDay.Shift.Groups.Count() <= 0)
                {
                    return(null);
                }

                var shiftSignups =
                    (await _shiftSignupRepository.GetAllShiftSignupsByShiftIdAndDateAsync(shiftDay.ShiftId,
                                                                                          shiftDay.Day)).ToList();


                foreach (var group in shiftDay.Shift.Groups)
                {
                    var roleRequirements = new Dictionary <int, int>();

                    if (group.Roles != null && group.Roles.Any())
                    {
                        foreach (var role in group.Roles)
                        {
                            roleRequirements.Add(role.PersonnelRoleId, role.Required);
                        }
                    }

                    if (shiftSignups != null && shiftSignups.Any())
                    {
                        var groupSignups = shiftSignups.Where(x => x.DepartmentGroupId == group.DepartmentGroupId);

                        foreach (var signup in groupSignups)
                        {
                            var roles = await _personnelRolesService.GetRolesForUserAsync(signup.UserId, shiftDay.Shift.DepartmentId);

                            foreach (var personnelRole in roles)
                            {
                                if (roleRequirements.ContainsKey(personnelRole.PersonnelRoleId))
                                {
                                    roleRequirements[personnelRole.PersonnelRoleId]--;
                                }
                            }
                        }
                    }

                    shiftGroups.Add(group.DepartmentGroupId, roleRequirements);
                }
            }

            return(shiftGroups);
        }
Beispiel #2
0
        public async Task <bool> CanUserCreateCallAsync(string userId, int departmentId)
        {
            var permission = await _permissionsService.GetPermissionByDepartmentTypeAsync(departmentId, PermissionTypes.CreateCall);

            bool isGroupAdmin = false;
            var  group        = await _departmentGroupsService.GetGroupForUserAsync(userId, departmentId);

            var roles = await _personnelRolesService.GetRolesForUserAsync(userId, departmentId);

            var department = await _departmentsService.GetDepartmentByIdAsync(departmentId);

            if (group != null)
            {
                isGroupAdmin = group.IsUserGroupAdmin(userId);
            }

            return(_permissionsService.IsUserAllowed(permission, department.IsUserAnAdmin(userId), isGroupAdmin, roles));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
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);
        }
Beispiel #5
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));
        }
        public override async Task <ClaimsPrincipal> CreateAsync(TUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var userId = await UserManager.GetUserIdAsync(user);

            var userName = await UserManager.GetUserNameAsync(user);

            var profile = await _userProfileService.GetProfileByUserIdAsync(userId);

            var id = new ClaimsIdentity(
                CookieAuthenticationDefaults.AuthenticationScheme,
                Options.ClaimsIdentity.UserNameClaimType,
                Options.ClaimsIdentity.RoleClaimType
                );

            id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
            id.AddClaim(new Claim(Options.ClaimsIdentity.UserNameClaimType, userName));

            if (UserManager.SupportsUserSecurityStamp)
            {
                id.AddClaim(new Claim(Options.ClaimsIdentity.SecurityStampClaimType,
                                      await UserManager.GetSecurityStampAsync(user)));
            }

            if (UserManager.SupportsUserRole)
            {
                var roles = await _claimsRepository.GetRolesAsync(user);

                foreach (var roleName in roles)
                {
                    id.AddClaim(new Claim(Options.ClaimsIdentity.RoleClaimType, roleName));
                }
            }

            ClaimsPrincipal principal = new ClaimsPrincipal(id);

            if (principal.Identity is ClaimsIdentity)
            {
                ClaimsIdentity identity = (ClaimsIdentity)principal.Identity;

                if (profile != null)
                {
                    Claim displayNameClaim = new Claim("DisplayName", profile.FullName.AsFirstNameLastName);
                    if (!identity.HasClaim(displayNameClaim.Type, displayNameClaim.Value))
                    {
                        identity.AddClaim(displayNameClaim);
                    }
                }

                Claim emailClaim = new Claim(ClaimTypes.Email, user.Email);
                if (!identity.HasClaim(emailClaim.Type, emailClaim.Value))
                {
                    identity.AddClaim(emailClaim);
                }

                if (_usersService.IsUserInRole(user.Id, _usersService.AdminRoleId))
                {
                    ClaimsLogic.AddSystemAdminClaims(id, userName, user.Id, "System Admin");
                }
                else if (_usersService.IsUserInRole(user.Id, _usersService.AffiliateRoleId))
                {
                    ClaimsLogic.AddAffiliteClaims(id, userName,
                                                  user.Id, profile.FullName.AsFirstNameLastName);
                }
                else
                {
                    var department = await _departmentsService.GetDepartmentForUserAsync(userName);

                    if (department == null)
                    {
                        return(null);
                    }

                    var group = await _departmentGroupsService.GetGroupForUserAsync(user.Id, department.DepartmentId);

                    var departmentAdmin = department.IsUserAnAdmin(user.Id);
                    var permissions     = await _permissionsService.GetAllPermissionsForDepartmentAsync(department.DepartmentId);

                    var roles = await _personnelRolesService.GetRolesForUserAsync(user.Id, department.DepartmentId);

                    ClaimsLogic.AddDepartmentClaim(id, department.DepartmentId,
                                                   departmentAdmin);
                    //ClaimsLogic.DepartmentName = department.Name;

                    DateTime signupDate;
                    if (department.CreatedOn.HasValue)
                    {
                        signupDate = department.CreatedOn.Value;
                    }
                    else
                    {
                        signupDate = DateTime.UtcNow;
                    }

                    //ClaimsLogic.DepartmentId = department.DepartmentId;

                    var name = user.UserName;
                    if (profile != null && !String.IsNullOrWhiteSpace(profile.LastName))
                    {
                        name = profile.FullName.AsFirstNameLastName;
                    }

                    ClaimsLogic.AddGeneralClaims(id, userName,
                                                 user.Id, name, department.DepartmentId, department.Name, user.Email,
                                                 signupDate);

                    bool isGroupAdmin = false;

                    if (group != null)
                    {
                        isGroupAdmin = group.IsUserGroupAdmin(user.Id);
                    }

                    if (departmentAdmin)
                    {
                        var groups = await _departmentGroupsService.GetAllGroupsForDepartmentAsync(department.DepartmentId);

                        if (groups != null)
                        {
                            foreach (var departmentGroup in groups)
                            {
                                ClaimsLogic.AddGroupClaim(id, departmentGroup.DepartmentGroupId, true);
                            }
                        }
                    }
                    else
                    {
                        if (group != null)
                        {
                            ClaimsLogic.AddGroupClaim(id, group.DepartmentGroupId, isGroupAdmin);
                        }
                    }

                    ClaimsLogic.AddCallClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddActionClaims(id);
                    ClaimsLogic.AddLogClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddStaffingClaims(id);
                    ClaimsLogic.AddPersonnelClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddUnitClaims(id, departmentAdmin);
                    ClaimsLogic.AddUnitLogClaims(id);
                    ClaimsLogic.AddMessageClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddRoleClaims(id, departmentAdmin);
                    ClaimsLogic.AddProfileClaims(id);
                    ClaimsLogic.AddReportsClaims(id);
                    ClaimsLogic.AddGenericGroupClaims(id, departmentAdmin);
                    ClaimsLogic.AddDocumentsClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddNotesClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddScheduleClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddShiftClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddTrainingClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddPIIClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddInventoryClaims(id, departmentAdmin, permissions, isGroupAdmin, roles);
                    ClaimsLogic.AddConnectClaims(id, departmentAdmin);
                    ClaimsLogic.AddCommandClaims(id, departmentAdmin);
                    ClaimsLogic.AddProtocolClaims(id, departmentAdmin);
                }
            }

            return(principal);
        }
Beispiel #7
0
        public async Task <ActionResult <PersonnelInfoResult> > GetPersonnelInfo(string userId)
        {
            var result = new PersonnelInfoResult();
            var user   = _usersService.GetUserById(userId);


            if (user == null)
            {
                return(NotFound());
            }

            var department = await _departmentsService.GetDepartmentByUserIdAsync(user.UserId);

            if (department == null)
            {
                return(NotFound());
            }

            if (department.DepartmentId != DepartmentId)
            {
                return(Unauthorized());
            }

            var profile = await _userProfileService.GetProfileByUserIdAsync(user.UserId);

            var group = await _departmentGroupsService.GetGroupForUserAsync(user.UserId, DepartmentId);

            var roles = await _personnelRolesService.GetRolesForUserAsync(user.UserId, DepartmentId);

            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 = department.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)
                {
                    result.Roles.Add(role.Name);
                }
            }

            var action = await _actionLogsService.GetLastActionLogForUserAsync(user.UserId, DepartmentId);

            var userState = await _userStateService.GetLastUserStateByUserIdAsync(user.UserId);

            result.Ats = (int)ActionTypes.StandingBy;
            result.Stf = userState.State;
            result.Stm = userState.Timestamp.TimeConverter(department);

            if (action == null)
            {
                result.Stm = DateTime.UtcNow.TimeConverter(department);
            }
            else
            {
                result.Ats = action.ActionTypeId;
                result.Atm = action.Timestamp.TimeConverter(department);

                if (action.DestinationId.HasValue)
                {
                    if (action.ActionTypeId == (int)ActionTypes.RespondingToScene)
                    {
                        result.Did = action.DestinationId.Value;
                    }
                    else if (action.ActionTypeId == (int)ActionTypes.RespondingToStation)
                    {
                        result.Did = action.DestinationId.Value;
                    }
                    else if (action.ActionTypeId == (int)ActionTypes.AvailableStation)
                    {
                        result.Did = action.DestinationId.Value;
                    }
                }
            }

            return(Ok(result));
        }
Beispiel #8
0
        public async Task <ActionResult <DepartmentRightsResult> > GetCurrentUsersRights()
        {
            var result     = new DepartmentRightsResult();
            var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false);

            var departmentMembership = await _departmentsService.GetDepartmentMemberAsync(UserId, DepartmentId, false);

            var roles = await _personnelRolesService.GetRolesForUserAsync(UserId, DepartmentId);

            if (departmentMembership == null)
            {
                return(Unauthorized());
            }

            if (departmentMembership.IsAdmin.HasValue)
            {
                result.Adm = departmentMembership.IsAdmin.Value;
            }

            if (department.ManagingUserId == UserId)
            {
                result.Adm = true;
            }

            bool isGroupAdmin = false;

            result.Grps = new List <GroupRight>();

            var group = await _departmentGroupsService.GetGroupForUserAsync(UserId, DepartmentId);

            if (group != null)
            {
                var groupRight = new GroupRight();
                groupRight.Gid = group.DepartmentGroupId;
                groupRight.Adm = group.IsUserGroupAdmin(UserId);

                if (groupRight.Adm)
                {
                    isGroupAdmin = true;
                }

                result.Grps.Add(groupRight);
            }

            var createCallPermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CreateCall);

            var viewPIIPermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.ViewPersonalInfo);

            var createNotePermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CreateNote);

            var createMessagePermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CreateMessage);

            result.VPii = _permissionsService.IsUserAllowed(viewPIIPermission, result.Adm, isGroupAdmin, roles);
            result.CCls = _permissionsService.IsUserAllowed(createCallPermission, result.Adm, isGroupAdmin, roles);
            result.ANot = _permissionsService.IsUserAllowed(createNotePermission, result.Adm, isGroupAdmin, roles);
            result.CMsg = _permissionsService.IsUserAllowed(createMessagePermission, result.Adm, isGroupAdmin, roles);

            if (!String.IsNullOrWhiteSpace(Config.FirebaseConfig.ResponderJsonFile) && !String.IsNullOrWhiteSpace(Config.FirebaseConfig.ResponderProjectEmail))
            {
                result.FirebaseApiToken = await _firebaseService.CreateTokenAsync(UserId, null);
            }

            return(result);
        }
Beispiel #9
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));
        }