コード例 #1
0
        public HttpResponseMessage AddStudent(MoStudent moStudent)
        {
            var httpStatus = HttpStatusCode.OK;

            if (ModelState.IsValid)
            {
                var isfalse = db.Save(moStudent);
            }
            return(Request.CreateResponse(httpStatus, moStudent));
        }
コード例 #2
0
        public async Task <ActionResult> Add(MoStudent model)
        {
            if (ModelState.IsValid)
            {
                var webapiUrl = "http://localhost:59641/test/add";

                var httpResponseMsg = new HttpResponseMessage();

                using (var httpClient = new HttpClient())
                {
                    httpResponseMsg = await httpClient.PostAsync <MoStudent>(webapiUrl, model, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
                }
                model = httpResponseMsg.Content.ReadAsAsync <MoStudent>().Result;
            }
            ModelState.AddModelError("", model.Id > 0?"添加成功":"添加失败");
            return(View(model));
        }
コード例 #3
0
        public async Task <ActionResult> Index()
        {
            var searchData = new MoStudent();
            //查询条件

            var webapiURL = "http://localhost:59641/test/all01_2";

            var httpResponseMsg = new HttpResponseMessage();

            using (var httpClient = new HttpClient())
            {
                httpResponseMsg = await httpClient.GetAsync(webapiURL);
            }
            var students = httpResponseMsg.Content.ReadAsAsync <List <MoStudent> >().Result;

            return(View(students));
        }
コード例 #4
0
 public bool Save(MoStudent moStudent)
 {
     moStudent.Id = students.Max(b => b.Id) + 1;
     students.Add(moStudent);
     return(true);
 }