Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] NotificationModel notification, CancellationToken cancellationToken = default)
        {
            var user = await _dbContext.Users.FindAsync(new object[] { UserId }, cancellationToken);

            if (user == null)
            {
                return(BadRequest($"User {this.UserEmail} not found"));
            }

            switch (notification.NotificationType)
            {
            case NotificationTypeEnum.Email:
                await _notificationService.SendMailAsync(new EmailNotification
                {
                    Body            = notification.Body,
                    Cc              = notification.Cc,
                    Cci             = notification.Cci,
                    From            = notification.From,
                    Subject         = notification.Subject,
                    To              = notification.To,
                    FromDisplayName = notification.FromDisplayName,
                    IsBodyHtml      = notification.IsBodyHtml,
                    AppId           = Assembly.GetExecutingAssembly().FullName,
                    UserId          = user.Id.ToString(),
                    TemplateId      = "d-46b66e30d388448d955ec0b73630eb21",
                    TemplateData    = new
                    {
                        header     = "Reset Password",
                        text       = notification.Body,
                        c2a_link   = "",
                        c2a_button = "Reset Password"
                    }
                }, cancellationToken);

                break;

            case NotificationTypeEnum.Sms:
                break;

            case NotificationTypeEnum.PushBrowser:
                break;

            case NotificationTypeEnum.PushMobile:
                break;

            default:
                await _notificationService.SendMailAsync(new EmailNotification
                {
                    Body            = notification.Body,
                    Cc              = notification.Cc,
                    Cci             = notification.Cci,
                    From            = notification.From,
                    Subject         = notification.Subject,
                    To              = notification.To,
                    FromDisplayName = notification.FromDisplayName,
                    IsBodyHtml      = notification.IsBodyHtml,
                    AppId           = Assembly.GetExecutingAssembly().FullName,
                    UserId          = user.Id.ToString()
                }, cancellationToken);

                break;
            }
            return(Ok());
        }