Beispiel #1
0
        private void InitializeUserInformation( UserInformationDto userInformationDto )
        {
            lock ( _userPermissionsSync )
            {
                lock ( _currentUserContextSync )
                {
                    _userPermissions.Clear ();

                    foreach ( var grantedPermission in userInformationDto.GrantedPermissions )
                    {
                        var permission = new Permission { Name = grantedPermission };
                        _userPermissions.Add ( permission );
                    }

                    var agency = new AgencyContext (
                        userInformationDto.AgencyKey,
                        userInformationDto.AgencyDisplayName );
                    var location = new LocationContext (
                        userInformationDto.LocationKey,
                        userInformationDto.LocationDisplayName );
                    var staff = new StaffContext (
                        userInformationDto.StaffKey,
                        userInformationDto.StaffFirstName,
                        userInformationDto.StaffMiddleName,
                        userInformationDto.StaffLastName,
                        userInformationDto.DirectEmailAddress );
                    var account = new AccountContext (
                        userInformationDto.AccountKey,
                        userInformationDto.AccountIdentifier );
                    var currentUserContext = new CurrentUserContext (
                        agency,
                        location,
                        staff,
                        account );

                    CurrentUserContext = currentUserContext;
                }
            }
        }
        /// <summary>
        /// Creates the user information dto.
        /// </summary>
        /// <returns>A <see cref="UserInformationDto"/></returns>
        public UserInformationDto CreateUserInformationDto()
        {
            var claimsPrincipal = _currentClaimsPrincipalService.GetCurrentPrincipal ();
            var permissions = claimsPrincipal.CurrentPermissions ();
            var accountKey = claimsPrincipal.CurrentAccountKey ();
            var staffKey = claimsPrincipal.CurrentStaffKey ();

            UserInformationDto userInformationDto = null;

            var session = _sessionProvider.GetSession ();

            var account = session.Get<SystemAccount> ( accountKey );
            var staff = account.StaffMembers.First ( x => x.Key == staffKey );
            var agency = staff.Agency;
            var location = staff.PrimaryLocation;

            userInformationDto = new UserInformationDto
                {
                    AccountKey = account.Key,
                    AccountIdentifier = account.Identifier,
                    AgencyKey = agency.Key,
                    AgencyDisplayName = agency.AgencyProfile.AgencyName.DisplayName,
                    LocationKey = location == null ? 0 : location.Key,
                    LocationDisplayName = location == null ? string.Empty : location.LocationProfile.LocationName.DisplayName,
                    StaffKey = staff.Key,
                    StaffFirstName = staff.StaffProfile.StaffName.First,
                    StaffMiddleName = staff.StaffProfile.StaffName.Middle,
                    StaffLastName = staff.StaffProfile.StaffName.Last,
                    DirectEmailAddress = staff.DirectAddressCredential == null ? null : (staff.DirectAddressCredential.DirectAddress == null? null : staff.DirectAddressCredential.DirectAddress.Address),
                    GrantedPermissions = permissions
                };

            return userInformationDto;
        }