public override Response Handle(GetAvailableRolesRequest request)
        {
            var response      = CreateTypedResponse();
            var staff         = _staffRepository.GetByKey(request.Key);
            var systemAccount = _systemAccountRepository.GetByStaffKey(staff.Key);
            var allRoles      = Session.QueryOver <Role> ()
                                .Where(r => r.RoleType != RoleType.Internal)
                                .JoinQueryOver(r => r.Organization)
                                .Where(o => o.Key == UserContext.OrganizationKey)
                                .List();

            if (systemAccount == null || systemAccount.Roles == null || !systemAccount.Roles.Any())
            {
                response.Roles = Mapper.Map <IEnumerable <Role>, IEnumerable <RoleDto> > (allRoles);
            }
            else
            {
                var currentRoles   = systemAccount.Roles.Select(sar => sar.Role);
                var availableRoles = allRoles.Except(currentRoles, new RoleComparer());
                response.Roles = Mapper.Map <IEnumerable <Role>, IEnumerable <RoleDto> > (availableRoles);
            }
            if (response.Roles == null)
            {
                response.Roles = Enumerable.Empty <RoleDto> ();
            }
            return(response);
        }
Beispiel #2
0
        /// <summary>
        ///     Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void Handle(GetStaffDtoByKeyRequest request, GetStaffDtoResponse response)
        {
            var staff    = _staffRepository.GetByKey(request.Key);
            var staffDto = Mapper.Map <Staff, StaffDto> (staff);

            var systemAccount = _systemAccountRepository.GetByStaffKey(staff.Key);

            if (systemAccount != null)
            {
                var systemAccountDto = Mapper.Map <SystemAccount, SystemAccountDto> (systemAccount);

                staffDto.SystemAccount = systemAccountDto;
            }
            response.DataTransferObject = staffDto;
        }