public IHttpActionResult Post([FromBody] DummyPost dummy) { //dummy is not null if (dummy == null) { //return BadRequest("Dummy data null"); //we can also do something like return(Content(HttpStatusCode.BadRequest, "Dummy data null")); } //fluent validation var result = new DummyPostValidator().Validate(dummy); if (!result.IsValid) { foreach (var f in result.Errors) { ModelState.AddModelError(f.PropertyName, f.ErrorMessage); } } //dummy model state is valid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //over write the Id value of the dummy dummy.Id = 50; dummy.Message = "Standard Post"; return(base.BuildJasonResult <DummyPost>(dummy, this)); }
public IHttpActionResult ExtraPostMultiLineReturn([FromBody] DummyPost dummy) { //dummy is not null if (dummy == null) { return(BadRequest("Dummy data null")); } //dummy model state is valid if (!ModelState.IsValid) { return(BadRequest("Dummy data model state is not valid")); } //multiline return var dummies = new List <DummyPost> { new DummyPost { Id = 1, Message = "One M", Name = "One" }, new DummyPost { Id = 2, Message = "Two M", Name = "Two" } }; dummy.Id = 50; dummy.Message = "Extra Post"; return(base.BuildJasonResult <List <DummyPost> >(dummies, this)); }
private async void DoPost() { var dp = new DummyPost { Id = 12345, Name = "XYZ" }; //we might be posting one model and getting back another model. Here the same model is getting posted. So .Post<inputModel Type, returnModel Type> var apiCallResult = await ApiCrudCallHelper.Post <DummyPost, DummyPost>(dp, txtApiPath.Text); txtResults.AppendText(apiCallResult.Message); }
private async void DoPut() { var dp = new DummyPost { Id = 12345, Name = "XYZ" }; //we might be posting one model and getting back another model. Here the same model is getting posted. So .Post<inputModel Type, returnModel Type> //since this is a PUT call, append the id to the url as well var apiUrl = $"{txtApiPath.Text}/98745"; var apiCallResult = await ApiCrudCallHelper.Put <DummyPost, DummyPost>(dp, apiUrl); txtResults.AppendText(apiCallResult.Message); }
public IHttpActionResult ExtraPostOk([FromBody] DummyPost dummy) { //dummy is not null if (dummy == null) { return(BadRequest("Dummy data null")); } //dummy model state is valid if (!ModelState.IsValid) { return(BadRequest("Dummy data model state is not valid")); } return(base.BuildResponseMessage(HttpStatusCode.OK, "Posted Ok")); }
public IHttpActionResult ExtraPost([FromBody] DummyPost dummy) { //dummy is not null if (dummy == null) { return(BadRequest("Dummy data null")); } //dummy model state is valid if (!ModelState.IsValid) { return(BadRequest("Dummy data model state is not valid")); } //over write the Id value of the dummy dummy.Id = 50; dummy.Message = "Extra Post"; return(base.BuildJasonResult <DummyPost>(dummy, this)); }