Exemple #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);
        }
Exemple #2
0
        public static async Task <bool> DeleteTrack(string trackId)
        {
            // decrement the count
            var track = await GetTrack(trackId);

            ExtendedUserRepository.DecrementTrackCount(track.PartitionKey, track.is_private);

            // send messages to queue
            TableStorageRepository.AddMessageToQueue("delete-posts-from-track", trackId);
            TableStorageRepository.AddMessageToQueue("delete-tracktags-from-track", trackId);

            // then delete track cosmos
            CosmosRepository <Track> .DeleteItemAsync(trackId);

            // then delete profile pics
            DeleteImages(trackId);

            // then delete from table storage, and return
            return(await TableStorageRepository.DeleteTrack(trackId));
        }