public HttpResponseMessage Post(User user) { if (ModelState.IsValid) { try { repository.AddUser(user); return(Request.CreateResponse(HttpStatusCode.Created, user)); } catch (Exception) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "The user with current name is exist"); return(response); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }