public async Task SendRewardAsync(User user, Reward reward, CancellationToken cancellationToken)
        {
            string emailSubject = "SSW Rewards - Reward Notification";

            // TODO: These values are hard coded here but will be
            // replaced with the user's details once we implement
            // physical address functionality and automatic sending
            // of rewards
            string recipientEmail = "*****@*****.**";
            string recipientName  = "SSW Marketing";

            bool rewardSentSuccessully;

            if (reward.RewardType == RewardType.Physical)
            {
                PhysicalRewardEmail emailProps = new PhysicalRewardEmail
                {
                    RecipientAddress = "Please contact user for address", // TODO: when we implement addess capture, change to: user.Address.ToString(),
                    RecipientName    = user.FullName,
                    RewardName       = reward.Name
                };

                rewardSentSuccessully = await _emailService.SendPhysicalRewardEmail(recipientEmail, recipientName, emailSubject, emailProps, cancellationToken);
            }
            else
            {
                // TODO: Replace this with logic that:
                // 1. Determines if it is a free ticket
                // 2. If yes, generate with the appropriate API (currently eventbrite) and send to user
                // 3. If no, send notification to Marketing for appropriate action

                string voucherCode = "Please generate for user";

                //end TODO

                DigitalRewardEmail emailProps = new DigitalRewardEmail
                {
                    RecipientName  = user.FullName,
                    RecipientEmail = user.Email,
                    RewardName     = reward.Name,
                    VoucherCode    = voucherCode
                };

                rewardSentSuccessully = await _emailService.SendDigitalRewardEmail(recipientEmail, recipientName, emailSubject, emailProps, cancellationToken);
            }

            if (!rewardSentSuccessully)
            {
                _logger.LogError("Error sending email reward notification.", reward, user);
            }
        }
Exemple #2
0
        public async Task <bool> SendDigitalRewardEmail(string to, string toName, string subject, DigitalRewardEmail emailProps, CancellationToken cancellationToken)
        {
            var template = "<p>Hi SSW Marketing</p><p>@Model.RecipientName has claimed @Model.RewardName.</p></p>Please generate a voucher code and send it to @Model.RecipientEmail.</p><p>Thanks,</p><p>SSW Rewards Notification Service</p>";

            var result = await _fluentEmail
                         .To(to)
                         .Subject(subject)
                         .UsingTemplate(template, emailProps)
                         .SendAsync(cancellationToken);

            if (result.Successful)
            {
                return(true);
            }
            else
            {
                _logger.LogError("Error sending email", _fluentEmail);
                return(false);
            }
        }