Ejemplo n.º 1
0
        public async Task <IActionResult> Subscribe(SubscribeInputViewModel inputModel)
        {
            var userId = this.usersService.GetLoggedUserId();

            var user = await this.usersService.GetLoggedUserByIdAsync(userId);

            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            if (user.HasSubscribe)
            {
                this.TempData["SubscribeMessage"] = GlobalConstants.UserSubscribeDenied;

                return(this.RedirectToAction("Index"));
            }
            else
            {
                this.TempData["SubscribeMessage"] = GlobalConstants.UserSubscribeSuccess;

                await this.usersService.UserSubscribeAsync(user);

                await this.SendEmail(inputModel);

                return(this.RedirectToAction("Index"));
            }
        }
Ejemplo n.º 2
0
        private async Task SendEmail(SubscribeInputViewModel inputModel)
        {
            await this.emailSender.SendEmailAsync(
                GlobalConstants.ApplicationSendEmail,
                GlobalConstants.AdministratorRoleName,
                inputModel.Email,
                GlobalConstants.SubscribeEmailSubject,
                GlobalConstants.SubscribeEmailContent);

            await this.emailSender.SendEmailAsync(
                GlobalConstants.ApplicationSendEmail,
                GlobalConstants.AdministratorRoleName,
                GlobalConstants.AdministratorReceiveEmail,
                GlobalConstants.AdministratorSubscribeEmailSubject,
                string.Format(GlobalConstants.AdministratorSubscribeEmailContent, inputModel.Email));
        }