Пример #1
0
        public async Task <IActionResult> ActivateUser(string id)
        {
            ApplicationUser appUser = await this._accountManager.GetUserByIdAsync(id);

            if (appUser == null)
            {
                return(NotFound(id));
            }

            appUser.IsEnabled = true;
            var result = await _accountManager.UpdateUserAsync(appUser);

            if (result.Item1)
            {
                var recipients = new EmailAddress[] {
                    new EmailAddress {
                        Name  = appUser.FirstName + " " + appUser.LastName,
                        Email = appUser.Email
                    }
                };

                var requestParam = new Dictionary <string, string>
                {
                    { "{fullName}", appUser.FirstName + " " + appUser.LastName }
                };

                var response = await EmailSender.SendEmailAsync(
                    recipients,
                    subject : "Adam.info Account Information",
                    content : EmailTemplates.GetAccountActivatedEmail(requestParam, "en"),
                    isHtml : true,
                    addBccs : true);

                if (!response.Item1)
                {
                    this.logger.LogWarning(new EventId(1, "Email Error"), null, $"Failed to send Email Error: {response.Item2}");
                }
            }
            else
            {
                throw new Exception("The following errors occurred whilst activating user: "******", ", result.Item2));
            }

            return(NoContent());
        }