public async Task <IActionResult> AddToSubscriptions([FromRoute] Guid id) { var currentUser = ControllerContext.CurrentUser(); var discountUserPromocodes = await _discounts.AddToSubscriptionsAsync(id, currentUser.Id); _logger.LogInformation("Add To Subscriptions. Guid: {@id}. Result: {@userPromocodes}. User: {@currentUser}.", id, discountUserPromocodes, currentUser); if (discountUserPromocodes != null && !discountUserPromocodes.CurrentPromocode.IsEmpty()) { var employee = (await _users.GetUserByUidAsync(currentUser.Id)).ToEmployee(); var userEvent = new PromocodeAddedIntegrationEvent <UserMailContent> (new UserMailContent(employee, id, discountUserPromocodes.DiscountName, discountUserPromocodes.CurrentPromocode.PromocodeValue), "WebApi", new BusParams("crazyprice.direct", "mail.user")); await PublishThroughEventBusAsync(userEvent); var companyEvent = new PromocodeAddedIntegrationEvent <CompanyMailContent> (new CompanyMailContent(discountUserPromocodes.Company, id, discountUserPromocodes.DiscountName, discountUserPromocodes.CurrentPromocode.PromocodeValue), "WebApi", new BusParams("crazyprice.direct", "mail.company")); await PublishThroughEventBusAsync(companyEvent); } return(Ok(discountUserPromocodes?.UserPromocodes)); }
public async Task Handle(PromocodeAddedIntegrationEvent <CompanyMailContent> @event) { _logger.LogInformation("Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.EventId, ApplicationInfo.ApplicationName, @event); var message = new MimeMessage(); message.From.Add(new MailboxAddress("Exadel Info", "*****@*****.**")); message.To.Add(new MailboxAddress("Mr. Friend", "*****@*****.**")); message.Subject = "Exadel Promo"; message.Body = _mailBuilder.GetMessageBody(MailBodyOption.Company, LanguageOption.Ru, @event.Content); await _mailClient.SendAsync(message); await Task.CompletedTask; }