private static RefValueRepresentation CreateObjectRef(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade no, RestControlFlags flags) { var helper = new UriMtHelper(oidStrategy, req, no); ObjectRelType rt = new ObjectRelType(RelValues.Element, helper); return(RefValueRepresentation.Create(oidStrategy, rt, 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())); }
private static MapRepresentation GetMap(IOidStrategy oidStrategy, HttpRequestMessage req, ContextFacade context, RestControlFlags flags) { MapRepresentation value; // All reasons why we cannot create a linkrep if (context.Specification.IsParseable || context.Specification.IsCollection || context.ProposedValue == null || context.ProposedObjectFacade == null || context.ProposedObjectFacade.Specification.IsParseable) { value = CreateMap(context, context.ProposedValue); } else { value = CreateMap(context, RefValueRepresentation.Create(oidStrategy, new ObjectRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, context.ProposedObjectFacade)), flags)); } return(value); }
private static MapRepresentation GetMap(HttpRequestMessage req, ContextSurface context, RestControlFlags flags) { MapRepresentation value; // All reasons why we cannot create a linkrep if (context.Specification.IsParseable() || context.Specification.IsCollection() || context.ProposedValue == null || context.ProposedNakedObject == null || context.ProposedNakedObject.Specification.IsParseable()) { value = CreateMap(context, context.ProposedValue); } else { value = CreateMap(context, RefValueRepresentation.Create(new ObjectRelType(RelValues.Self, new UriMtHelper(req, context.ProposedNakedObject)), flags)); } return(value); }
private MapRepresentation CreateArguments(HttpRequestMessage req, ActionResultContextSurface actionResult) { var optionalProperties = new List <OptionalProperty>(); foreach (ParameterContextSurface visibleParamContext in actionResult.ActionContext.VisibleParameters) { IRepresentation value; if (visibleParamContext.Specification.IsParseable()) { object proposedObj = visibleParamContext.ProposedNakedObject == null ? visibleParamContext.ProposedValue : visibleParamContext.ProposedNakedObject.Object; object valueObj = RestUtils.ObjectToPredefinedType(proposedObj); value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueObj)); } else if (visibleParamContext.Specification.IsCollection()) { if (visibleParamContext.ElementSpecification.IsParseable()) { var proposedCollection = ((IEnumerable)(visibleParamContext.ProposedNakedObject == null ? visibleParamContext.ProposedValue : visibleParamContext.ProposedNakedObject.Object)).Cast <object>(); var valueObjs = proposedCollection.Select(RestUtils.ObjectToPredefinedType).ToArray(); value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueObjs)); } else { var refNos = visibleParamContext.ProposedNakedObject.ToEnumerable().Select(no => no).ToArray(); var refs = refNos.Select(no => RefValueRepresentation.Create(new ObjectRelType(RelValues.Self, new UriMtHelper(req, no)), Flags)).ToArray(); value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, refs)); } } else { var valueRef = RefValueRepresentation.Create(new ObjectRelType(RelValues.Self, new UriMtHelper(req, visibleParamContext.ProposedNakedObject)), Flags); value = MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, valueRef)); } optionalProperties.Add(new OptionalProperty(visibleParamContext.Id, value)); } return(MapRepresentation.Create(optionalProperties.ToArray())); }
private static MapRepresentation GetMap(IOidStrategy oidStrategy, HttpRequestMessage req, ContextFacade context, RestControlFlags flags) { MapRepresentation value; // All reasons why we cannot create a linkrep if (context.Specification.IsCollection && context.ElementSpecification != null && !context.ElementSpecification.IsParseable) { var proposedObjectFacade = oidStrategy.FrameworkFacade.GetObject(context.ProposedValue); var coll = proposedObjectFacade.ToEnumerable().Select(no => CreateObjectRef(oidStrategy, req, no, flags)).ToArray(); value = CreateMap(context, coll); } else if (context.Specification.IsParseable || context.ProposedValue == null || context.ProposedObjectFacade == null || context.ProposedObjectFacade.Specification.IsParseable) { value = CreateMap(context, context.ProposedValue); } else { value = CreateMap(context, RefValueRepresentation.Create(oidStrategy, new ObjectRelType(RelValues.Self, new UriMtHelper(oidStrategy, req, context.ProposedObjectFacade)), flags)); } return(value); }