Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. [Route("{user}/{platform}/profile")]
  2. [HttpPut]
  3. public async Task UpdateProfile([ModelBinder]AppUser user, Platform platform, [FromBody] IProfile profile)
  4.  
  5. public class ProfileModelBinder : IModelBinder
  6. {
  7. public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
  8. {
  9. object platformParameterFromQueryString;
  10.  
  11. if (actionContext.RequestContext.RouteData.Values.TryGetValue("platform", out platformParameterFromQueryString))
  12. {
  13. Platform platformParameter;
  14.  
  15. if (platformParameterFromQueryString == null || !Enum.TryParse<Platform>(platformParameterFromQueryString.ToString(), out platformParameter))
  16. throw new ArgumentException("platform parameter not found");
  17.  
  18. if (platformParameter== Platform.Alpha)
  19. {
  20. var jsonContent = actionContext.Request.Content.ReadAsStringAsync().Result;
  21.  
  22. bindingContext.Model = JsonConvert.DeserializeObject<AlphaProfile>(jsonContent);
  23. }
  24. else
  25. {
  26. throw new NotImplementedException();
  27. }
  28. }
  29.  
  30.  
  31.  
  32. return (bindingContext.Model != null);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement