Esempio n. 1
0
        public HttpResponseMessage InsertUserDetailsByManager([FromBody] UserDetailsView user)
        {
            //HttpStatusCodeResult httpStatusCodeResult = null;
            //int code =(int) HttpStatusCode.OK;
            try
            {
                //var jsonString = userNew.Content.ReadAsStringAsync().Result;
                // UserDetailsView user = JsonConvert.DeserializeObject<UserDetailsView>(userNew);
                UserValidatorManager validator = new UserValidatorManager();

                ValidationResult results = validator.Validate(user);
                if (results.IsValid)
                {
                    Userservice userservice = new Userservice();
                    userservice.InsertUserDetails(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);
                    //List<string> errorlist = new List<string>();
                    //foreach (var value in results.Errors)
                    //{
                    //    errorlist.Add(value.ErrorMessage);
                    //}
                    // 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);
            }
        }