コード例 #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
        private void TestCanEdit(bool expected, EntryStatus entryStatus = EntryStatus.Finished, UserGroupId userGroup = UserGroupId.Regular)
        {
            artist.Status = entryStatus;
            user.GroupId  = userGroup;

            var result = EntryPermissionManager.CanEdit(new FakePermissionContext(user), artist);

            Assert.AreEqual(expected, result, "result");
        }
コード例 #3
0
        private void TestCanEdit(bool expected, EntryStatus entryStatus = EntryStatus.Finished, UserGroupId userGroup = UserGroupId.Regular)
        {
            _artist.Status = entryStatus;
            _user.GroupId  = userGroup;

            var result = EntryPermissionManager.CanEdit(new FakePermissionContext(_user), _artist);

            result.Should().Be(expected, "result");
        }
コード例 #4
0
ファイル: SongListContract.cs プロジェクト: sethura/vocadb
        public SongListContract(SongList list, IUserPermissionContext permissionContext)
            : base(list)
        {
            ParamIs.NotNull(() => list);

            Author           = new UserContract(list.Author);
            CanEdit          = EntryPermissionManager.CanEdit(permissionContext, list);
            Description      = list.Description;
            FeaturedCategory = list.FeaturedCategory;
        }
コード例 #5
0
ファイル: SongListContract.cs プロジェクト: lordofire/vocadb
        public SongListContract(SongList list, IUserPermissionContext permissionContext)
            : base(list)
        {
            ParamIs.NotNull(() => list);

            Author           = new UserWithEmailContract(list.Author);
            CanEdit          = EntryPermissionManager.CanEdit(permissionContext, list);
            Description      = list.Description;
            FeaturedCategory = list.FeaturedCategory;
            Thumb            = (list.Thumb != null ? new EntryThumbContract(list.Thumb) : null);
        }
コード例 #6
0
        public SongListContract(SongList list, IUserPermissionContext permissionContext)
            : base(list)
        {
            ParamIs.NotNull(() => list);

            Author      = new UserWithEmailContract(list.Author);
            CanEdit     = EntryPermissionManager.CanEdit(permissionContext, list);
            Description = list.Description;
            EventDate   = list.EventDate;
            Status      = list.Status;
            Thumb       = (list.Thumb != null ? new EntryThumbContract(list.Thumb) : null);
            Version     = list.Version;
        }
コード例 #7
0
        public void CanEdit_ApprovedEntry_OwnerUser()
        {
            var artist = CreateEntry.Artist(ArtistType.Producer);
            var user   = CreateEntry.User();

            artist.Status = EntryStatus.Approved;
            user.GroupId  = UserGroupId.Regular;

            user.AddOwnedArtist(artist);

            var result = EntryPermissionManager.CanEdit(new FakePermissionContext(user), artist);

            Assert.IsTrue(result, "result");
        }
コード例 #8
0
        public static bool CanEdit(IEntryWithStatus entry)
        {
            ParamIs.NotNull(() => entry);

            return(EntryPermissionManager.CanEdit(Manager, entry));
        }
コード例 #9
0
        public SongDetails(SongDetailsContract contract, IUserPermissionContext userContext, PVHelper pvHelper)
        {
            ParamIs.NotNull(() => contract);

            Contract                   = contract;
            AdditionalNames            = contract.AdditionalNames;
            Albums                     = contract.Albums;
            AlternateVersions          = contract.AlternateVersions.Where(a => a.SongType != SongType.Original).ToArray();
            ArtistString               = contract.ArtistString;
            BrowsedAlbumId             = contract.Album?.Id;
            CanEdit                    = EntryPermissionManager.CanEdit(userContext, contract.Song);
            CanEditPersonalDescription = contract.CanEditPersonalDescription;
            CanRemoveTagUsages         = contract.CanRemoveTagUsages;
            CommentCount               = contract.CommentCount;
            CreateDate                 = contract.CreateDate;
            DefaultLanguageSelection   = contract.TranslatedName.DefaultLanguage;
            Deleted                    = contract.Deleted;
            Draft                     = contract.Song.Status == EntryStatus.Draft;
            FavoritedTimes            = contract.Song.FavoritedTimes;
            Hits                      = contract.Hits;
            Id                        = contract.Song.Id;
            IsFavorited               = contract.UserRating != SongVoteRating.Nothing;
            LatestComments            = contract.LatestComments;
            Length                    = contract.Song.LengthSeconds;
            LikedTimes                = contract.LikeCount;
            ListCount                 = contract.ListCount;
            Lyrics                    = contract.LyricsFromParents;
            MergedTo                  = contract.MergedTo;
            Name                      = contract.Song.Name;
            NicoId                    = contract.Song.NicoId;
            Notes                     = contract.Notes;
            OriginalVersion           = (contract.Song.SongType != SongType.Original ? contract.OriginalVersion : null);
            Pools                     = contract.Pools;
            PublishDate               = contract.Song.PublishDate;
            RatingScore               = contract.Song.RatingScore;
            ReleaseEvent              = contract.ReleaseEvent;
            PersonalDescriptionText   = contract.PersonalDescriptionText;
            PersonalDescriptionAuthor = contract.PersonalDescriptionAuthor;
            SongType                  = contract.Song.SongType;
            SongTypeTag               = contract.SongTypeTag;
            Status                    = contract.Song.Status;
            Suggestions               = contract.Suggestions;
            Tags                      = contract.Tags;
            UserRating                = contract.UserRating;
            WebLinks                  = contract.WebLinks.ToList();
            ContentFocus              = SongHelper.GetContentFocus(SongType);

            Animators    = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Animator)).ToArray();
            Bands        = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Band)).ToArray();
            Illustrators = ContentFocus == ContentFocus.Illustration ? contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Illustrator)).ToArray() : null;
            Performers   = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray();
            Producers    = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray();
            var subjectsForThis = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Subject)).ToArray();

            Subject      = subjectsForThis.Any() ? subjectsForThis : contract.SubjectsFromParents;
            OtherArtists = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle) ||
                                                  a.Categories.HasFlag(ArtistCategories.Label) ||
                                                  a.Categories.HasFlag(ArtistCategories.Other) ||
                                                  (ContentFocus != ContentFocus.Illustration && a.Categories.HasFlag(ArtistCategories.Illustrator))).ToArray();

            var pvs = contract.PVs;

            OriginalPVs     = pvs.Where(p => p.PVType == PVType.Original).ToArray();
            OtherPVs        = pvs.Where(p => p.PVType != PVType.Original).ToArray();
            PrimaryPV       = pvHelper.PrimaryPV(pvs);
            ThumbUrl        = VideoServiceHelper.GetThumbUrlPreferNotNico(pvs);
            ThumbUrlMaxSize = VideoServiceHelper.GetMaxSizeThumbUrl(pvs) ?? ThumbUrl;

            if (PrimaryPV == null && !string.IsNullOrEmpty(NicoId))
            {
                PrimaryPV = new PVContract {
                    PVId = NicoId, Service = PVService.NicoNicoDouga
                }
            }
            ;

            if (pvs.All(p => p.Service != PVService.Youtube))
            {
                var nicoPV = VideoServiceHelper.PrimaryPV(pvs, PVService.NicoNicoDouga);
                var query  = HttpUtility.UrlEncode((nicoPV != null && !string.IsNullOrEmpty(nicoPV.Name))
                                        ? nicoPV.Name
                                        : $"{ArtistString} {Name}");

                WebLinks.Add(new WebLinkContract($"http://www.youtube.com/results?search_query={query}",
                                                 ViewRes.Song.DetailsStrings.SearchYoutube, WebLinkCategory.Other, disabled: false));
            }

            JsonModel = new SongDetailsAjax(this, contract.PreferredLyrics, contract.Song.Version);

            MinMilliBpm = contract.MinMilliBpm;
            MaxMilliBpm = contract.MaxMilliBpm;
        }
コード例 #10
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);
        }
コード例 #11
0
        public SongDetails(SongDetailsContract contract)
        {
            ParamIs.NotNull(() => contract);

            AdditionalNames   = contract.AdditionalNames;
            Albums            = contract.Albums;
            AlternateVersions = contract.AlternateVersions.Where(a => a.SongType != SongType.Original).ToArray();
            ArtistString      = contract.ArtistString;
            CanEdit           = EntryPermissionManager.CanEdit(MvcApplication.LoginManager, contract.Song);
            CommentCount      = contract.CommentCount;
            CreateDate        = contract.CreateDate;
            Deleted           = contract.Deleted;
            Draft             = contract.Song.Status == EntryStatus.Draft;
            FavoritedTimes    = contract.Song.FavoritedTimes;
            Hits            = contract.Hits;
            Id              = contract.Song.Id;
            IsFavorited     = contract.UserRating != SongVoteRating.Nothing;
            LatestComments  = contract.LatestComments;
            LikedTimes      = contract.LikeCount;
            Lyrics          = contract.LyricsFromParents;
            Name            = contract.Song.Name;
            NicoId          = contract.Song.NicoId;
            Notes           = contract.Notes;
            OriginalVersion = (contract.Song.SongType != SongType.Original ? contract.OriginalVersion : null);
            Pools           = contract.Pools;
            RatingScore     = contract.Song.RatingScore;
            SongType        = contract.Song.SongType;
            Status          = contract.Song.Status;
            Tags            = contract.Tags;
            UserRating      = contract.UserRating;
            WebLinks        = contract.WebLinks.ToList();

            Animators    = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Animator)).ToArray();
            Performers   = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray();
            Producers    = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray();
            OtherArtists = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle) ||
                                                  a.Categories.HasFlag(ArtistCategories.Label) ||
                                                  a.Categories.HasFlag(ArtistCategories.Other)).ToArray();

            var pvs = contract.PVs;

            OriginalPVs = pvs.Where(p => p.PVType == PVType.Original).ToArray();
            OtherPVs    = pvs.Where(p => p.PVType != PVType.Original).ToArray();
            PrimaryPV   = PVHelper.PrimaryPV(pvs);

            if (PrimaryPV == null && !string.IsNullOrEmpty(NicoId))
            {
                PrimaryPV = new PVContract {
                    PVId = NicoId, Service = PVService.NicoNicoDouga
                }
            }
            ;

            var nicoPvId = PVHelper.GetNicoId(pvs, NicoId);

            if (!string.IsNullOrEmpty(nicoPvId))
            {
                WebLinks.Add(new WebLinkContract(VideoServiceUrlFactory.NicoSound.CreateUrl(nicoPvId),
                                                 ViewRes.Song.DetailsStrings.CheckNicoSound, WebLinkCategory.Other));
            }

            if (pvs.All(p => p.Service != PVService.Youtube))
            {
                var nicoPV = VideoServiceHelper.PrimaryPV(pvs, PVService.NicoNicoDouga);
                var query  = (nicoPV != null && !string.IsNullOrEmpty(nicoPV.Name))
                                        ? nicoPV.Name
                                        : string.Format("{0} {1}", ArtistString, Name);

                WebLinks.Add(new WebLinkContract(string.Format("http://www.youtube.com/results?search_query={0}", query),
                                                 ViewRes.Song.DetailsStrings.SearchYoutube, WebLinkCategory.Other));
            }
        }
コード例 #12
0
        public void CanEdit_ApprovedEntry_OwnerUser()
        {
            var result = EntryPermissionManager.CanEdit(new FakePermissionContext(_verifiedUser), _verifiedArtist);

            result.Should().BeTrue("result");
        }
コード例 #13
0
ファイル: SongModels.cs プロジェクト: sethura/vocadb
        public SongDetails(SongDetailsContract contract)
        {
            ParamIs.NotNull(() => contract);

            Contract                 = contract;
            AdditionalNames          = contract.AdditionalNames;
            Albums                   = contract.Albums;
            AlternateVersions        = contract.AlternateVersions.Where(a => a.SongType != SongType.Original).ToArray();
            ArtistString             = contract.ArtistString;
            CanEdit                  = EntryPermissionManager.CanEdit(MvcApplication.LoginManager, contract.Song);
            CommentCount             = contract.CommentCount;
            CreateDate               = contract.CreateDate;
            DefaultLanguageSelection = contract.TranslatedName.DefaultLanguage;
            Deleted                  = contract.Deleted;
            Draft           = contract.Song.Status == EntryStatus.Draft;
            FavoritedTimes  = contract.Song.FavoritedTimes;
            Hits            = contract.Hits;
            Id              = contract.Song.Id;
            IsFavorited     = contract.UserRating != SongVoteRating.Nothing;
            LatestComments  = contract.LatestComments;
            Length          = contract.Song.LengthSeconds;
            LikedTimes      = contract.LikeCount;
            ListCount       = contract.ListCount;
            Lyrics          = contract.LyricsFromParents;
            MergedTo        = contract.MergedTo;
            Name            = contract.Song.Name;
            NicoId          = contract.Song.NicoId;
            Notes           = contract.Notes;
            OriginalVersion = (contract.Song.SongType != SongType.Original ? contract.OriginalVersion : null);
            Pools           = contract.Pools;
            RatingScore     = contract.Song.RatingScore;
            SongType        = contract.Song.SongType;
            Status          = contract.Song.Status;
            Tags            = contract.Tags;
            UserRating      = contract.UserRating;
            WebLinks        = contract.WebLinks.ToList();

            Animators    = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Animator)).ToArray();
            Bands        = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Band)).ToArray();
            Performers   = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Vocalist)).ToArray();
            Producers    = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Producer)).ToArray();
            OtherArtists = contract.Artists.Where(a => a.Categories.HasFlag(ArtistCategories.Circle) ||
                                                  a.Categories.HasFlag(ArtistCategories.Label) ||
                                                  a.Categories.HasFlag(ArtistCategories.Other)).ToArray();

            var pvs = contract.PVs;

            OriginalPVs     = pvs.Where(p => p.PVType == PVType.Original).ToArray();
            OtherPVs        = pvs.Where(p => p.PVType != PVType.Original).ToArray();
            PrimaryPV       = PVHelper.PrimaryPV(pvs);
            ThumbUrl        = VideoServiceHelper.GetThumbUrlPreferNotNico(pvs);
            ThumbUrlMaxSize = VideoServiceHelper.GetMaxSizeThumbUrl(pvs) ?? ThumbUrl;

            /*var nicoMimiUrl = GetNicoMimiUrl(contract);
             * if (!string.IsNullOrEmpty(nicoMimiUrl)) {
             *      WebLinks.Add(new WebLinkContract(nicoMimiUrl, ViewRes.Song.DetailsStrings.NicoMimiDownload, WebLinkCategory.Other));
             * }*/

            if (PrimaryPV == null && !string.IsNullOrEmpty(NicoId))
            {
                PrimaryPV = new PVContract {
                    PVId = NicoId, Service = PVService.NicoNicoDouga
                }
            }
            ;

            if (pvs.All(p => p.Service != PVService.Youtube))
            {
                var nicoPV = VideoServiceHelper.PrimaryPV(pvs, PVService.NicoNicoDouga);
                var query  = HttpUtility.UrlEncode((nicoPV != null && !string.IsNullOrEmpty(nicoPV.Name))
                                        ? nicoPV.Name
                                        : string.Format("{0} {1}", ArtistString, Name));

                WebLinks.Add(new WebLinkContract(string.Format("http://www.youtube.com/results?search_query={0}", query),
                                                 ViewRes.Song.DetailsStrings.SearchYoutube, WebLinkCategory.Other));
            }
        }
コード例 #14
0
        public void CanEdit_ApprovedEntry_OwnerUser()
        {
            var result = EntryPermissionManager.CanEdit(new FakePermissionContext(verifiedUser), verifiedArtist);

            Assert.IsTrue(result, "result");
        }