Esempio n. 1
0
        public void SetUp()
        {
            artist     = CreateEntry.Producer(name: "Tripshots");
            vocalist   = CreateEntry.Vocalist(name: "Hatsune Miku");
            repository = new FakeArtistRepository(artist, vocalist);
            var weblink = new ArtistWebLink(artist, "Website", "http://tripshots.net", WebLinkCategory.Official);

            artist.WebLinks.Add(weblink);
            repository.Save(weblink);
            repository.SaveNames(artist, vocalist);

            user = CreateEntry.User(name: "Miku", group: UserGroupId.Moderator);
            repository.Save(user);
            permissionContext = new FakePermissionContext(user);
            imagePersister    = new InMemoryImagePersister();

            queries = new ArtistQueries(repository, permissionContext, new FakeEntryLinkFactory(), imagePersister, imagePersister, MemoryCache.Default,
                                        new FakeUserIconFactory(), new EnumTranslations());

            newArtistContract = new CreateArtistContract {
                ArtistType  = ArtistType.Producer,
                Description = string.Empty,
                Names       = new[] {
                    new LocalizedStringContract("Tripshots", ContentLanguageSelection.English)
                },
                WebLink = new WebLinkContract("http://tripshots.net/", "Website", WebLinkCategory.Official)
            };
        }
Esempio n. 2
0
        public void SetUp()
        {
            artist     = CreateEntry.Producer(name: "Tripshots");
            repository = new FakeArtistRepository(artist);

            foreach (var name in artist.Names)
            {
                repository.Save(name);
            }

            user = CreateEntry.User(name: "Miku");
            repository.Save(user);
            permissionContext = new FakePermissionContext(user);
            imagePersister    = new InMemoryImagePersister();

            queries = new ArtistQueries(repository, permissionContext, new FakeEntryLinkFactory(), imagePersister, imagePersister, MemoryCache.Default);

            newArtistContract = new CreateArtistContract {
                ArtistType  = ArtistType.Producer,
                Description = string.Empty,
                Names       = new[] {
                    new LocalizedStringContract("Tripshots", ContentLanguageSelection.English)
                },
                WebLink = new WebLinkContract("http://tripshots.net/", "Website", WebLinkCategory.Official)
            };
        }
Esempio n. 3
0
        public async Task <ArtistContract> Create(CreateArtistContract contract)
        {
            ParamIs.NotNull(() => contract);

            if (contract.Names == null || !contract.Names.Any())
            {
                throw new ArgumentException("Artist needs at least one name", "contract");
            }

            VerifyManageDatabase();

            var diff = new ArtistDiff();

            diff.Names.Set();

            return(await repository.HandleTransactionAsync(async ctx => {
                ctx.AuditLogger.SysLog(string.Format("creating a new artist with name '{0}'", contract.Names.First().Value));

                var artist = new Artist {
                    ArtistType = contract.ArtistType,
                    Description = new EnglishTranslatedString(contract.Description.Trim())
                };

                artist.Names.Init(contract.Names, artist);

                if (contract.WebLink != null)
                {
                    artist.CreateWebLink(contract.WebLink.Description, contract.WebLink.Url, contract.WebLink.Category);
                    diff.WebLinks.Set();
                }

                artist.Status = (contract.Draft || !(new ArtistValidator().IsValid(artist))) ? EntryStatus.Draft : EntryStatus.Finished;

                await ctx.SaveAsync(artist);

                if (contract.PictureData != null)
                {
                    var pictureData = contract.PictureData;
                    var parsed = ImageHelper.GetOriginal(pictureData.UploadedFile, pictureData.ContentLength, pictureData.Mime);
                    artist.Picture = new PictureData(parsed);
                    artist.PictureMime = parsed.Mime;

                    pictureData.Id = artist.Id;
                    pictureData.EntryType = EntryType.Artist;
                    var thumbGenerator = new ImageThumbGenerator(imagePersister);
                    thumbGenerator.GenerateThumbsAndMoveImage(pictureData.UploadedFile, pictureData, ImageSizes.Thumb | ImageSizes.SmallThumb | ImageSizes.TinyThumb);

                    diff.Picture.Set();
                }

                var archived = await ArchiveAsync(ctx, artist, diff, ArtistArchiveReason.Created);
                await ctx.UpdateAsync(artist);

                await ctx.AuditLogger.AuditLogAsync(string.Format("created artist {0} ({1})", entryLinkFactory.CreateEntryLink(artist), artist.ArtistType));
                await AddEntryEditedEntryAsync(ctx.OfType <ActivityEntry>(), artist, EntryEditEvent.Created, archived);

                return new ArtistContract(artist, PermissionContext.LanguagePreference);
            }));
        }
Esempio n. 4
0
        public ArtistContract Create(CreateArtistContract contract)
        {
            ParamIs.NotNull(() => contract);

            if (contract.Names == null || !contract.Names.Any())
            {
                throw new ArgumentException("Artist needs at least one name", "contract");
            }

            VerifyManageDatabase();

            return(HandleTransaction(session => {
                SysLog(string.Format("creating a new artist with name '{0}'", contract.Names.First().Value));

                var artist = new Artist {
                    ArtistType = contract.ArtistType,
                    Description = contract.Description.Trim(),
                    Status = contract.Draft ? EntryStatus.Draft : EntryStatus.Finished
                };

                artist.Names.Init(contract.Names, artist);

                if (contract.PictureData != null)
                {
                    artist.Picture = new PictureData(contract.PictureData);
                }

                if (contract.WebLink != null)
                {
                    artist.CreateWebLink(contract.WebLink.Description, contract.WebLink.Url, contract.WebLink.Category);
                }

                session.Save(artist);

                Archive(session, artist, ArtistArchiveReason.Created);
                session.Update(artist);

                AuditLog(string.Format("created {0}", EntryLinkFactory.CreateEntryLink(artist)), session);
                AddEntryEditedEntry(session, artist, EntryEditEvent.Created);

                return new ArtistContract(artist, PermissionContext.LanguagePreference);
            }));
        }
Esempio n. 5
0
        public void SetUp()
        {
            _artist     = CreateEntry.Producer(name: "Tripshots");
            _vocalist   = CreateEntry.Vocalist(name: "Hatsune Miku");
            _repository = new FakeArtistRepository(_artist, _vocalist);
            var weblink = new ArtistWebLink(_artist, "Website", "http://tripshots.net", WebLinkCategory.Official, disabled: false);

            _artist.WebLinks.Add(weblink);
            _repository.Save(weblink);
            _repository.SaveNames(_artist, _vocalist);

            _user  = CreateEntry.User(name: "Miku", group: UserGroupId.Moderator);
            _user2 = CreateEntry.User(name: "Rin", group: UserGroupId.Regular);
            _repository.Save(_user);
            _permissionContext = new FakePermissionContext(_user);
            _imagePersister    = new InMemoryImagePersister();

            _queries = new ArtistQueries(
                _repository,
                _permissionContext,
                new FakeEntryLinkFactory(),
                _imagePersister,
                _imagePersister,
                MemoryCache.Default,
                new FakeUserIconFactory(),
                new EnumTranslations(),
                _imagePersister,
                new FakeDiscordWebhookNotifier());

            _newArtistContract = new CreateArtistContract
            {
                ArtistType  = ArtistType.Producer,
                Description = string.Empty,
                Names       = new[] {
                    new LocalizedStringContract("Tripshots", ContentLanguageSelection.English)
                },
                WebLink = new WebLinkContract("http://tripshots.net/", "Website", WebLinkCategory.Official, disabled: false)
            };
        }