예제 #1
0
        public async Task <ServiceResult> CreateGameCast(Guid userId, DTO.Casting.CreateCastData castData)
        {
            var result = new ServiceResult();

            var user = await this.alexandriaContext.UserProfiles.FirstOrDefaultAsync(up => up.Id == userId);

            if (user == null)
            {
                result.Error = Shared.ErrorKey.UserProfile.UserNotFound;
                return(result);
            }

            var matchSeries = await this.alexandriaContext.MatchSeries
                              .Include(ms => ms.TournamentRound)
                              .Include(ms => ms.MatchSeriesCastings)
                              .Include(ms => ms.MatchSeriesCastingClaims)
                              .FirstOrDefaultAsync(ms => ms.Id == castData.MatchSeriesId);

            if (matchSeries == null)
            {
                result.Error = Shared.ErrorKey.MatchSeries.NotFound;
                return(result);
            }

            if (matchSeries.MatchSeriesCastings.Any())
            {
                result.Error = Shared.ErrorKey.Casting.AlreadyClaimed;
                return(result);
            }

            if (!castData.StartsAt.HasValue)
            {
                castData.StartsAt = matchSeries.ScheduledAt;
            }

            var cast = await this.DangerouslyCreateGameCast(userId, castData);

            this.cacheBreaker.Break(Shared.Cache.Tournament.Schedule(matchSeries.TournamentRound.TournamentId));
            result.Succeed();

            return(result);
        }
예제 #2
0
        public async Task <OperationResult> CreateGameCast([FromBody] DTO.Casting.CreateCastData payload)
        {
            var userId = this.HttpContext.GetUserId();

            if (!userId.HasValue || userId == Guid.Empty)
            {
                return(new OperationResult());
            }

            if (!await this.castingUtils.CanCast(userId.Value, payload.MatchSeriesId))
            {
                return(new OperationResult(403));
            }

            var result = await this.gameCastingService.CreateGameCast(userId.Value, payload);

            if (result.Success)
            {
                return(new OperationResult(201));
            }

            return(new OperationResult(result.Error));
        }
예제 #3
0
        private async Task <MatchSeriesCasting> DangerouslyCreateGameCast(Guid userId, DTO.Casting.CreateCastData castData)
        {
            var cast = new MatchSeriesCasting(castData.StreamURL, castData.StartsAt);

            cast.AddParticipant(userId, CastingRole.PlayByPlay);
            cast.MatchSeriesId = castData.MatchSeriesId;

            this.alexandriaContext.MatchSeriesCastings.Add(cast);
            await this.authorizationService.AddPermission(userId,
                                                          AuthorizationHelper.GenerateARN(typeof(MatchSeriesCasting), cast.Id.ToString(), GameCast.All));


            return(cast);
        }