22using System . Collections . Generic ;
33using System . Linq ;
44using System . Net . Http ;
5- using NetCoreStack . Contracts ;
65
76namespace NetCoreStack . Proxy
87{
@@ -12,31 +11,29 @@ public class HttpPutContentBinder : BodyContentBinder
1211
1312 public override void BindContent ( ContentModelBindingContext bindingContext )
1413 {
14+ var isMultiPartFormData = bindingContext . IsMultiPartFormData ;
15+ var templateKeys = bindingContext . UriDefinition . TemplateKeys ;
16+
17+ // bindingContext.Parameters.Select(p => p.PropertyName);
18+
19+ //if (bindingContext.ArgsLength == 1)
20+ //{
21+
22+ //}
23+
1524 ModelDictionaryResult result = bindingContext . GetResolvedContentResult ( ) ;
1625 List < string > keys = result . Dictionary . Keys . ToList ( ) ;
17- EnsureTemplate ( bindingContext . MethodMarkerTemplate , bindingContext . Args , bindingContext . UriDefinition , result . Dictionary , keys ) ;
18- if ( bindingContext . ArgsLength == 1 )
19- {
20- bindingContext . ContentResult = ContentModelBindingResult . Success ( SerializeToString ( bindingContext . Args [ 0 ] ) ) ;
26+ EnsureTemplate ( bindingContext . MethodMarkerTemplate , bindingContext . UriDefinition , result . Dictionary , keys ) ;
27+ if ( isMultiPartFormData )
28+ {
29+ var content = GetMultipartFormDataContent ( result ) ;
30+ bindingContext . ContentResult = ContentModelBindingResult . Success ( content ) ;
2131 return ;
22- // request.Content = SerializeToString(argsDic.First().Value);
2332 }
24- else if ( bindingContext . ArgsLength == 2 )
25- {
26- var firstParameter = result . Dictionary [ keys [ 0 ] ] ;
27- var secondParameter = result . Dictionary [ keys [ 1 ] ] ;
2833
29- // PUT Request first parameter should be Id or Key
30- if ( firstParameter . GetType ( ) . IsPrimitive ( ) )
31- {
32- bindingContext . UriBuilder . Query += string . Format ( "&{0}={1}" , keys [ 0 ] , firstParameter ) ;
33- }
34-
35- // request.RequestUri = uriBuilder.Uri;
36- // request.Content = SerializeToString(secondParameter);
37- bindingContext . ContentResult = ContentModelBindingResult . Success ( SerializeToString ( secondParameter ) ) ;
38- return ;
39- }
34+ // PUT Request first parameter should be Id or Key then will be removed from the result dictionary
35+ // The remaining parameters belong to the body
36+ bindingContext . ContentResult = ContentModelBindingResult . Success ( SerializeToString ( result . Dictionary ) ) ;
4037 }
4138 }
4239}
0 commit comments