Exemple #1
0
        public IHttpActionResult Get([FromBody] ComplexTypeDto dto)
        {
            //if (!ModelState.IsValid)
            //    return BadRequest("int 1 should be between 1 to 100");

            return(Ok(dto));
        }
        public HttpResponseMessage GetAnHttpResponse()
        {
            var dto = new ComplexTypeDto()
            {
                String1 = "This is string 1",
                String2 = "This is string 2",
                Int1    = 55,
                Date1   = DateTime.Now
            };

            //var response = new HttpResponseMessage(HttpStatusCode.OK)
            //{
            //    // note I am responsible for my own content negotiation!
            //    // this content will confuse a caller wanting XML or other media type
            //    Content = new StringContent(JsonConvert.SerializeObject(dto), Encoding.UTF8, "application/json")
            //};

            // or alternatively
            var response = Request.CreateResponse(dto);

            response.Headers.Add("X-MyCustomHeader", "MyHeaderValue");
            response.ReasonPhrase = "Most Excellent!";

            // error response
            response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid something or other");

            return(response);
        }
Exemple #3
0
        [ValidateModelState(BodyRequired = true)]    // METHOD 2: Use an Action Filter
        public IHttpActionResult Post([FromBody] ComplexTypeDto dto)
        {
            // METHOD 1: Inline model validation
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            return(Ok("Posted data valid"));
        }
        public IHttpActionResult GetAnActionResult()
        {
            var dto = new ComplexTypeDto()
            {
                String1 = "This is string 1",
                String2 = "This is string 2",
                Int1    = 55,
                Date1   = DateTime.Now
            };

            return(Ok(dto).AddHeader("X-MyCustomHeader", "test value"));
        }
 public ActionResult Rpc(ComplexTypeDto objectValue, string[] arrayValue, string stringValue, int numberValue, bool trueValue, bool falseValue, object nullValue)
 {
     return Json(new{
         objectValue,
         arrayValue,
         stringValue,
         numberValue,
         trueValue,
         falseValue,
         nullValue
     });
 }
        public ComplexTypeDto GetObject()
        {
            var dto = new ComplexTypeDto()
            {
                String1 = "This is string 1",
                String2 = "This is string 2",
                Int1    = 55,
                Date1   = DateTime.Now
            };

            // error response:
            throw new InvalidOperationException("I'm sorry, Dave, I'm afraid I can't do that.");

            return(dto);
        }
        public IHttpActionResult GetAnActionResult()
        {
            var dto = new ComplexTypeDto()
            {
                String1 = "This is string 1",
                String2 = "This is string 2",
                Int1    = 55,
                Date1   = DateTime.Now
            };

            //var response = Json(dto);
            var response = Ok(dto).AddHeader("X-MyCustomHeader", "test value");

            //var response = BadRequest("test test test").AddHeader("X-MyCustomHeader", "test value");

            return(response);
        }
Exemple #8
0
        public IHttpActionResult GetObject()
        {
            var dto = new ComplexTypeDto
            {
                String1 = "this is string 1",
                String2 = "this is string 2",
                Int1    = 55,
                Int2    = 22,
                Date1   = DateTime.Now
            };
            //try { throw new Exception("omg exception happened"); }
            //catch (Exception ex)
            //{
            //    return BadRequest();
            //}
            var res = Ok(dto);

            return(res);
        }
Exemple #9
0
        public IHttpActionResult GetAnActionResult()
        {
            var dto = new ComplexTypeDto()
            {
                String1 = "This is string 1",
                String2 = "This is string 2",
                Int1    = 55,
                Date1   = DateTime.Now
            };

            //var response = Json(dto);
            var response = Ok(dto).AddHeader("X-MyCustomHeader", "test value");

            // For a cool affluent-syntax chaining of cachability [.Cached()], see this: https://gist.github.com/bradwilson/8586562
            // return Ok("Hello, " + name).Cached(Cacheability.Public, maxAge: TimeSpan.FromMinutes(15));

            //var response = BadRequest("test test test").AddHeader("X-MyCustomHeader", "test value");

            return(response);
        }
 public IHttpActionResult ComplexTest([FromUri] ComplexTypeDto obj)
 {
     return(Json(obj));
 }
 public IHttpActionResult RetirnComplex([FromUri] ComplexTypeDto Dto)
 {
     return(Ok(Dto));
 }