public async Task <IActionResult> Post(CreateCustomer command) { var context = GetContext(command.Id); await BusPublisher.SendAsync(command, context); return(Accepted()); }
public async Task <IActionResult> Post(CreateLocationCommand locationCommand) { var context = GetContext(locationCommand.commandId); await BusPublisher.SendAsync(locationCommand, context); return(Accepted()); }
//public RabbitMQBrokerFactory(IServiceProvider provider, IBusClient client, RabbitMqOptions options) //{ // // Subscriber = new BusSubscriber(provider.GetService); // Publisher = new BusPublisher(client, options); //} public RabbitMQBrokerFactory(IServiceProvider provider) { client = provider.GetService <IBusClient>(); options = provider.GetService <RabbitMqOptions>(); Publisher = new BusPublisher(client, options); Subscriber = new BusSubscriber(provider); }
public async Task <JsonWebToken> Handle(RefreshAccessToken request, CancellationToken cancellationToken) { var token = request.Token; var refreshToken = await RefreshTokenRepository.GetAsync(token); if (refreshToken == null) { throw new IdentityException(Codes.RefreshTokenNotFound, "Refresh accessToken was not found."); } if (refreshToken.Revoked) { throw new IdentityException(Codes.RefreshTokenAlreadyRevoked, $"Refresh accessToken: '{refreshToken.Id}' was revoked."); } var user = await GetUserOrThrowAsync(refreshToken.UserId); var claims = await ClaimsProvider.GetAsync(user.Id); var jwt = JwtService.CreateToken(user.Id.ToString("N"), user.Role, claims); jwt.RefreshToken = refreshToken.Token; var @event = new AccessTokenRefreshedIntegrationEvent(user.Id); BusPublisher.Publish(@event); return(jwt); }
public async Task <IActionResult> Post(AddProductToBasket command) { var context = GetContext(); await BusPublisher.SendAsync(command, context); return(Accepted()); }
/// <summary> /// Handle the command with context /// </summary> /// <param name="command">The command to handle</param> /// <param name="context">The correlation context</param> /// <returns></returns> public override async Task HandleAsync(DeleteTypeDePropriete command, ICorrelationContext context) { await base.HandleAsync(command, context); await Repository.DeleteAsync(command.Id); await BusPublisher.PublishAsync(CreateEvent <TypeDeProprieteDeleted>(command), context); }
/// <summary> /// Handle the command with context /// </summary> /// <param name="command">The command to handle</param> /// <param name="context">The correlation context</param> /// <returns></returns> public override async Task HandleAsync(UpdateProduct command, ICorrelationContext context) { await base.HandleAsync(command, context); var product = GetDomainObject(command); await Repository.UpdateAsync(product); await BusPublisher.PublishAsync(CreateEvent <ProductUpdated>(command), context); }
protected async Task <IActionResult> SendAsync <T, TResourceType>(T command, TResourceType resourceId = default(TResourceType), string resource = "") where T : ICommand { var resId = GetContextResourceId(resourceId); var context = GetContext <T>(resId, resource); await BusPublisher.SendAsync(command, context); return(Accepted(context)); }
/// <summary> /// Handle the command with context /// </summary> /// <param name="command">The command to handle</param> /// <param name="context">The correlation context</param> /// <returns></returns> public override async Task HandleAsync(DeleteProduct command, ICorrelationContext context) { //await base.HandleAsync(command, context); await CheckExist(command.Id); await Repository.DeleteAsync(command.Id); await BusPublisher.PublishAsync(CreateEvent <ProductDeleted>(command), context); }
/// <summary> /// Handle the command with context /// </summary> /// <param name="command">The command to handle</param> /// <param name="context">The correlation context</param> /// <returns></returns> public override async Task HandleAsync(CreateTypeDePropriete command, ICorrelationContext context) { await base.HandleAsync(command, context); var product = GetDomainObject(command); product.CreatedDate = product.UpdatedDate = DateTime.Now; await Repository.AddAsync(product); await BusPublisher.PublishAsync(CreateEvent <TypeDeProprieteCreated>(command), context); }
protected async Task <IActionResult> SendAsync <TCommand, TResourceType>(TCommand command, [AllowNull] TResourceType resourceId, string resource = "") where TCommand : ICommand { var resId = GetContextResourceId(resourceId); var context = GetContext <TCommand>(resId, resource); await BusPublisher.SendAsync(command, context); return(Accepted(context)); }
public override async Task HandleAsync(CreateDefaultsSettings command, ICorrelationContext context) { DefaultsSettings.Get.ForEach(async s => { Setting setting = Mapper.Map <Setting>(s); CreateSetting cmd = Mapper.Map <CreateSetting>(setting); await BusPublisher.SendAsync(cmd, context); }); }
public override async Task HandleAsync(ReleaseProducts command, ICorrelationContext context) { foreach ((Guid productId, int quantity) in command.Products) { _logger.LogInformation($"Releasing a product: '{productId}' ({quantity})"); var product = await Repository.GetAsync(productId); if (product == null) { _logger.LogInformation($"Product was not found: '{productId}' (can't release)."); continue; } product.SetQuantity(product.Quantity + quantity); await Repository.UpdateAsync(product); _logger.LogInformation($"Released a product: '{productId}' ({quantity})"); } await BusPublisher.PublishAsync(CreateEvent <ProductsReleased>(command), context); }
/// <summary> /// Handle the command with context /// </summary> /// <param name="command">The command to handle</param> /// <param name="context">The correlation context</param> /// <returns></returns> public override async Task HandleAsync(CreateArticle command, ICorrelationContext context) { await base.HandleAsync(command, context); var product = GetDomainObject(command); if (product.Code == null) { throw new MicroSException("article_code_needed", $"The code article must be provided"); } var exist = await Repository.ExistsAsync(article => article.Code == product.Code); if (exist) { //throw new MicroSException("article_code_duplicate", $"This code article ${product.Code} already exist"); await BusPublisher.PublishAsync(new ArticleDuplicatedEvent(product.Code), context); } if (string.IsNullOrEmpty(product.Type)) { throw new MicroSException("article_invalid", $"you must define {nameof(product.Type)}"); } if (product.Type == "MO") { WeStringBuilder sb = new WeStringBuilder(); if (product.TxOpe <= 0) { sb.Add($"you must define {nameof(product.TxOpe)}"); } if (product.TxPrep <= 0) { sb.Add($"you must define {nameof(product.TxPrep)}"); } if (sb.HasItems) { throw new MicroSException("article_invalid", sb.Join("\n")); } product.Nomenclatures = null; product.Operations = null; product.Tarifs = null; } else if (product.Type == "TO" || product.Type == "PR") { WeStringBuilder sb = new WeStringBuilder(); if (product.Prix <= 0) { sb.Add($"you must define {nameof(product.Prix)}"); } if (product.Densite <= 0) { sb.Add($"you must define {nameof(product.Densite)}"); } if (sb.HasItems) { throw new MicroSException("article_invalid", sb.Join("\n")); } } if (product.TpPrep < 0) { throw new MicroSException("article_invalid", $"you must define {nameof(product.TpPrep)}"); } if (product.TpOpe < 0) { throw new MicroSException("article_invalid", $"you must define {nameof(product.TpOpe)}"); } if (product.TpBase < 0) { throw new MicroSException("article_invalid", $"you must define {nameof(product.TpBase)}"); } if (product.Operations != null) { var query = from op in product.Operations.ToList() group op by op.Ordre into grp where grp.Count() > 1 select grp.Key; if (query.Any()) { WeStringBuilder sb = new WeStringBuilder(); sb.Add(query); throw new MicroSException("operation_duplicate", $"Cannot have duplicate Ordre:${sb.Join(",")}"); } } await Repository.AddAsync(product); await BusPublisher.PublishAsync(CreateEvent <ArticleCreated>(command), context); }