public async Task <JwtAdto> GoogleAsync(ClientCredentialAdto clientCredentialAdto) { using (ITransaction transaction = _transactionManager.Create()) { try { AuthenticationGrantTypeGoogle authenticationGrantTypeGoogle = (AuthenticationGrantTypeGoogle)await _authenticationServiceCommandRepository.GetSingleAsync( s => s is AuthenticationGrantTypeGoogle && s.Id == clientCredentialAdto.Id); if (authenticationGrantTypeGoogle == null) { throw new BusinessApplicationException(ExceptionType.BadRequest, ErrorCodes.ClientCredentialLoginNotConfigured, "Client credential login not configured"); } IClientCredentialAuthenticationResult clientCredentialAuthenticationResult = await _googleAuthenticationValidator.Validate(authenticationGrantTypeGoogle, new ValidateClientCredentialAdto { Token = clientCredentialAdto.Token, RedirectUri = clientCredentialAdto.RedirectUri }); if (!clientCredentialAuthenticationResult.Success) { throw new BusinessApplicationException(ExceptionType.Unauthorized, "Could not validate access token"); } Identity identity = await _getIdentityByClientCredentialIdentifierQuery.RunAsync(authenticationGrantTypeGoogle, clientCredentialAuthenticationResult.Identifier); if (identity == null) { identity = await _createIdentityCommand.ExecuteAsync(); await _registerClientCredentialCommand.ExecuteAsync(identity, authenticationGrantTypeGoogle, new RegisterClientCredentialCommandDdto { Identifier = clientCredentialAuthenticationResult.Identifier }); await _identityCommandRepository.AddAsync(identity); } await _clientCredentialLoginCommand.ExecuteAsync(identity); await _identityCommandRepository.UpdateAsync(identity); JwtAdto jwtAdto = await _jwtFactory.GenerateJwtAsync <JwtAdto>(GetClaimsIdentity(identity), identity.Session.Id); transaction.Commit(); return(jwtAdto); } catch (InvalidLoginDomainException) { throw new BusinessApplicationException(ExceptionType.Unauthorized, "Your login details are incorrect"); } catch (DomainValidationRuleException e) { throw new BusinessValidationRuleApplicationException(e.ValidationResult); } } }
public async Task CreateKeyAsync(DataKey dataKey) { Application application = await _applicationCommandRepository.GetSingleAsync(a => a.SystemName == _appSettings.SystemName); if (application == null) { application = await _createApplicationCommand.ExecuteAsync(new CreateApplicationCommandDdto { SystemName = _appSettings.SystemName }); await _addApplicationDataKeyCommand.ExecuteAsync(application, new AddApplicationDataKeyCommandDdto { Type = dataKey.Name, Value = dataKey.Value }); await _applicationCommandRepository.AddAsync(application); } else { await _addApplicationDataKeyCommand.ExecuteAsync(application, new AddApplicationDataKeyCommandDdto { Type = dataKey.Name, Value = dataKey.Value }); await _applicationCommandRepository.UpdateAsync(application); } }
public async Task <PasswordAdto> RegisterPasswordAsync(RegisterPasswordAdto registerPasswordAdto) { using (ITransaction transaction = _transactionManager.Create()) { try { Identity identity = await _createIdentityCommand.ExecuteAsync(); await _registerPasswordCommand.ExecuteAsync(identity, await GetAuthenticationGrantTypePasswordAsync(), new RegisterPasswordCommandDdto { Identifier = registerPasswordAdto.Identifier, Password = registerPasswordAdto.Password, ConfirmPassword = registerPasswordAdto.ConfirmPassword, EmailAddress = registerPasswordAdto.EmailAddress }); await _identityCommandRepository.AddAsync(identity); transaction.Commit(); return(new PasswordAdto { IdentityId = identity.Id }); } catch (DomainValidationRuleException e) { throw new BusinessValidationRuleApplicationException(e.ValidationResult); } } }
public async Task <Guid> Handle(CreateRequest request, CancellationToken cancellationToken) { var category = request.Adapt <Category>(); await _categoryRepository.AddAsync(category); return(category.Id); }
// RegisterOpenCardUserInfoCommand命令的处理程序 // 整个命令处理程序的核心都在这里 // 不仅包括命令验证的收集,持久化,还有领域事件和通知的添加 public async Task <Unit> Handle(RegisterSerilogCommand message, CancellationToken cancellationToken) { // 命令验证 if (!message.IsValid()) { await NotifyValidationErrorsAsync(message); // 错误信息收集 return(await Task.FromResult(new Unit())); // 返回,结束当前线程 } // 实例化领域模型,这里才真正的用到了领域模型 // 注意这里是通过构造函数方法实现 var customer = new Serilog(message.Id, message.Message, message.Level, message.TimeStamp, message.Exception, message.LogEvent, message.Remarks, message.IsDeleted, message.IsEnable, message.CreateTime, message.CreateUserId, message.ModifyUserId); // 持久化 await _CommandRepository.AddAsync(customer); // 统一提交 if (await CommitAsync()) { //通过领域事件发布 成功 通知 await Bus.RaiseEvent(new DomainNotification(DomainHandlerType.Register, DomainNotificationType.Success, "", $"{typeof(Serilog).Name} 登记成功")); } return(await Task.FromResult(new Unit())); }
public async Task <ProductDto> Handle(CreateRequest request, CancellationToken cancellationToken) { //TODO: refactor to let upload service decide where to store image var imageUrl = $"ProductImage/{request.ProductCode}/{Guid.NewGuid()}"; await _storageService.UploadFile(request.ProductImage.OpenReadStream(), imageUrl); var product = request.Adapt <Product>(); product.Id = Guid.NewGuid(); product.ProductCategories = new List <ProductCategory> { new ProductCategory { CategoryId = request.Category, ProductId = product.Id } }; product.ProductImages = new List <ProductImage> { new ProductImage { IsPrimary = true, ProductId = product.Id, Id = Guid.NewGuid(), StorageUrl = imageUrl } }; await _productRepository.AddAsync(product); return(product.Adapt <ProductDto>()); }
public async Task CreateAsync(CreateUserAdto createUserAdto) { using (ITransaction transaction = _transactionManager.Create()) { Identity identity = await _queryRepository.GetByIdAsync(createUserAdto.IdentityId); try { User user = await _createUserCommand.ExecuteAsync(new CreateUserCommandDdto { Identity = identity }); await _commandRepository.AddAsync(user); } catch (CreateDomainException e) { throw new BusinessApplicationException(ExceptionType.Unknown, e); } catch (ConcurrencyDomainException e) { throw new BusinessApplicationException(ExceptionType.Concurrency, e); } catch (DomainValidationRuleException e) { throw new BusinessValidationRuleApplicationException(e.ValidationResult); } transaction.Commit(); } }
public async Task <Guid> Handle(CreateRequest request, CancellationToken cancellationToken) { var brand = request.Adapt <Brand>(); await _brandRepository.AddAsync(brand); return(brand.Id); }
public async Task ExecuteAsync() { using (ITransaction transaction = _transactionManager.Create()) { try { IList <SharedDataKey> existingKeys = (await _commandRepository.GetAsync()).ToList(); foreach (FieldInfo fieldInfo in typeof(Library.Core.Domain.DataProtectors.SharedDataKeys).GetFields()) { string keyName = fieldInfo.GetRawConstantValue().ToString(); SharedDataKey key = existingKeys.SingleOrDefault(k => k.Name == keyName); if (key == null) { SharedDataKey sharedDataKey = await _createSharedDataKeyCommand.ExecuteAsync(new CreateSharedDataKeyCommandDdto { Name = keyName, Value = _encryptionFactory.CreateKey() }); await _commandRepository.AddAsync(sharedDataKey); } else { await _changeSharedDataKeyCommand.ExecuteAsync(key, new ChangeSharedDataKeyCommandDdto { Value = _encryptionFactory.CreateKey() }); await _commandRepository.UpdateAsync(key); } } transaction.Commit(); } catch (Exception) { _logger.LogCritical("Unable to initialise shared data keys"); throw; } } }
public async Task RegisterAsync(RegisterApplicationAdto registerApplicationAdto) { using (ITransaction transaction = _transactionManager.Create()) { try { Domain.Applications.Application application = await _commandRepository.GetSingleAsync(a => a.SystemName == registerApplicationAdto.SystemName); if (application == null) { application = await _createApplicationCommand.ExecuteAsync(new CreateApplicationDdto { Name = registerApplicationAdto.Name, SystemName = registerApplicationAdto.SystemName, HostUri = registerApplicationAdto.HostUri }); await _commandRepository.AddAsync(application); } else { await _changeApplicationCommand.ExecuteAsync(application, new ChangeApplicationDdto { Name = registerApplicationAdto.Name, HostUri = registerApplicationAdto.HostUri }); } transaction.Commit(); } catch (CreateDomainException e) { throw new BusinessApplicationException(ExceptionType.Unknown, e); } catch (ConcurrencyDomainException e) { throw new BusinessApplicationException(ExceptionType.Unknown, e); } } }
public async Task <FacebookAdto> CreateAsync(CreateFacebookAdto createFacebookAdto) { using (ITransaction transaction = _transactionManager.Create()) { try { AuthenticationGrantTypeFacebook authenticationGrantTypeFacebook = await _createAuthenticationGrantTypeFacebookCommand.ExecuteAsync( _mapper.Map <CreateFacebookAdto, CreateAuthenticationGrantTypeFacebookDdto>(createFacebookAdto)); await _commandRepository.AddAsync(authenticationGrantTypeFacebook); transaction.Commit(); return(CreateFacebookAdto(authenticationGrantTypeFacebook)); } catch (DomainValidationRuleException e) { throw new BusinessValidationRuleApplicationException(e.ValidationResult); } } }
public async Task CreateAsync(CreateAdminAuthenticationIdentityAdto createAdminAuthenticationIdentityAdto) { using (ITransaction transaction = _transactionManager.Create()) { try { Identity identity = await _createIdentityCommand.ExecuteAsync(); string tempPassword = $"{String.RandomChar(20)}{String.RandomNumeric(3)}{String.RandomSpecial(3)}"; await _registerPasswordCommand.ExecuteAsync(identity, await GetAuthenticationGrantTypePassword(), new RegisterPasswordCommandDdto { Identifier = createAdminAuthenticationIdentityAdto.EmailAddress, EmailAddress = createAdminAuthenticationIdentityAdto.EmailAddress, Password = tempPassword, ConfirmPassword = tempPassword }); await _commandRepository.AddAsync(identity); await _forgotPasswordCommand.ExecuteAsync(new ForgotPasswordCommandDdto { EmailAddress = createAdminAuthenticationIdentityAdto.EmailAddress }); await _commandRepository.UpdateAsync(identity); await Message.SendAsync(AdminIdentityCreatedMessage.Create(createAdminAuthenticationIdentityAdto.ApplicationName, identity.Id)); transaction.Commit(); } catch (DomainValidationRuleException e) { _logger.LogInformation("Could not create admin identity", e); } } }
public Task AddAsync(T item) { return(_commandRepository.AddAsync(item)); }