Ejemplo n.º 1
0
 public void DeserializeAsset(AssetFile assetFile, StreamReader stream)
 {
     m_pointsMustBe      = (PointRelationship)stream.ReadInt32();
     threshold           = stream.ReadInt32();
     subtractEnemyPoints = stream.ReadBoolean();
     stream.AlignTo();
     whenRelationship = (WhenRelationship)stream.ReadInt32();
     m_CTF_conditions = new SerializedArray <CaptureTheFlag.CTF_VictoryCondition>(assetFile, stream);
     m_CTC_conditions = new SerializedArray <CollectTheCoins.CollectTheCoins_VictoryCondition>(assetFile, stream);
 }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> GetListOfRelatedGames(string id, PointRelationship relationship,
                                                                    bool stats = false, NormalPointIdentityType idType = NormalPointIdentityType.Id, int skip = 0, int take = 9)
        {
            if (take > 50)
            {
                take = 50;
            }

            var point = await _dbContext.NormalPoints
                        .SingleOrDefaultAsync(p => idType == NormalPointIdentityType.IdCode?p.IdCode == id : p.Id == id);

            if (point == null || (point.Type != NormalPointType.Manufacturer && point.Type != NormalPointType.Genre))
            {
                return(NotFound());
            }

            var queryBase = _dbContext.NormalPoints.Where(p => p.Id == point.Id);
            IQueryable <Models.NormalPoint> queryNext;

            switch (relationship)
            {
            case PointRelationship.Developer:
                queryNext = queryBase.SelectMany(p => p.DeveloperForPoints);
                break;

            case PointRelationship.Publisher:
                queryNext = queryBase.SelectMany(p => p.PublisherForPoints);
                break;

            case PointRelationship.Series:
                queryNext = queryBase.SelectMany(p => p.SeriesForPoints);
                break;

            case PointRelationship.Genre:
                queryNext = queryBase.SelectMany(p => p.GenreForPoints);
                break;

            case PointRelationship.Tag:
                queryNext = queryBase.SelectMany(p => p.TagForPoints);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(relationship), relationship, null);
            }
            var points = await queryNext.OrderByDescending(p => p.ReleaseDate)
                         .Skip(() => skip).Take(() => take).ToListAsync();

            var userId = User.Identity.GetUserId();

            return(Ok(points.Select(p =>
            {
                var dto = new NormalPointDto(p)
                {
                    ReleaseDate = p.ReleaseDate
                };
                if (stats)
                {
                    dto.SubscriberCount = _dbContext.NormalPoints.Where(np => np.Id == p.Id)
                                          .Select(np => np.Subscribers.Count)
                                          .Single();
                    dto.ArticleCount = _dbContext.NormalPoints.Where(np => np.Id == p.Id)
                                       .Select(np => np.Articles.Count)
                                       .Single();
                    dto.Subscribed = _dbContext.NormalPoints.Where(np => np.Id == p.Id)
                                     .SelectMany(np => np.Subscribers)
                                     .Select(u => u.Id)
                                     .Contains(userId);
                }
                return dto;
            })));
        }