public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var studentClient = new OpenHack.University.Services.Student.StudentClient();

            studentClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(webserviceUrl);

            var studentToUpdateContract = await studentClient.GetByIdAsync(id.Value);


            if (studentToUpdateContract == null)
            {
                return(NotFound());
            }

            var studentToUpdate = new Student()
            {
                ID             = studentToUpdateContract.ID,
                LastName       = studentToUpdateContract.LastName,
                FirstMidName   = studentToUpdateContract.FirstMidName,
                EnrollmentDate = studentToUpdateContract.EnrollmentDate
            };

            await studentClient.DeleteAsync(studentToUpdate.ID);

            return(RedirectToPage("./Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var studentClient = new OpenHack.University.Services.Student.StudentClient();

            studentClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(webserviceUrl);

            var studentContract = await studentClient.GetByIdAsync(id.Value);

            Student = new Student()
            {
                ID             = studentContract.ID,
                LastName       = studentContract.LastName,
                FirstMidName   = studentContract.FirstMidName,
                EnrollmentDate = studentContract.EnrollmentDate
            };

            if (Student == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            var studentClient = new OpenHack.University.Services.Student.StudentClient();

            studentClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(webserviceUrl);

            var studentToUpdateContract = await studentClient.GetByIdAsync(id);

            if (studentToUpdateContract == null)
            {
                return(NotFound());
            }
            var studentToUpdate = new Student()
            {
                ID             = studentToUpdateContract.ID,
                LastName       = studentToUpdateContract.LastName,
                FirstMidName   = studentToUpdateContract.FirstMidName,
                EnrollmentDate = studentToUpdateContract.EnrollmentDate
            };


            if (await TryUpdateModelAsync <Student>(
                    studentToUpdate,
                    "student",
                    s => s.FirstMidName, s => s.LastName, s => s.EnrollmentDate))
            {
                await studentClient.ModifyAsync(new Services.Contract.Student()
                {
                    ID             = studentToUpdate.ID,
                    EnrollmentDate = studentToUpdate.EnrollmentDate,
                    FirstMidName   = studentToUpdate.FirstMidName,
                    LastName       = studentToUpdate.LastName
                });

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

            return(Page());
        }