Created
February 11, 2015 05:14
-
-
Save hyrmn/56173eba0aa00d54ab39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var units = imageMetadata.Units.Some() ? imageMetadata.Units : new Dictionary<string, int>(); | |
| var ratePlans = imageMetadata.RatePlans.Some() ? imageMetadata.RatePlans : new Dictionary<string, int>(); | |
| var relatedDocuments = units.Concat(ratePlans); | |
| var patchCommands = new List<ScriptedPatchCommandData>(); | |
| foreach (var relatedDocument in relatedDocuments) | |
| { | |
| var photo = new Photo | |
| { | |
| Url = imageMetadata.Id, | |
| Title = imageMetadata.Title, | |
| Description = imageMetadata.Description, | |
| SortOrder = relatedDocument.Value, | |
| }; | |
| patchCommands.Add(new ScriptedPatchCommandData | |
| { | |
| Key = relatedDocument.Key, | |
| Patch = new ScriptedPatchRequest() | |
| { | |
| Script = @" | |
| if(!_.has(this, 'Photos')) { | |
| _.extend(this, { 'Photos': []}); | |
| } | |
| this.Photos.RemoveWhere(function(photo) { | |
| return photo.Url === url; | |
| }); | |
| this.Photos.push(newPhoto);", | |
| Values = | |
| { | |
| {"url", imageMetadata.Id}, | |
| {"newPhoto", RavenJObject.FromObject(photo)} | |
| } | |
| } | |
| }); | |
| } | |
| _session.Advanced.GetDatabaseCommands().Batch(patchCommands); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment