Last active
September 1, 2017 03:25
-
-
Save ryanvgates/99a055449ab9901c40828360fa30cdbe to your computer and use it in GitHub Desktop.
Web API Put Gotcha
This file contains hidden or 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
[HttpPut] | |
public async Task<RestResponseModel<Company>> Put([FromUri] int companyId, Company company) | |
{ | |
var response = new RestResponseModel<Company>(); | |
try | |
{ | |
company.LastModifiedOn = DateTime.UtcNow; | |
company.ModifiedBy = Guid.Parse(this.UserAspId); | |
response.Data.Add(await this.dataAccess.UpdateCompany(id, company)); | |
} | |
catch (Exception exception) | |
{ | |
logger.Error(exception); | |
response.ErrorsAdd(exception); | |
} | |
return response; | |
} |
This file contains hidden or 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
[HttpPut("{id}")] | |
public string Put([FromRoute] int id, [FromBody] object company) | |
{ | |
return id + " was the parameter."; | |
} |
This file contains hidden or 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
[HttpPut] | |
public async Task<RestResponseModel<Company>> Put([FromUri] int id, Company company) | |
{ | |
var response = new RestResponseModel<Company>(); | |
try | |
{ | |
company.LastModifiedOn = DateTime.UtcNow; | |
company.ModifiedBy = Guid.Parse(this.UserAspId); | |
response.Data.Add(await this.dataAccess.UpdateCompany(id, company)); | |
} | |
catch (Exception exception) | |
{ | |
logger.Error(exception); | |
response.ErrorsAdd(exception); | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment