Created
October 15, 2012 12:57
-
-
Save satish860/3892324 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Url for the POST is http://localhost/api/todo | |
/// </summary> | |
/// <param name="item">Creates the Todo ITEM</param> | |
/// <returns></returns> | |
public HttpResponseMessage Post(TodoItem item) | |
{ | |
try | |
{ | |
if (string.IsNullOrEmpty(item.Description)) | |
{ | |
ValidationResult result = new ValidationResult { Name = "Description", ErrorMessage = "Description should not be empty" }; | |
return Request.CreateResponse<ValidationResult>(HttpStatusCode.BadRequest, result); | |
} | |
var response = Request.CreateResponse<TodoItem>(HttpStatusCode.Created, new TodoItem { }); | |
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "Todo", id = item.Id })); | |
return response; | |
} | |
catch (Exception ex) | |
{ | |
return Request.CreateResponse(HttpStatusCode.InternalServerError); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Url for the POST is http://localhost/api/todo | |
/// </summary> | |
/// <param name="item">Creates the Todo ITEM</param> | |
/// <returns></returns> | |
public HttpResponseMessage Post(TodoItem item) | |
{ | |
var response=Request.CreateResponse<TodoItem>(HttpStatusCode.Created, new TodoItem { }); | |
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "Todo", id = item.Id })); | |
return response; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace WebAPIKoans.Controllers | |
{ | |
public class TodoController : ApiController | |
{ | |
/// <summary> | |
/// Url-- POST http://localhost/api/todo | |
/// </summary> | |
/// <param name="item">Creates the Todo ITEM</param> | |
/// <returns></returns> | |
public HttpResponseMessage Post(TodoItem item) | |
{ | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Url for the POST is http://localhost/api/todo | |
/// </summary> | |
/// <param name="item">Creates the Todo ITEM</param> | |
/// <returns></returns> | |
public HttpResponseMessage Post(TodoItem item) | |
{ | |
if (string.IsNullOrEmpty(item.Description)) | |
{ | |
ValidationResult result = new ValidationResult { Name = "Description", ErrorMessage = "Description should not be empty" }; | |
return Request.CreateResponse<ValidationResult>(HttpStatusCode.BadRequest, result); | |
} | |
var response=Request.CreateResponse<TodoItem>(HttpStatusCode.Created, new TodoItem { }); | |
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "Todo", id = item.Id })); | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment