Exemple #1
0
        public HttpResponseMessage AddOneUserDog([FromBody] DogDetailsView userDog)
        {
            try
            {
                dogValidator     userdogValidator = new dogValidator();
                ValidationResult results          = userdogValidator.Validate(userDog);

                if (results.IsValid)
                {
                    //var jsonString = userDogs.Content.ReadAsStringAsync().Result;
                    //DogsForManagerView list = JsonConvert.DeserializeObject<DogsForManagerView>(jsonString);
                    //  UserDetailsView user = JsonConvert.DeserializeObject<UserDetailsView>(jsonString);
                    Userservice userservice = new Userservice();
                    userservice.AddOneDogForUser(userDog);
                    return(Request.CreateResponse(HttpStatusCode.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);
            }
        }