コード例 #1
0
        public AlbumDetails(AlbumDetailsContract contract)
        {
            ParamIs.NotNull(() => contract);

            AdditionalNames = contract.AdditionalNames;
            ArtistString    = contract.ArtistString;
            CanEdit         = EntryPermissionManager.CanEdit(MvcApplication.LoginManager, contract);
            CommentCount    = contract.CommentCount;
            CreateDate      = contract.CreateDate;
            Description     = contract.Description;
            Deleted         = contract.Deleted;
            DiscType        = contract.DiscType;
            Draft           = contract.Status == EntryStatus.Draft;
            Hits            = contract.Hits;
            Id             = contract.Id;
            LatestComments = contract.LatestComments;
            MergedTo       = contract.MergedTo;
            Name           = contract.Name;
            OwnedBy        = contract.OwnedCount;
            Pictures       = contract.Pictures;
            PVs            = contract.PVs;
            RatingAverage  = contract.RatingAverage;
            RatingCount    = contract.RatingCount;
            Songs          = contract.Songs.GroupBy(s => s.DiscNumber).ToArray();
            Status         = contract.Status;
            Tags           = contract.Tags;
            UserHasAlbum   = contract.AlbumForUser != null;
            Version        = contract.Version;
            WebLinks       = contract.WebLinks;
            WishlistedBy   = contract.WishlistCount;
            mime           = contract.CoverPictureMime;

            if (contract.AlbumForUser != null)
            {
                AlbumMediaType      = contract.AlbumForUser.MediaType;
                AlbumPurchaseStatus = contract.AlbumForUser.PurchaseStatus;
                CollectionRating    = contract.AlbumForUser.Rating;
            }

            if (contract.OriginalRelease != null)
            {
                CatNum          = contract.OriginalRelease.CatNum;
                ReleaseEvent    = contract.OriginalRelease.EventName;
                ReleaseDate     = contract.OriginalRelease.ReleaseDate;
                FullReleaseDate = ReleaseDate.Year.HasValue && ReleaseDate.Month.HasValue && ReleaseDate.Day.HasValue ? (DateTime?)new DateTime(ReleaseDate.Year.Value, ReleaseDate.Month.Value, ReleaseDate.Day.Value) : null;
            }

            var artists = contract.ArtistLinks;

            Bands        = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Band)).ToArray();
            Circles      = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle)).ToArray();
            Labels       = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Label)).ToArray();
            Producers    = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray();
            Vocalists    = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray();
            OtherArtists = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Other) || a.Categories.HasFlag(ArtistCategories.Animator)).ToArray();

            PrimaryPV = PVHelper.PrimaryPV(PVs);
        }
コード例 #2
0
        public void UpdatePersonalDescription(int albumId, AlbumDetailsContract data)
        {
            PermissionContext.VerifyLogin();

            HandleTransaction(ctx => {
                var album = ctx.Load(albumId);

                EntryPermissionManager.VerifyAccess(PermissionContext, album, EntryPermissionManager.CanEditPersonalDescription);

                album.PersonalDescriptionText     = data.PersonalDescriptionText;
                album.PersonalDescriptionAuthorId = data.PersonalDescriptionAuthor?.Id;

                ctx.Update(album);
                ctx.AuditLogger.AuditLog(string.Format("updated personal description for {0}", entryLinkFactory.CreateEntryLink(album)));
            });
        }
コード例 #3
0
        public AlbumDetailsContract GetAlbumDetails(int id, string hostname)
        {
            return(HandleQuery(session => {
                var album = session.Load <Album>(id);
                var contract = new AlbumDetailsContract(album, PermissionContext.LanguagePreference);

                var user = PermissionContext.LoggedUser;

                if (user != null)
                {
                    var albumForUser = session.Query <AlbumForUser>()
                                       .FirstOrDefault(a => a.Album.Id == id && a.User.Id == user.Id);

                    contract.AlbumForUser = (albumForUser != null ? new AlbumForUserContract(albumForUser, PermissionContext.LanguagePreference) : null);
                }

                contract.CommentCount = session.Query <AlbumComment>().Count(c => c.Album.Id == id);
                contract.LatestComments = session.Query <AlbumComment>()
                                          .Where(c => c.Album.Id == id)
                                          .OrderByDescending(c => c.Created).Take(3).ToArray()
                                          .Select(c => new CommentContract(c)).ToArray();
                contract.Hits = session.Query <AlbumHit>().Count(h => h.Album.Id == id);

                if (user != null || !string.IsNullOrEmpty(hostname))
                {
                    var agentNum = (user != null ? user.Id : hostname.GetHashCode());

                    using (var tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) {
                        var isHit = session.Query <AlbumHit>().Any(h => h.Album.Id == id && h.Agent == agentNum);

                        if (!isHit)
                        {
                            var hit = new AlbumHit(album, agentNum);
                            session.Save(hit);
                        }

                        tx.Commit();
                    }
                }


                return contract;
            }));
        }
コード例 #4
0
        public string GenerateDescription(AlbumDetailsContract album, Func <DiscType, string> albumTypeNames)
        {
            var sb = new StringBuilder();

            AddBasicDescription(sb, album, albumTypeNames);

            if (album.Songs.Any())
            {
                sb.AppendFormat(", {0} track(s)", album.Songs.Length);

                if (album.TotalLength != TimeSpan.Zero)
                {
                    sb.AppendFormat(" ({0})", DateTimeHelper.FormatMinSec(album.TotalLength));
                }
            }

            sb.Append(".");

            return(sb.ToString());
        }
コード例 #5
0
        /// <summary>
        /// Gets album details, and updates hit count if necessary.
        /// </summary>
        /// <param name="id">Id of the album to be retrieved.</param>
        /// <param name="hostname">
        /// Hostname of the user requestin the album. Used to hit counting when no user is logged in. If null or empty, and no user is logged in, hit count won't be updated.
        /// </param>
        /// <returns>Album details contract. Cannot be null.</returns>
        public AlbumDetailsContract GetAlbumDetails(int id, string hostname)
        {
            return(HandleQuery(session => {
                var album = session.Load <Album>(id);

                var stats = session.Query <Album>()
                            .Where(a => a.Id == id)
                            .Select(a => new {
                    OwnedCount = a.UserCollections.Count(au => au.PurchaseStatus == PurchaseStatus.Owned),
                    WishlistedCount = a.UserCollections.Count(au => au.PurchaseStatus == PurchaseStatus.Wishlisted),
                    CommentCount = a.Comments.Count,
                    Hits = a.Hits.Count
                })
                            .FirstOrDefault();

                if (stats == null)
                {
                    throw new ObjectNotFoundException(id, typeof(Album));
                }

                var user = PermissionContext.LoggedUser;

                SongVoteRating?GetRatingFunc(Song song)
                {
                    return user != null && song != null ? (SongVoteRating?)session.Query <FavoriteSongForUser>().Where(s => s.Song.Id == song.Id && s.User.Id == user.Id).Select(r => r.Rating).FirstOrDefault() : null;
                }

                var contract = new AlbumDetailsContract(album, PermissionContext.LanguagePreference, PermissionContext, imagePersister, pictureFilePersister, GetRatingFunc)
                {
                    OwnedCount = stats.OwnedCount,
                    WishlistCount = stats.WishlistedCount,
                    CommentCount = stats.CommentCount,
                    Hits = stats.Hits
                };

                if (user != null)
                {
                    var albumForUser = session.Query <AlbumForUser>()
                                       .FirstOrDefault(a => a.Album.Id == id && a.User.Id == user.Id);

                    contract.AlbumForUser = (albumForUser != null ? new AlbumForUserContract(albumForUser, PermissionContext.LanguagePreference) : null);
                }

                contract.LatestComments = session.Query <AlbumComment>()
                                          .Where(c => c.EntryForComment.Id == id)
                                          .OrderByDescending(c => c.Created)
                                          .Take(3)
                                          .ToArray()
                                          .Select(c => new CommentForApiContract(c, userIconFactory))
                                          .ToArray();

                if (album.Deleted)
                {
                    var mergeEntry = GetMergeRecord(session, id);
                    contract.MergedTo = (mergeEntry != null ? new AlbumContract(mergeEntry.Target, LanguagePreference) : null);
                }

                if (user != null || !string.IsNullOrEmpty(hostname))
                {
                    var agentNum = (user != null ? user.Id : hostname.GetHashCode());

                    using (var tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) {
                        var isHit = session.Query <AlbumHit>().Any(h => h.Entry.Id == id && h.Agent == agentNum);

                        if (!isHit)
                        {
                            var hit = new AlbumHit(album, agentNum);
                            session.Save(hit);

                            try {
                                tx.Commit();
                            } catch (SqlException x) {
                                session.AuditLogger.SysLog("Error while committing hit: " + x.Message);
                            }
                        }
                    }
                }

                return contract;
            }));
        }
コード例 #6
0
        /// <summary>
        /// Gets album details, and updates hit count if necessary.
        /// </summary>
        /// <param name="id">Id of the album to be retrieved.</param>
        /// <param name="hostname">
        /// Hostname of the user requestin the album. Used to hit counting when no user is logged in. If null or empty, and no user is logged in, hit count won't be updated.
        /// </param>
        /// <returns>Album details contract. Cannot be null.</returns>
        public AlbumDetailsContract GetAlbumDetails(int id, string hostname)
        {
            return(HandleQuery(session => {
                var album = session.Load <Album>(id);

                var stats = session.Query <Album>()
                            .Where(a => a.Id == id)
                            .Select(a => new {
                    OwnedCount = a.UserCollections.Count(au => au.PurchaseStatus == PurchaseStatus.Owned),
                    WishlistedCount = a.UserCollections.Count(au => au.PurchaseStatus == PurchaseStatus.Wishlisted),
                    CommentCount = a.Comments.Count,
                    Hits = a.Hits.Count
                })
                            .FirstOrDefault();

                if (stats == null)
                {
                    throw new ObjectNotFoundException(id, typeof(Album));
                }

                var contract = new AlbumDetailsContract(album, PermissionContext.LanguagePreference)
                {
                    OwnedCount = stats.OwnedCount,
                    WishlistCount = stats.WishlistedCount,
                    CommentCount = stats.CommentCount,
                    Hits = stats.Hits
                };

                var user = PermissionContext.LoggedUser;

                if (user != null)
                {
                    var albumForUser = session.Query <AlbumForUser>()
                                       .FirstOrDefault(a => a.Album.Id == id && a.User.Id == user.Id);

                    contract.AlbumForUser = (albumForUser != null ? new AlbumForUserContract(albumForUser, PermissionContext.LanguagePreference) : null);
                }

                contract.LatestComments = session.Query <AlbumComment>()
                                          .Where(c => c.Album.Id == id)
                                          .OrderByDescending(c => c.Created)
                                          .Take(3)
                                          .ToArray()
                                          .Select(c => new CommentContract(c))
                                          .ToArray();

                if (album.Deleted)
                {
                    var mergeEntry = GetMergeRecord(session, id);
                    contract.MergedTo = (mergeEntry != null ? new AlbumContract(mergeEntry.Target, LanguagePreference) : null);
                }

                if (user != null || !string.IsNullOrEmpty(hostname))
                {
                    var agentNum = (user != null ? user.Id : hostname.GetHashCode());

                    using (var tx = session.BeginTransaction(IsolationLevel.ReadUncommitted)) {
                        var isHit = session.Query <AlbumHit>().Any(h => h.Album.Id == id && h.Agent == agentNum);

                        if (!isHit)
                        {
                            var hit = new AlbumHit(album, agentNum);
                            session.Save(hit);

                            try {
                                tx.Commit();
                            } catch (SqlException x) {
                                log.WarnException("Error while committing hit", x);
                            }
                        }
                    }
                }


                return contract;
            }));
        }
コード例 #7
0
ファイル: AlbumModels.cs プロジェクト: kurono1984/vocadb
        public AlbumDetails(AlbumDetailsContract contract, IUserPermissionContext permissionContext)
        {
            ParamIs.NotNull(() => contract);

            AdditionalNames            = contract.AdditionalNames;
            ArtistString               = contract.ArtistString;
            CanEdit                    = EntryPermissionManager.CanEdit(permissionContext, contract);
            CanEditPersonalDescription = contract.CanEditPersonalDescription;
            CanRemoveTagUsages         = contract.CanRemoveTagUsages;
            CommentCount               = contract.CommentCount;
            CreateDate                 = contract.CreateDate;
            Description                = contract.Description;
            Deleted                    = contract.Deleted;
            DiscType                   = contract.DiscType;
            Draft                     = contract.Status == EntryStatus.Draft;
            Hits                      = contract.Hits;
            Id                        = contract.Id;
            LatestComments            = contract.LatestComments;
            LatestReview              = contract.Stats.LatestReview;
            LatestReviewRatingScore   = contract.Stats.LatestReviewRatingScore;
            MergedTo                  = contract.MergedTo;
            Name                      = contract.Name;
            OwnedBy                   = contract.Stats.OwnedCount;
            PersonalDescriptionText   = contract.PersonalDescriptionText;
            PersonalDescriptionAuthor = contract.PersonalDescriptionAuthor;
            Pictures                  = contract.Pictures;
            PVs                       = contract.PVs;
            RatingAverage             = contract.RatingAverage;
            RatingCount               = contract.RatingCount;
            ReviewCount               = contract.Stats.ReviewCount;
            Status                    = contract.Status;
            Tags                      = contract.Tags;
            TotalLength               = contract.TotalLength;
            UserHasAlbum              = contract.AlbumForUser != null;
            Version                   = contract.Version;
            WebLinks                  = contract.WebLinks;
            WishlistedBy              = contract.Stats.WishlistCount;
            mime                      = contract.CoverPictureMime;

            var songsByDiscs = contract.Songs.GroupBy(s => s.DiscNumber);

            Discs =
                (from songsByDisc in songsByDiscs
                 let dn = songsByDisc.Key
                          select new AlbumDisc(dn, songsByDisc, contract.Discs.ContainsKey(dn) ? contract.Discs[dn] : null))
                .ToArray();

            if (contract.AlbumForUser != null)
            {
                AlbumMediaType      = contract.AlbumForUser.MediaType;
                AlbumPurchaseStatus = contract.AlbumForUser.PurchaseStatus;
                CollectionRating    = contract.AlbumForUser.Rating;
            }

            if (contract.OriginalRelease != null)
            {
                CatNum          = contract.OriginalRelease.CatNum;
                ReleaseEvent    = contract.OriginalRelease.ReleaseEvent;
                ReleaseDate     = contract.OriginalRelease.ReleaseDate;
                FullReleaseDate = ReleaseDate.Year.HasValue && ReleaseDate.Month.HasValue && ReleaseDate.Day.HasValue ? (DateTime?)new DateTime(ReleaseDate.Year.Value, ReleaseDate.Month.Value, ReleaseDate.Day.Value) : null;
            }

            var artists = contract.ArtistLinks;

            ContentFocus = AlbumHelper.GetContentFocus(DiscType);

            Bands        = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Band)).ToArray();
            Circles      = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle)).ToArray();
            Illustrators = ContentFocus == ContentFocus.Illustration ? artists.Where(a => a.Categories.HasFlag(ArtistCategories.Illustrator)).ToArray() : null;
            Labels       = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Label)).ToArray();
            Producers    = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray();
            Vocalists    = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray();
            Subject      = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Subject)).ToArray();
            OtherArtists = artists.Where(a => a.Categories.HasFlag(ArtistCategories.Other) ||
                                         a.Categories.HasFlag(ArtistCategories.Animator) ||
                                         (ContentFocus != ContentFocus.Illustration && a.Categories.HasFlag(ArtistCategories.Illustrator))).ToArray();

            PrimaryPV = PVHelper.PrimaryPV(PVs);
        }
コード例 #8
0
ファイル: AlbumApiController.cs プロジェクト: ffdd270/vocadb
 public void PostPersonalDescription(int id, AlbumDetailsContract data)
 {
     queries.UpdatePersonalDescription(id, data);
 }
コード例 #9
0
        public AlbumDetailsContract GetAlbumDetails(int id, string hostname)
        {
            return(HandleQuery(session =>
            {
                var album = session.Load <Album>(id);

                var user = PermissionContext.LoggedUser;

                SongVoteRating?GetRatingFunc(Song song)
                {
                    return user != null && song != null ? (SongVoteRating?)session.Query <FavoriteSongForUser>().Where(s => s.Song.Id == song.Id && s.User.Id == user.Id).Select(r => r.Rating).FirstOrDefault() : null;
                }

                var contract = new AlbumDetailsContract(album, PermissionContext.LanguagePreference, PermissionContext, _imageUrlFactory, GetRatingFunc,
                                                        discTypeTag: new EntryTypeTags(session).GetTag(EntryType.Album, album.DiscType))
                {
                    CommentCount = Comments(session).GetCount(id),
                    Hits = session.Query <AlbumHit>().Count(h => h.Entry.Id == id),
                    Stats = GetSharedAlbumStats(session, album)
                };

                if (user != null)
                {
                    var albumForUser = session.Query <AlbumForUser>()
                                       .FirstOrDefault(a => a.Album.Id == id && a.User.Id == user.Id);

                    contract.AlbumForUser = (albumForUser != null ? new AlbumForUserContract(albumForUser, PermissionContext.LanguagePreference) : null);
                }

                contract.LatestComments = session.Query <AlbumComment>()
                                          .WhereNotDeleted()
                                          .Where(c => c.EntryForComment.Id == id)
                                          .OrderByDescending(c => c.Created)
                                          .Take(3)
                                          .ToArray()
                                          .Select(c => new CommentForApiContract(c, _userIconFactory))
                                          .ToArray();

                if (album.Deleted)
                {
                    var mergeEntry = GetMergeRecord(session, id);
                    contract.MergedTo = (mergeEntry != null ? new AlbumContract(mergeEntry.Target, LanguagePreference) : null);
                }

                if (user != null || !string.IsNullOrEmpty(hostname))
                {
                    var agentNum = (user != null ? user.Id : hostname.GetHashCode());

                    using (var tx = session.BeginTransaction(IsolationLevel.ReadUncommitted))
                    {
                        var isHit = session.Query <AlbumHit>().Any(h => h.Entry.Id == id && h.Agent == agentNum);

                        if (!isHit)
                        {
                            var hit = new AlbumHit(album, agentNum);
                            session.Save(hit);

                            try
                            {
                                tx.Commit();
                            }
                            catch (SqlException x)
                            {
                                session.AuditLogger.SysLog("Error while committing hit: " + x.Message);
                            }
                        }
                    }
                }

                return contract;
            }));
        }