public ExhibitPageResult(ExhibitPage page) { Id = page.Id; Type = page.Type; Title = page.Title; Text = page.Text; Description = page.Description; FontFamily = page.FontFamily; UserId = page.UserId; Audio = (int?)page.Audio.Id; AdditionalInformationPages = page.AdditionalInformationPages.Ids.Select(id => (int)id).ToList(); Status = page.Status; Timestamp = page.Timestamp; Used = page.Referencers.Count > 0; // a page is in use if it is referenced by an exhibit or page // properties only valid for certain page types: if (page.Type == PageType.Image_Page) { // 'image' only allowed for type IMAGE_PAGE Image = (int?)page.Image.Id; } if (page.Type == PageType.Slider_Page) { // 'images' and 'hideYearNumbers' only allowed for type SLIDER_PAGE Images = page.Images?.Select(img => new SliderPageImageResult(img)).ToArray() ?? Array.Empty <SliderPageImageResult>(); HideYearNumbers = page.HideYearNumbers; } }
private void ApplyEvent(IEvent ev) { if (ev is ICrudEvent crudEvent) { var entity = (crudEvent.GetEntityType(), crudEvent.Id); if (crudEvent is IDeleteEvent) { ClearIncomingReferences(entity); ClearOutgoingReferences(entity); } else if (crudEvent is IUpdateEvent) { ClearOutgoingReferences(entity); } } switch (ev) { case ExhibitCreated e: var newExhibit = new Exhibit(e.Properties) { Id = e.Id, UserId = e.UserId, Timestamp = e.Timestamp }; _db.GetCollection <Exhibit>(ResourceType.Exhibit.Name).InsertOne(newExhibit); break; case ExhibitUpdated e: var originalExhibit = _db.GetCollection <Exhibit>(ResourceType.Exhibit.Name).AsQueryable().First(x => x.Id == e.Id); var updatedExhibit = new Exhibit(e.Properties) { Id = e.Id, UserId = originalExhibit.UserId, Timestamp = e.Timestamp }; updatedExhibit.Referencers.AddRange(originalExhibit.Referencers); _db.GetCollection <Exhibit>(ResourceType.Exhibit.Name).ReplaceOne(x => x.Id == e.Id, updatedExhibit); break; case ExhibitDeleted e: MarkDeleted <Exhibit>(ResourceType.Exhibit, e.Id); break; case ExhibitPageCreated3 e: var newPage = new ExhibitPage(e.Properties) { Id = e.Id, UserId = e.UserId, Timestamp = e.Timestamp }; _db.GetCollection <ExhibitPage>(ResourceType.ExhibitPage.Name).InsertOne(newPage); break; case ExhibitPageUpdated3 e: var originalPage = _db.GetCollection <ExhibitPage>(ResourceType.ExhibitPage.Name).AsQueryable().First(x => x.Id == e.Id); var updatedPage = new ExhibitPage(e.Properties) { Id = e.Id, UserId = originalPage.UserId, Timestamp = e.Timestamp }; updatedPage.Referencers.AddRange(originalPage.Referencers); _db.GetCollection <ExhibitPage>(ResourceType.ExhibitPage.Name).ReplaceOne(x => x.Id == e.Id, updatedPage); break; case ExhibitPageDeleted2 e: MarkDeleted <ExhibitPage>(ResourceType.ExhibitPage, e.Id); break; case RouteCreated e: var newRoute = new Route(e.Properties) { Id = e.Id, UserId = e.UserId, Timestamp = e.Timestamp }; _db.GetCollection <Route>(ResourceType.Route.Name).InsertOne(newRoute); break; case RouteUpdated e: var originalRoute = _db.GetCollection <Route>(ResourceType.Route.Name).AsQueryable().First(x => x.Id == e.Id); var updatedRoute = new Route(e.Properties) { Id = e.Id, UserId = originalRoute.UserId, Timestamp = e.Timestamp }; updatedRoute.Referencers.AddRange(originalRoute.Referencers); _db.GetCollection <Route>(ResourceType.Route.Name).ReplaceOne(r => r.Id == e.Id, updatedRoute); break; case RouteDeleted e: MarkDeleted <Route>(ResourceType.Route, e.Id); break; case MediaCreated e: var newMedia = new MediaElement(e.Properties) { Id = e.Id, UserId = e.UserId, Timestamp = e.Timestamp }; _db.GetCollection <MediaElement>(ResourceType.Media.Name).InsertOne(newMedia); break; case MediaUpdate e: var originalMedia = _db.GetCollection <MediaElement>(ResourceType.Media.Name).AsQueryable().First(x => x.Id == e.Id); var updatedMedia = new MediaElement(e.Properties) { Id = e.Id, UserId = originalMedia.UserId, Timestamp = e.Timestamp }; updatedMedia.Referencers.AddRange(originalMedia.Referencers); updatedMedia.File = originalMedia.File; _db.GetCollection <MediaElement>(ResourceType.Media.Name).ReplaceOne(m => m.Id == e.Id, updatedMedia); break; case MediaDeleted e: MarkDeleted <MediaElement>(ResourceType.Media, e.Id); break; case MediaFileUpdated e: var fileDocBson = e.ToBsonDocument(); fileDocBson.Remove("_id"); var bsonDoc = new BsonDocument("$set", fileDocBson); _db.GetCollection <MediaElement>(ResourceType.Media.Name).UpdateOne(x => x.Id == e.Id, bsonDoc); break; case TagCreated e: var newTag = new Tag(e.Properties) { Id = e.Id, UserId = e.UserId, Timestamp = e.Timestamp, }; _db.GetCollection <Tag>(ResourceType.Tag.Name).InsertOne(newTag); break; case TagUpdated e: var originalTag = _db.GetCollection <Tag>(ResourceType.Tag.Name).AsQueryable().First(x => x.Id == e.Id); var updatedTag = new Tag(e.Properties) { Id = e.Id, UserId = originalTag.UserId, Timestamp = e.Timestamp, }; updatedTag.Referencers.AddRange(originalTag.Referencers); _db.GetCollection <Tag>(ResourceType.Tag.Name).ReplaceOne(x => x.Id == e.Id, updatedTag); break; case TagDeleted e: MarkDeleted <Tag>(ResourceType.Tag, e.Id); break; case ScoreAdded e: var newScoreRecord = new ScoreRecord { Id = e.Id, UserId = e.UserId, Score = e.Score, Timestamp = e.Timestamp }; _db.GetCollection <ScoreRecord>(ResourceType.ScoreRecord.Name).InsertOne(newScoreRecord); break; } if (ev is ICreateEvent createEvent) { AddReferences((createEvent.GetEntityType(), createEvent.Id), createEvent.GetReferences()); } else if (ev is IUpdateEvent updateEvent) { AddReferences((updateEvent.GetEntityType(), updateEvent.Id), updateEvent.GetReferences()); } }