public async Task <IActionResult> RemovePublisher([FromBody] PublisherRemoveRequest request)
    {
        var leagueYearPublisherRecord = await GetExistingLeagueYearAndPublisher(request.PublisherID, ActionProcessingModeBehavior.Allow, RequiredRelationship.LeagueManager, RequiredYearStatus.YearNotFinishedDraftNotStarted);

        if (leagueYearPublisherRecord.FailedResult is not null)
        {
            return(leagueYearPublisherRecord.FailedResult);
        }
        var validResult = leagueYearPublisherRecord.ValidResult !;
        var leagueYear  = validResult.LeagueYear;
        var publisher   = validResult.Publisher;

        await _publisherService.FullyRemovePublisher(leagueYear, publisher);

        return(Ok());
    }
Beispiel #2
0
        public async Task <IActionResult> RemovePublisher([FromBody] PublisherRemoveRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var league = await _fantasyCriticService.GetLeagueByID(request.LeagueID);

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

            if (league.Value.LeagueManager.UserID != currentUser.UserID)
            {
                return(Forbid());
            }

            var publisher = await _publisherService.GetPublisher(request.PublisherID);

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

            if (publisher.Value.LeagueYear.League.LeagueID != league.Value.LeagueID)
            {
                return(Forbid());
            }

            if (publisher.Value.LeagueYear.PlayStatus.PlayStarted)
            {
                return(BadRequest());
            }

            await _publisherService.RemovePublisher(publisher.Value);

            return(Ok());
        }