2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Net . Http ;
5
- using NetCoreStack . Contracts ;
6
5
7
6
namespace NetCoreStack . Proxy
8
7
{
@@ -12,31 +11,29 @@ public class HttpPutContentBinder : BodyContentBinder
12
11
13
12
public override void BindContent ( ContentModelBindingContext bindingContext )
14
13
{
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
+
15
24
ModelDictionaryResult result = bindingContext . GetResolvedContentResult ( ) ;
16
25
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 ) ;
21
31
return ;
22
- // request.Content = SerializeToString(argsDic.First().Value);
23
32
}
24
- else if ( bindingContext . ArgsLength == 2 )
25
- {
26
- var firstParameter = result . Dictionary [ keys [ 0 ] ] ;
27
- var secondParameter = result . Dictionary [ keys [ 1 ] ] ;
28
33
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 ) ) ;
40
37
}
41
38
}
42
39
}
0 commit comments