public override TPostResponseResource Post(IPostForm form) { var requestOptions = new RequestOptions(); AddEtagOptions(requestOptions); return((TPostResponseResource)Client.Post(Uri, (TResource)((object)form), requestOptions)); }
public virtual object SaveResourceFromForm(IPostForm form) { var formType = form.GetType(); var resourceInterface = this.GetMostInheritedResourceInterface(formType); ResourceInfoAttribute resInfo; if (!TryGetResourceInfoForType(resourceInterface, out resInfo)) { throw new InvalidOperationException("Unable to get resource info for " + formType.FullName); } var resource = Activator.CreateInstance(resInfo.PocoType); foreach (var formProp in formType.GetProperties()) { if (form.PropertyIsSerialized(formProp.Name)) { var resProp = resInfo.PocoType.GetProperty(formProp.Name); var value = formProp.GetValue(form, null); if (value != null) { Type valueType = value.GetType(); if (value is PostResourceBase) { value = SaveResourceFromForm((PostResourceBase)value); } else if (valueType != typeof(string)) { Type elementType; Type[] dictTypeArgs; if (valueType.TryExtractTypeArguments(typeof(IDictionary <,>), out dictTypeArgs)) { value = mapFormDictionaryToResourceDictionaryMethod .MakeGenericMethod(dictTypeArgs) .Invoke(this, new[] { value }); } else if (valueType.TryGetEnumerableElementType(out elementType)) { value = mapFormListToResourceListMethod.MakeGenericMethod(elementType) .Invoke(this, new[] { value }); } } } resProp.SetValue(resource, value, null); } } if (!resInfo.IsValueObject) { Save(resource); } return(resource); }
public virtual object OnPost(IPostForm form) { var resourceInterface = this.GetMostInheritedResourceInterface(form.GetType()); Delegate del; if (this.postHandlers.TryGetValue(resourceInterface, out del)) { return(del.DynamicInvoke(form)); } return(SaveResourceFromForm(form)); }
public virtual Task <object> PostAsync(string uri, IPostForm form, RequestOptions options) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } if (form == null) { throw new ArgumentNullException(nameof(form)); } return(this.dispatcher.SendRequestAsync(uri, "POST", form, GetSerializationContextProvider(options), options)); }
public Task <object> PostAsync(string uri, IPostForm form, RequestOptions options) { return(this.client.PostAsync(uri, form, options)); }
public Task <object> PostAsync(string uri, IPostForm form, RequestOptions options) { throw new NotImplementedException(); }
public virtual TPostReturnType Post(IPostForm form) { return((TPostReturnType)Client.OnPost(form)); }
public virtual TPostResponseResource Post(IPostForm form) { return((TPostResponseResource)Client.Post(Uri, (TResource)((object)form), null)); }