diff options
author | marcinzelent <marcin@zelent.net> | 2017-05-03 20:08:32 +0200 |
---|---|---|
committer | marcinzelent <marcin@zelent.net> | 2017-05-03 20:08:32 +0200 |
commit | b31e2799c8ab431a0aaf1477f97c3885d94329a9 (patch) | |
tree | 333a3ce0ec31b668153c345d3130e862c9e9f030 | |
parent | 71eb55ef1f2098a5543316f34bc2d820b412fae7 (diff) |
Added method for getting user by username.
-rw-r--r-- | ApartmentManager/HousingWebAPI/Controllers/UsersController.cs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/ApartmentManager/HousingWebAPI/Controllers/UsersController.cs b/ApartmentManager/HousingWebAPI/Controllers/UsersController.cs index af3ac1d..098c97a 100644 --- a/ApartmentManager/HousingWebAPI/Controllers/UsersController.cs +++ b/ApartmentManager/HousingWebAPI/Controllers/UsersController.cs @@ -23,18 +23,18 @@ namespace HousingWebApi.Controllers } // GET: api/Users/by-username/username - //[ResponseType(typeof(User))] - //[Route("api/Users/by-username/{username:string}")] - //public IHttpActionResult GetUserByUsername(string username) - //{ - // User user = db.Users.Find(username); - // if (user == null) - // { - // return NotFound(); - // } - - // return Ok(user); - //} + [ResponseType(typeof(User))] + [Route("api/Users/by-username/{username}")] + public IHttpActionResult GetUserByUsername(string username) + { + User user = db.Users.SingleOrDefault(u => u.Username == username); + if (user == null) + { + return NotFound(); + } + + return Ok(user); + } // GET: api/Users/5 [ResponseType(typeof(User))] |