Example #1
0
        public async Task <OperationResult <bool> > AddNewCollectionComment(User user, Guid collectionId, string cmt)
        {
            var sw         = Stopwatch.StartNew();
            var result     = false;
            var errors     = new List <Exception>();
            var collection = DbContext.Collections
                             .FirstOrDefault(x => x.RoadieId == collectionId);

            if (collection == null)
            {
                return(new OperationResult <bool>(true, string.Format("Collection Not Found [{0}]", collectionId)));
            }

            var newComment = new data.Comment
            {
                CollectionId = collection.Id,
                UserId       = user.Id.Value,
                Cmt          = cmt
            };

            DbContext.Comments.Add(newComment);
            await DbContext.SaveChangesAsync();

            CacheManager.ClearRegion(collection.CacheRegion);
            sw.Stop();
            result = true;
            return(new OperationResult <bool>
            {
                Data = result,
                IsSuccess = result,
                Errors = errors,
                OperationTime = sw.ElapsedMilliseconds
            });
        }
Example #2
0
        private void ClearCaches(data.Comment comment)
        {
            switch (comment.CommentType)
            {
            case CommentType.Artist:
                var artist = DbContext.Artists.FirstOrDefault(x => x.Id == comment.ArtistId);
                if (artist != null)
                {
                    CacheManager.ClearRegion(artist.CacheRegion);
                }
                break;

            case CommentType.Collection:
                var collection = DbContext.Collections.FirstOrDefault(x => x.Id == comment.CollectionId);
                if (collection != null)
                {
                    CacheManager.ClearRegion(collection.CacheRegion);
                }
                break;

            case CommentType.Genre:
                var genre = DbContext.Genres.FirstOrDefault(x => x.Id == comment.GenreId);
                if (genre != null)
                {
                    CacheManager.ClearRegion(genre.CacheRegion);
                }
                break;

            case CommentType.Label:
                var label = DbContext.Labels.FirstOrDefault(x => x.Id == comment.LabelId);
                if (label != null)
                {
                    CacheManager.ClearRegion(label.CacheRegion);
                }
                break;

            case CommentType.Playlist:
                var playlist = DbContext.Playlists.FirstOrDefault(x => x.Id == comment.PlaylistId);
                if (playlist != null)
                {
                    CacheManager.ClearRegion(playlist.CacheRegion);
                }
                break;

            case CommentType.Release:
                var release = DbContext.Releases.FirstOrDefault(x => x.Id == comment.ReleaseId);
                if (release != null)
                {
                    CacheManager.ClearRegion(release.CacheRegion);
                }
                break;

            case CommentType.Track:
                var track = DbContext.Tracks.FirstOrDefault(x => x.Id == comment.TrackId);
                if (track != null)
                {
                    CacheManager.ClearRegion(track.CacheRegion);
                }
                break;
            }
        }