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));
        }
Example #2
0
        public async Task <IActionResult> AddToSubscriptions([FromRoute] Guid id)
        {
            var incomingUser   = ControllerContext.IncomingUser();
            var userPromocodes = await _discounts.AddToSubscriptionsAsync(id, incomingUser.Id);

            _logger.LogInformation("Add To Subscriptions. Guid: {@id}. Result: {@userPromocodes}. User: {@incomingUser}.", id, userPromocodes, incomingUser);

            return(Ok(userPromocodes));
        }