예제 #1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var response = await client.CreateClient("client").GetStringAsync("api/Students/" + id);

            Student = JsonConvert.DeserializeObject <Models.APIViewModels.Student>(response);

            if (Student == null)
            {
                return(NotFound());
            }
            return(Page());
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyStudent = new Models.APIViewModels.Student();

            if (await TryUpdateModelAsync <Models.APIViewModels.Student>(
                    emptyStudent,
                    "student", // Prefix for form value.
                    s => s.FirstName, s => s.LastName, s => s.EnrollmentDate))
            {
                var response = await client.CreateClient("client").PostAsJsonAsync("api/Students", emptyStudent);

                return(RedirectToPage("./Index"));
            }

            return(null);
        }