示例#1
0
        public HttpResponseMessage AddRoom([FromBody] RoomsDetailsView roomsDetails)
        {
            try
            {
                //var jsonString = userNew.Content.ReadAsStringAsync().Result;
                // UserDetailsView user = JsonConvert.DeserializeObject<UserDetailsView>(userNew);
                RoomValidator    validator = new RoomValidator();
                ValidationResult results   = validator.Validate(roomsDetails);
                if (results.IsValid)
                {
                    RoomsServie roomsServie = new RoomsServie();
                    roomsServie.AddRoom(roomsDetails);
                    return(Request.CreateResponse(HttpStatusCode.OK));

                    //  return Ok();
                }
                else
                {
                    //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);
            }
        }