Пример #1
0
        public static async Task <TrackAuth> CreateTrack(TrackAuth track)
        {
            if (track.PartitionKey == null || track.name == null)
            {
                return(null);
            }

            var extendedUser = await ExtendedUserRepository.GetExtendedUser(track.PartitionKey);

            // check private maxed out
            if (track.is_private)
            {
                if (extendedUser.Private_Tracks >= extendedUser.Private_Tracks_Max)
                {
                    return(null);
                }
            }

            // check public maxed out
            if (!track.is_private)
            {
                if (extendedUser.Public_Tracks >= extendedUser.Public_Tracks_Max)
                {
                    return(null);
                }
            }

            track.RowKey       = track.RowKey ?? Guid.NewGuid().ToString();
            track.subscribers  = 0;
            track.rate_limit   = extendedUser.Rate_Per_Track;
            track.track_key    = AuthRepository.GenerateRandomString(64);
            track.track_secret = AuthRepository.GenerateSHA256(track.RowKey + track.track_key);

            // insert into table storage
            var newTrack = await TableStorageRepository.InsertTrackAuth(track);

            if (newTrack == null)
            {
                return(null);
            }

            // insert into Cosmos
            await(dynamic) CosmosRepository <Track> .CreateItemAsync(new Track(track));

            // increment user's track count
            ExtendedUserRepository.IncrementTrackCount(track.PartitionKey, track.is_private);

            return(newTrack);
        }
Пример #2
0
 // cosmos stuff
 public static async Task <PostCosmos> InsertPostToCosmos(PostCosmos post)
 {
     return(await(dynamic) CosmosRepository <PostCosmos> .CreateItemAsync(post));
 }