public static ActionResultRepresentation Create(HttpRequestMessage req, ActionResultContextSurface actionResult, RestControlFlags flags) { if (actionResult.HasResult) { IRepresentation result; if (actionResult.Result == null) { result = null; } else if (actionResult.Specification.IsParseable()) { result = ScalarRepresentation.Create(actionResult.Result, req, flags); } else if (actionResult.Specification.IsObject()) { result = ObjectRepresentation.Create(actionResult.Result, req, flags); } else { result = ListRepresentation.Create(actionResult, req, flags); } return(CreateWithOptionals <ActionResultRepresentation>(new object[] { req, actionResult, flags }, new[] { new OptionalProperty(JsonPropertyNames.Result, result) })); } return(new ActionResultRepresentation(req, actionResult, flags)); }
protected static object GetPropertyValue(IOidStrategy oidStrategy, HttpRequestMessage req, IAssociationFacade property, IObjectFacade target, RestControlFlags flags, bool valueOnly = false) { IObjectFacade valueNakedObject = property.GetValue(target); string title = RestUtils.SafeGetTitle(property, valueNakedObject); if (valueNakedObject == null) { return(null); } if (property.Specification.IsParseable || property.Specification.IsCollection) { return(RestUtils.ObjectToPredefinedType(valueNakedObject.GetDomainObject())); } if (valueOnly) { return(RefValueRepresentation.Create(oidStrategy, new ValueRelType(property, new UriMtHelper(oidStrategy, req, valueNakedObject)), flags)); } var helper = new UriMtHelper(oidStrategy, req, property.IsInline ? target : valueNakedObject); var optionals = new List <OptionalProperty> { new OptionalProperty(JsonPropertyNames.Title, title) }; if (property.IsEager(target)) { optionals.Add(new OptionalProperty(JsonPropertyNames.Value, ObjectRepresentation.Create(oidStrategy, valueNakedObject, req, flags))); } return(LinkRepresentation.Create(oidStrategy, new ValueRelType(property, helper), flags, optionals.ToArray())); }