예제 #1
0
        public async Task <IActionResult> RewardeesAsync(int id)
        {
            var reward = _rewardService.GetReward(id);

            if (reward == null)
            {
                return(NotFound());
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, reward, Policy.CanViewRewardees);

            if (!authResult.Succeeded)
            {
                return(Forbid());
            }

            ViewBag.Reward = reward;
            return(View(_rewardService.GetRewardees(id)));
        }
예제 #2
0
        public async Task <IActionResult> RewardeesAsync(int id, EmailInputModel input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Compose", input));
            }

            var reward = _rewardService.GetReward(id);

            if (reward == null)
            {
                return(NotFound());
            }

            var authResult = await _authorizationService.AuthorizeAsync(User, reward, Policy.CanEmail);

            if (!authResult.Succeeded)
            {
                return(Forbid());
            }

            var recipients = _rewardService.GetRewardees(id).Where(r => r.RequirementsMet)
                             .Select(r => new User
            {
                Id        = r.Id,
                FirstName = r.FirstName,
                LastName  = r.LastName,
                Email     = r.Email
            }).ToList();
            var msg = _emailSender.CreateMessage(User, recipients, input.Subject, input.Content);

            if (msg != null)
            {
                _ = _emailSender.SendAsync(msg);
            }

            _logger.LogInformation("{user} emailed to the rewardees of reward {reward}", User.Identity.Name, id);

            return(Redirect(input.RedirectUrl));
        }