コード例 #1
0
        public HttpResponseMessage UpdateUserDetails([FromBody] UserDetailsView user)
        {
            try
            {
                UpdateUserValidator validator = new UpdateUserValidator();
                ValidationResult    results   = validator.Validate(user);
                if (results.IsValid)
                {
                    Userservice userservice = new Userservice();
                    userservice.UpdateUserDetails(user);
                    return(Request.CreateResponse(HttpStatusCode.OK));

                    //  return Ok();
                }
                else
                {
                    List <string> errorlist = new List <string>();
                    foreach (var value in results.Errors)
                    {
                        errorlist.Add(value.ErrorMessage);
                    }
                    var response = Request.CreateResponse(HttpStatusCode.BadRequest);
                    response.Content = new StringContent(errorlist[0]);
                    return(response);
                    //  return Request.CreateResponse(HttpStatusCode.BadRequest);
                }
            }
            catch (HttpRequestException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
                // throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest,
                //                           badInputValidationException.Result));
                //Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }
        }