示例#1
0
        public IHttpActionResult Post([FromBody] DummyPost dummy)
        {
            //dummy is not null
            if (dummy == null)
            {
                //return BadRequest("Dummy data null");
                //we can also do something like
                return(Content(HttpStatusCode.BadRequest, "Dummy data null"));
            }

            //fluent validation
            var result = new DummyPostValidator().Validate(dummy);

            if (!result.IsValid)
            {
                foreach (var f in result.Errors)
                {
                    ModelState.AddModelError(f.PropertyName, f.ErrorMessage);
                }
            }

            //dummy model state is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //over write the Id value of the dummy
            dummy.Id      = 50;
            dummy.Message = "Standard Post";

            return(base.BuildJasonResult <DummyPost>(dummy, this));
        }
示例#2
0
        public IHttpActionResult ExtraPostMultiLineReturn([FromBody] DummyPost dummy)
        {
            //dummy is not null
            if (dummy == null)
            {
                return(BadRequest("Dummy data null"));
            }

            //dummy model state is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest("Dummy data model state is not valid"));
            }

            //multiline return
            var dummies = new List <DummyPost>
            {
                new DummyPost {
                    Id = 1, Message = "One M", Name = "One"
                },
                new DummyPost {
                    Id = 2, Message = "Two M", Name = "Two"
                }
            };

            dummy.Id      = 50;
            dummy.Message = "Extra Post";

            return(base.BuildJasonResult <List <DummyPost> >(dummies, this));
        }
示例#3
0
        private async void DoPost()
        {
            var dp = new  DummyPost {
                Id = 12345, Name = "XYZ"
            };
            //we might be posting one model and getting back another model. Here the same model is getting posted. So .Post<inputModel Type, returnModel Type>
            var apiCallResult = await ApiCrudCallHelper.Post <DummyPost, DummyPost>(dp, txtApiPath.Text);

            txtResults.AppendText(apiCallResult.Message);
        }
示例#4
0
        private async void DoPut()
        {
            var dp = new DummyPost {
                Id = 12345, Name = "XYZ"
            };
            //we might be posting one model and getting back another model. Here the same model is getting posted. So .Post<inputModel Type, returnModel Type>
            //since this is a PUT call, append the id to the url as well
            var apiUrl        = $"{txtApiPath.Text}/98745";
            var apiCallResult = await ApiCrudCallHelper.Put <DummyPost, DummyPost>(dp, apiUrl);

            txtResults.AppendText(apiCallResult.Message);
        }
示例#5
0
        public IHttpActionResult ExtraPostOk([FromBody] DummyPost dummy)
        {
            //dummy is not null
            if (dummy == null)
            {
                return(BadRequest("Dummy data null"));
            }

            //dummy model state is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest("Dummy data model state is not valid"));
            }

            return(base.BuildResponseMessage(HttpStatusCode.OK, "Posted Ok"));
        }
示例#6
0
        public IHttpActionResult ExtraPost([FromBody] DummyPost dummy)
        {
            //dummy is not null
            if (dummy == null)
            {
                return(BadRequest("Dummy data null"));
            }

            //dummy model state is valid
            if (!ModelState.IsValid)
            {
                return(BadRequest("Dummy data model state is not valid"));
            }

            //over write the Id value of the dummy
            dummy.Id      = 50;
            dummy.Message = "Extra Post";

            return(base.BuildJasonResult <DummyPost>(dummy, this));
        }