コード例 #1
0
ファイル: OAuthClientService.cs プロジェクト: lsrob123/Lx.Sys
        private GetTokensResponse CreateTokenResponse(IBasicRequestKey request, TokenResponse result,
                                                      string redirectUriOnSuccess, string redirectUriOnFailure)
        {
            var response = _mappingService.Map <GetTokensResponse>(result).LinkTo(request);

            var exceptions = new List <Exception>();

            if (!string.IsNullOrWhiteSpace(result.Error))
            {
                exceptions.Add(new Exception($"{result.ErrorType} - {result.Error} - {result.ErrorDescription}"));
            }
            if (result.Exception != null)
            {
                exceptions.Add(result.Exception);
            }
            if (!string.IsNullOrWhiteSpace(result.HttpErrorReason))
            {
                exceptions.Add(new HttpException((int)result.HttpStatusCode, result.HttpErrorReason));
            }

            if (exceptions.Any())
            {
                response.WithProcessResult(exceptions);
                response.RedirectUri = redirectUriOnFailure;
            }
            else
            {
                response.WithProcessResult(ProcessResultType.Ok);
                response.RedirectUri = redirectUriOnSuccess;
            }

            return(response);
        }
コード例 #2
0
 public CreateVerificationCodeResponse LinkTo(IBasicRequestKey request,
                                              VerificationPurpose verificationPurpose)
 {
     this.LinkTo(request);
     VerificationPurpose = verificationPurpose;
     return(this);
 }
コード例 #3
0
ファイル: CompletionState.cs プロジェクト: lsrob123/Lx.Sys
        public CompletionState(IBasicRequestKey request, string progressMessage = null)
        {
            if (request != null)
            {
                this.LinkTo(request);
            }

            SetProgressMessage(progressMessage);
        }
コード例 #4
0
        public MemberUpdatedEvent CreateOrUpdateMember(IBasicRequestKey request, MemberUpdateDto dto,
                                                       Func <MemberUpdateDto, UserProfileDto> createUserProfileDto)
        {
            var member = MappingService.Map <Member>(dto).AsNewEntity();

            if (dto.Roles == null)
            {
                dto.Roles = new List <RoleDto>();
            }
            if (!dto.Roles.Any())
            {
                dto.Roles.Add(new RoleDto {
                    RoleType = RoleTypeName.BasicMember
                });
            }
            foreach (var roleDto in dto.Roles)
            {
                roleDto.UserKey = member.Key;
            }

            var roles = dto.Roles.Select(x => MappingService.Map <Role>(x).AsNewEntity()).ToList();

            var updatedEvent = new MemberUpdatedEvent().LinkTo(request);

            updatedEvent.WithProcessResult(ExecuteWithProcessResult(uow =>
            {
                var updatedMember = uow.Store.AddOrUpdate(member,
                                                          x => x.Email.Address == member.Email.Address ||
                                                          x.Mobile.LocalNumberWithAreaCodeInDigits == member.Mobile.LocalNumberWithAreaCodeInDigits ||
                                                          x.Username == member.Username
                                                          );
                var updatedMemberDto   = MappingService.Map <MemberUpdateDto>(updatedMember);
                updatedMemberDto.Roles = new List <RoleDto>();
                uow.Store.Delete <Role>(x => x.UserKey == updatedMember.Key);
                foreach (var role in roles)
                {
                    var updatedRole = uow.Store.Add(role);
                    updatedMemberDto.Roles.Add(MappingService.Map <RoleDto>(updatedRole));
                }
                updatedEvent.WithMember(updatedMemberDto)
                .WithUserProfile(createUserProfileDto?.Invoke(updatedMemberDto));
            }));
            return(updatedEvent);
        }
コード例 #5
0
        /// <summary>
        ///     Link to another request/response object with same OriginatorGroup, RequestReference
        ///     and possibly Sid (saga ID)
        /// </summary>
        /// <typeparam name="TRequestKey"></typeparam>
        /// <param name="basicRequestKey"></param>
        /// <param name="other"></param>
        /// <param name="alternativeGroup"></param>
        /// <returns></returns>
        public static TRequestKey LinkTo <TRequestKey>(this TRequestKey basicRequestKey, IBasicRequestKey other,
                                                       string alternativeGroup = null)
            where TRequestKey : IBasicRequestKey
        {
            if (other == null)
            {
                return(basicRequestKey);
            }

            basicRequestKey.OriginatorGroup = string.IsNullOrWhiteSpace(alternativeGroup)
                ? other.OriginatorGroup
                : alternativeGroup.Trim();
            basicRequestKey.RequestReference     = other.RequestReference;
            basicRequestKey.OriginatorConnection = other.OriginatorConnection;

            var requestKey = basicRequestKey as IRequestKey;

            if (requestKey != null)
            {
                var otherAsRequestKey = other as IRequestKey;
                if (otherAsRequestKey != null)
                {
                    requestKey.ServiceReferences = otherAsRequestKey.ServiceReferences;
                }
            }

            var withSagaId = basicRequestKey as IHasSagaId;

            if (withSagaId == null)
            {
                return(basicRequestKey);
            }

            var otherWithSagaId = other as IHasSagaId;

            if (otherWithSagaId != null)
            {
                withSagaId.Sid = otherWithSagaId.Sid;
            }

            return(basicRequestKey);
        }
コード例 #6
0
 public CreateVerificationCodeResponse CreateVerificationCode(Guid userKey, IBasicRequestKey request,
                                                              VerificationPurpose verificationPurpose)
 {
     throw new NotImplementedException();
 }