Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Route("{user}/{platform}/profile")]
- [HttpPut]
- public async Task UpdateProfile([ModelBinder]AppUser user, Platform platform, [FromBody] IProfile profile)
- public class ProfileModelBinder : IModelBinder
- {
- public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
- {
- object platformParameterFromQueryString;
- if (actionContext.RequestContext.RouteData.Values.TryGetValue("platform", out platformParameterFromQueryString))
- {
- Platform platformParameter;
- if (platformParameterFromQueryString == null || !Enum.TryParse<Platform>(platformParameterFromQueryString.ToString(), out platformParameter))
- throw new ArgumentException("platform parameter not found");
- if (platformParameter== Platform.Alpha)
- {
- var jsonContent = actionContext.Request.Content.ReadAsStringAsync().Result;
- bindingContext.Model = JsonConvert.DeserializeObject<AlphaProfile>(jsonContent);
- }
- else
- {
- throw new NotImplementedException();
- }
- }
- return (bindingContext.Model != null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement