Пример #1
0
        public async Task <IActionResult> RemoveEventAsync(int rewardId, int eventId)
        {
            var reward = _rewardService.GetReward(rewardId);

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

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

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

            var rewardEvent = _rewardService.GetRewardEvent(rewardId, eventId);

            if (rewardEvent == null)
            {
                return(BadRequest());
            }

            _rewardService.RemoveRewardEvent(rewardEvent);
            _rewardService.SaveChanges();
            _logger.LogInformation("{user} removed event {event} from reward {reward}",
                                   User.Identity.Name, eventId, rewardId);

            return(Ok());
        }