예제 #1
0
        public async Task <IActionResult> ChangePublisherName([FromBody] ChangePublisherNameRequest request)
        {
            var publisher = await _fantasyCriticService.GetPublisher(request.PublisherID);

            if (publisher.HasNoValue)
            {
                return(BadRequest());
            }

            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            bool userIsInLeague = await _fantasyCriticService.UserIsInLeague(publisher.Value.League, currentUser);

            if (!userIsInLeague)
            {
                return(Forbid());
            }

            if (publisher.Value.User.UserID != currentUser.UserID)
            {
                return(Forbid());
            }

            await _fantasyCriticService.ChangePublisherName(publisher.Value, request.PublisherName);

            return(Ok());
        }