コード例 #1
0
        public async Task <IActionResult> RemovePublisherGame([FromBody] GameRemoveRequest request)
        {
            var currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

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

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

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

            var league = await _fantasyCriticService.GetLeagueByID(publisher.Value.League.LeagueID);

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

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

            Maybe <PublisherGame> publisherGame = await _fantasyCriticService.GetPublisherGame(request.PublisherGameID);

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

            var leagueYear = await _fantasyCriticService.GetLeagueYear(league.Value.LeagueID, publisher.Value.Year);

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

            Result result = await _fantasyCriticService.RemovePublisherGame(leagueYear.Value, publisher.Value, publisherGame.Value);

            if (result.IsFailure)
            {
                return(BadRequest(result.Error));
            }

            await _fantasyCriticService.UpdateFantasyPoints(leagueYear.Value);

            return(Ok());
        }