Last active
December 14, 2015 07:39
-
-
Save jmarnold/5052180 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
| public class CaseSnapshotFlattener : ICaseSnapshotFlattener | |
| { | |
| private readonly IProjectionRunner _runner; | |
| public CaseSnapshotFlattener(IProjectionRunner runner) | |
| { | |
| _runner = runner; | |
| } | |
| public IDictionary<string, object> ToJson(CaseSnapshot model) | |
| { | |
| var node = new DictionaryMediaNode(); | |
| _runner.Run(new CaseSnapshotProjection(), model, node); | |
| return node.Values; | |
| } | |
| } |
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
| public class CaseSnapshotProjection : Projection<CaseSnapshot> | |
| { | |
| public CaseSnapshotProjection() | |
| : base(DisplayFormatting.UseDisplayFormatting) | |
| { | |
| Value(x => x.Id); | |
| Value(x => x.ScheduledTime); | |
| Value(x => x.IsAddOn).FormattedBy(listValue => listValue.Value == AddOnList.Yes); | |
| Value(x => x.Cancelled).FormattedBy(x => x.IsTrue); | |
| ForAttribute("Title").Use(context => | |
| { | |
| var lookup = context.Service<UserLookup>(); | |
| var lastName = lookup.PersonFor(context.Subject.Surgeon1.Value).LastName; | |
| return "{0}, {1}".ToFormat(lastName, context.Subject.ScheduledTime.Value.ToString("hhmm")); | |
| }); | |
| ForAttribute("ShortTitle").Use(context => "{0}, {1}".ToFormat( | |
| context.Subject.ScheduledTime.Value.ToString("hhmm"), | |
| context.Subject.CaseCode)); | |
| Value(x => x.Id).Name("url").WriteUrlFor(guid => new ViewCaseSnapshot{ | |
| Id = guid | |
| }); | |
| Value(x => x.Id).Name("mobileUrl").WriteUrlFor(id => new MobileViewCaseSnapshot{ | |
| Id = id | |
| }); | |
| ForAttribute("Timestamps").Use(context => TimestampJson.ToJson(context.Subject.Data)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment