public static ActionResultRepresentation Create(IOidStrategy oidStrategy, HttpRequestMessage req, ActionResultContextFacade actionResult, RestControlFlags flags) { if (actionResult.HasResult) { IRepresentation result; if (actionResult.Result == null) { result = null; } else if (actionResult.Specification.IsParseable) { result = ScalarRepresentation.Create(oidStrategy, actionResult.Result, req, flags); } else if (actionResult.Specification.IsObject) { result = ObjectRepresentation.Create(oidStrategy, actionResult.Result, req, flags); } else { result = PagedListRepresentation.Create(oidStrategy, actionResult, req, flags); } return(CreateWithOptionals <ActionResultRepresentation>(new object[] { oidStrategy, req, actionResult, flags }, new[] { new OptionalProperty(JsonPropertyNames.Result, result) })); } return(new ActionResultRepresentation(oidStrategy, req, actionResult, flags)); }
public static ActionResultRepresentation Create(IOidStrategy oidStrategy, HttpRequest req, ActionResultContextFacade actionResult, RestControlFlags flags) { if (!actionResult.HasResult) { return(new ActionResultRepresentation(oidStrategy, req, actionResult, flags)); } IRepresentation result = actionResult switch { _ when actionResult.Result == null => null, _ when actionResult.Specification.IsParseable => ScalarRepresentation.Create(oidStrategy, actionResult.Result, req, flags), _ when actionResult.Specification.IsObject => ObjectRepresentation.Create(oidStrategy, actionResult.Result, req, flags), _ => PagedListRepresentation.Create(oidStrategy, actionResult, req, flags) }; return(CreateWithOptionals <ActionResultRepresentation>(new object[] { oidStrategy, req, actionResult, flags }, new[] { new OptionalProperty(JsonPropertyNames.Result, result) })); } }
public static object GetPropertyValue(IOidStrategy oidStrategy, HttpRequest req, IAssociationFacade property, IObjectFacade target, RestControlFlags flags, bool valueOnly, bool useDateOverDateTime) { var valueNakedObject = property.GetValue(target); if (valueNakedObject == null) { return(null); } if (target.IsTransient && property.IsUsable(target).IsAllowed&& property.IsVisible(target) && property.IsSetToImplicitDefault(target)) { return(null); } if (property.Specification.IsParseable || property.Specification.IsCollection) { return(RestUtils.ObjectToPredefinedType(valueNakedObject.Object, useDateOverDateTime)); } if (valueOnly) { return(RefValueRepresentation.Create(oidStrategy, new ValueRelType(property, new UriMtHelper(oidStrategy, req, valueNakedObject)), flags)); } var title = RestUtils.SafeGetTitle(property, valueNakedObject); 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())); }