Пример #1
0
        public ArchivedVenueContract(Venue venue, VenueDiff diff)
        {
            ParamIs.NotNull(() => venue);

            Address            = venue.Address;
            AddressCountryCode = venue.AddressCountryCode;
            Coordinates        = new OptionalGeoPointContract(venue.Coordinates);
            Description        = venue.Description;
            Id             = venue.Id;
            Names          = diff.IncludeNames ? venue.Names.Names.Select(n => new LocalizedStringContract(n)).ToArray() : null;
            TranslatedName = new ArchivedTranslatedStringContract(venue.TranslatedName);
            WebLinks       = diff.IncludeWebLinks ? venue.WebLinks.Links.Select(l => new ArchivedWebLinkContract(l)).ToArray() : null;
        }
Пример #2
0
        private ArchivedVenueVersion Archive(IDatabaseContext <Venue> ctx, Venue venue, VenueDiff diff, EntryEditEvent reason, string notes)
        {
            var agentLoginData = ctx.OfType <User>().CreateAgentLoginData(_permissionContext);
            var archived       = ArchivedVenueVersion.Create(venue, diff, agentLoginData, reason, notes);

            ctx.Save(archived);
            return(archived);
        }
Пример #3
0
        public int Update(VenueForEditContract contract)
        {
            ParamIs.NotNull(() => contract);

            PermissionContext.VerifyManageDatabase();

            return(HandleTransaction(ctx =>
            {
                Venue venue;

                if (contract.Id == 0)
                {
                    venue = new Venue(contract.DefaultNameLanguage, contract.Names, contract.Description)
                    {
                        Address = contract.Address,
                        AddressCountryCode = contract.AddressCountryCode,
                        Coordinates = (contract.Coordinates != null) ? new OptionalGeoPoint(contract.Coordinates) : new OptionalGeoPoint(),
                        Status = contract.Status
                    };
                    ctx.Save(venue);

                    var diff = new VenueDiff(VenueEditableFields.OriginalName | VenueEditableFields.Names);

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

                    if (contract.Coordinates != null)
                    {
                        diff.Coordinates.Set();
                    }

                    var webLinkDiff = venue.WebLinks.Sync(contract.WebLinks, venue);
                    ctx.OfType <VenueWebLink>().Sync(webLinkDiff);

                    if (webLinkDiff.Changed)
                    {
                        diff.WebLinks.Set();
                    }

                    ctx.Update(venue);

                    var archived = Archive(ctx, venue, diff, EntryEditEvent.Created, string.Empty);
                    AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), venue, EntryEditEvent.Created, archived);

                    AuditLog($"created {_entryLinkFactory.CreateEntryLink(venue)}", ctx);
                }
                else
                {
                    venue = ctx.Load <Venue>(contract.Id);
                    _permissionContext.VerifyEntryEdit(venue);
                    var diff = new VenueDiff(DoSnapshot(venue, ctx));

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

                    var nameDiff = venue.Names.Sync(contract.Names, venue);
                    ctx.Sync(nameDiff);

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

                    if (venue.Address != contract.Address)
                    {
                        diff.Address.Set();
                        venue.Address = contract.Address;
                    }

                    if (venue.AddressCountryCode != contract.AddressCountryCode)
                    {
                        diff.AddressCountryCode.Set();
                        venue.AddressCountryCode = contract.AddressCountryCode;
                    }

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

                    if (!venue.Coordinates.Equals(contract.Coordinates))
                    {
                        diff.Coordinates.Set();
                        venue.Coordinates = (contract.Coordinates != null) ? new OptionalGeoPoint(contract.Coordinates) : new OptionalGeoPoint();
                    }

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

                    var webLinkDiff = venue.WebLinks.Sync(contract.WebLinks, venue);
                    ctx.OfType <VenueWebLink>().Sync(webLinkDiff);

                    if (webLinkDiff.Changed)
                    {
                        diff.WebLinks.Set();
                    }

                    ctx.Update(venue);

                    var archived = Archive(ctx, venue, diff, EntryEditEvent.Updated, string.Empty);
                    AddEntryEditedEntry(ctx.OfType <ActivityEntry>(), venue, EntryEditEvent.Updated, archived);

                    AuditLog($"updated {_entryLinkFactory.CreateEntryLink(venue)}", ctx);
                }

                return venue.Id;
            }));
        }