Esempio n. 1
0
        public int UpdateSeries(ReleaseEventSeriesForEditContract contract)
        {
            ParamIs.NotNull(() => contract);

            PermissionContext.VerifyPermission(PermissionToken.ManageEventSeries);

            return(HandleTransaction(session => {
                ReleaseEventSeries series;

                if (contract.Id == 0)
                {
                    series = new ReleaseEventSeries(contract.Name, contract.Description, contract.Aliases);

                    session.Save(series);

                    AuditLog("created " + series, session);
                }
                else
                {
                    series = session.Load <ReleaseEventSeries>(contract.Id);

                    series.Name = contract.Name;
                    series.Description = contract.Description;
                    series.UpdateAliases(contract.Aliases);

                    AuditLog("updated " + series, session);
                }

                return series.Id;
            }));
        }
Esempio n. 2
0
        public void UpdateSeries_NoPermission()
        {
            user.GroupId = UserGroupId.Limited;
            permissionContext.RefreshLoggedUser(repository);

            var contract = new ReleaseEventSeriesForEditContract(series, ContentLanguagePreference.English);

            queries.UpdateSeries(contract, null);
        }
Esempio n. 3
0
        public void UpdateSeries_NoPermission()
        {
            user.GroupId = UserGroupId.Regular;
            permissionContext.RefreshLoggedUser(repository);

            var contract = new ReleaseEventSeriesForEditContract(series);

            queries.UpdateSeries(contract, null);
        }
Esempio n. 4
0
        public SeriesEdit(ReleaseEventSeriesForEditContract contract)
        {
            ParamIs.NotNull(() => contract);

            Aliases     = contract.Aliases.ToList();
            Description = contract.Description;
            Id          = contract.Id;
            Name        = contract.Name;
        }
Esempio n. 5
0
        public void CopyNonEditableProperties(ReleaseEventSeriesForEditContract contract, IUserPermissionContext userContext)
        {
            AllowedEntryStatuses = EntryPermissionManager.AllowedEntryStatuses(userContext).ToArray();

            if (contract != null)
            {
                Deleted = contract.Deleted;
            }
        }
Esempio n. 6
0
        public void UpdateSeries_UpdateDefaultLanguage_EventsUpdated()
        {
            var contract = new ReleaseEventSeriesForEditContract(series, ContentLanguagePreference.English)
            {
                DefaultNameLanguage = ContentLanguageSelection.Japanese
            };

            var result = queries.UpdateSeries(contract, null);

            Assert.AreEqual(ContentLanguageSelection.Japanese, existingEvent.TranslatedName.DefaultLanguage, "Default language");
        }
Esempio n. 7
0
        public void UpdateSeries_DuplicateName()
        {
            var series2 = repository.SaveWithNames <ReleaseEventSeries, EventSeriesName>(CreateEntry.EventSeries("M3.9"));

            repository.SaveWithNames <ReleaseEvent, EventName>(CreateEntry.SeriesEvent(series2, 2013, "Spring"));

            var contract = new ReleaseEventSeriesForEditContract(series, ContentLanguagePreference.English);

            contract.Names[0].Value = "M3.9";

            queries.UpdateSeries(contract, null);
        }
Esempio n. 8
0
        public void UpdateSeries_Create()
        {
            var contract = new ReleaseEventSeriesForEditContract {
                Names = Names("Comiket")
            };

            var result = queries.UpdateSeries(contract, null);

            var seriesFromRepo = repository.Load <ReleaseEventSeries>(result);

            Assert.AreEqual(2, repository.List <ReleaseEventSeries>().Count, "Number of series in repo");
            Assert.IsNotNull(seriesFromRepo, "Series was loaded successfully");
            Assert.AreEqual("Comiket", seriesFromRepo.TranslatedName.Default, "Name was updated");
        }
Esempio n. 9
0
        public void UpdateSeries_Update()
        {
            var contract = new ReleaseEventSeriesForEditContract(series);

            contract.Name = "M3.9";

            var result = queries.UpdateSeries(contract, null);

            var seriesFromRepo = repository.Load <ReleaseEventSeries>(result);

            Assert.AreEqual(1, repository.List <ReleaseEventSeries>().Count, "Number of series in repo");
            Assert.IsNotNull(seriesFromRepo, "Series was loaded successfully");
            Assert.AreEqual("M3.9", seriesFromRepo.Name, "Name was updated");
        }
Esempio n. 10
0
        public SeriesEdit(ReleaseEventSeriesForEditContract contract, IUserPermissionContext userContext)
        {
            ParamIs.NotNull(() => contract);

            Category            = contract.Category;
            Contract            = contract;
            DefaultNameLanguage = contract.DefaultNameLanguage;
            Description         = contract.Description;
            Id       = contract.Id;
            Name     = contract.Name;
            Names    = contract.Names;
            Status   = contract.Status;
            WebLinks = contract.WebLinks;

            CopyNonEditableProperties(contract, userContext);
        }
Esempio n. 11
0
        public void UpdateSeries_UpdateName_EventsUpdated()
        {
            var contract = new ReleaseEventSeriesForEditContract(series, ContentLanguagePreference.English);

            contract.Names[0].Value = "M3.9";

            var result = queries.UpdateSeries(contract, null);

            var seriesFromRepo = repository.Load <ReleaseEventSeries>(result);

            Assert.AreEqual(1, repository.List <ReleaseEventSeries>().Count, "Number of series in repo");
            Assert.IsNotNull(seriesFromRepo, "Series was loaded successfully");
            Assert.AreEqual("M3.9", seriesFromRepo.TranslatedName.Default, "Name was updated");

            Assert.AreEqual(1, existingEvent.Names.Names.Count, "Number of event names");
            Assert.AreEqual("M3.9 2013 Spring", existingEvent.Names.Names[0].Value, "Event name value");
        }
Esempio n. 12
0
        public int UpdateSeries(ReleaseEventSeriesForEditContract contract, EntryPictureFileContract pictureData)
        {
            ParamIs.NotNull(() => contract);

            PermissionContext.VerifyManageDatabase();

            return(HandleTransaction(session => {
                ReleaseEventSeries series;

                if (contract.Id == 0)
                {
                    series = new ReleaseEventSeries(contract.DefaultNameLanguage, contract.Names, contract.Description)
                    {
                        Category = contract.Category,
                        Status = contract.Status
                    };
                    session.Save(series);

                    var diff = new ReleaseEventSeriesDiff(ReleaseEventSeriesEditableFields.OriginalName | ReleaseEventSeriesEditableFields.Names);

                    diff.Description.Set(!string.IsNullOrEmpty(contract.Description));

                    var weblinksDiff = WebLink.Sync(series.WebLinks, contract.WebLinks, series);

                    if (weblinksDiff.Changed)
                    {
                        diff.WebLinks.Set();
                        session.OfType <ReleaseEventWebLink>().Sync(weblinksDiff);
                    }

                    if (pictureData != null)
                    {
                        diff.Picture.Set();
                        SaveImage(series, pictureData);
                        session.Update(series);
                    }

                    session.Update(series);

                    Archive(session, series, diff, EntryEditEvent.Created, string.Empty);

                    AuditLog(string.Format("created {0}", entryLinkFactory.CreateEntryLink(series)), session);
                }
                else
                {
                    series = session.Load <ReleaseEventSeries>(contract.Id);
                    permissionContext.VerifyEntryEdit(series);
                    var diff = new ReleaseEventSeriesDiff(ReleaseEventSeriesEditableFields.Nothing);

                    if (series.TranslatedName.DefaultLanguage != contract.DefaultNameLanguage)
                    {
                        series.TranslatedName.DefaultLanguage = contract.DefaultNameLanguage;
                        diff.OriginalName.Set();
                    }

                    var nameDiff = series.Names.Sync(contract.Names, series);
                    session.Sync(nameDiff);

                    if (nameDiff.Changed)
                    {
                        diff.Names.Set();
                    }


                    if (series.Category != contract.Category)
                    {
                        diff.Category.Set();
                        series.Category = contract.Category;
                    }

                    if (series.Description != contract.Description)
                    {
                        diff.Description.Set();
                        series.Description = contract.Description;
                    }

                    if (series.Status != contract.Status)
                    {
                        diff.Status.Set();
                        series.Status = contract.Status;
                    }

                    if (pictureData != null)
                    {
                        diff.Picture.Set();
                        SaveImage(series, pictureData);
                    }

                    var weblinksDiff = WebLink.Sync(series.WebLinks, contract.WebLinks, series);

                    if (weblinksDiff.Changed)
                    {
                        diff.WebLinks.Set();
                        session.OfType <ReleaseEventWebLink>().Sync(weblinksDiff);
                    }

                    session.Update(series);

                    if (diff.Names.IsChanged || diff.OriginalName.IsChanged)
                    {
                        var eventNamesQuery = new UpdateEventNamesQuery();
                        foreach (var ev in series.Events.Where(e => !e.CustomName))
                        {
                            eventNamesQuery.UpdateNames(session, ev, series, ev.CustomName, ev.SeriesNumber, ev.SeriesSuffix, ev.Names);
                            session.Update(ev);
                        }
                    }

                    Archive(session, series, diff, EntryEditEvent.Updated, string.Empty);

                    AuditLog(string.Format("updated {0}", entryLinkFactory.CreateEntryLink(series)), session);
                }

                return series.Id;
            }));
        }
Esempio n. 13
0
        public int UpdateSeries(ReleaseEventSeriesForEditContract contract, EntryPictureFileContract pictureData)
        {
            ParamIs.NotNull(() => contract);

            PermissionContext.VerifyPermission(PermissionToken.ManageEventSeries);

            return(HandleTransaction(session => {
                ReleaseEventSeries series;

                if (contract.Id == 0)
                {
                    series = new ReleaseEventSeries(contract.Name, contract.Description, contract.Aliases);
                    session.Save(series);

                    var diff = new ReleaseEventSeriesDiff(ReleaseEventSeriesEditableFields.Name);

                    diff.Description.Set(!string.IsNullOrEmpty(contract.Description));
                    diff.Names.Set(contract.Aliases.Any());

                    var weblinksDiff = WebLink.Sync(series.WebLinks, contract.WebLinks, series);

                    if (weblinksDiff.Changed)
                    {
                        diff.WebLinks.Set();
                        session.OfType <ReleaseEventWebLink>().Sync(weblinksDiff);
                    }

                    if (pictureData != null)
                    {
                        diff.Picture.Set();
                        SaveImage(series, pictureData);
                        session.Update(series);
                    }

                    session.Update(series);

                    Archive(session, series, diff, EntryEditEvent.Created, string.Empty);

                    AuditLog(string.Format("created {0}", entryLinkFactory.CreateEntryLink(series)), session);
                }
                else
                {
                    series = session.Load <ReleaseEventSeries>(contract.Id);
                    var diff = new ReleaseEventSeriesDiff(ReleaseEventSeriesEditableFields.Name);

                    if (series.Name != contract.Name)
                    {
                        diff.Name.Set();
                        series.Name = contract.Name;
                    }

                    if (series.Description != contract.Description)
                    {
                        diff.Description.Set();
                        series.Description = contract.Description;
                    }

                    if (series.UpdateAliases(contract.Aliases))
                    {
                        diff.Names.Set();
                    }

                    if (pictureData != null)
                    {
                        diff.Picture.Set();
                        SaveImage(series, pictureData);
                    }

                    var weblinksDiff = WebLink.Sync(series.WebLinks, contract.WebLinks, series);

                    if (weblinksDiff.Changed)
                    {
                        diff.WebLinks.Set();
                        session.OfType <ReleaseEventWebLink>().Sync(weblinksDiff);
                    }

                    session.Update(series);

                    Archive(session, series, diff, EntryEditEvent.Updated, string.Empty);

                    AuditLog(string.Format("updated {0}", entryLinkFactory.CreateEntryLink(series)), session);
                }

                return series.Id;
            }));
        }