diff --git a/ClientApp/src/app/home/home.component.html b/ClientApp/src/app/home/home.component.html index f724d64..fb6ce23 100644 --- a/ClientApp/src/app/home/home.component.html +++ b/ClientApp/src/app/home/home.component.html @@ -11,7 +11,7 @@ {{ instructor.firstName }} {{ instructor.lastName }} - + @@ -21,6 +21,6 @@
- + diff --git a/ClientApp/src/app/home/home.component.ts b/ClientApp/src/app/home/home.component.ts index 146d96b..f06ede2 100644 --- a/ClientApp/src/app/home/home.component.ts +++ b/ClientApp/src/app/home/home.component.ts @@ -15,12 +15,30 @@ export class HomeComponent { constructor(private instructorsService: InstructorsHttpService) {} ngOnInit() { - this.loadInstructors() + this.loadInstructors() } private loadInstructors() { - this.instructorsService.getInstructors().subscribe(result => { - this.instructors = result; - }) + this.instructorsService.getInstructors().subscribe(result => { + this.instructors = result + }) + } + + saveChanges() { + if(this.changingInstructor.id == null) { + this.instructorsService.createInstructor(this.changingInstructor).subscribe(result => { + this.instructors.push(result) + }) + + } else { + this.instructorsService.updateInstructor(this.changingInstructor) + } + this.changingInstructor = new Instructor() + } + + deleteInstructor(instructor: Instructor) { + this.instructorsService.deleteInstructor(instructor.id).subscribe(_ =>{ + this.instructors.splice(this.instructors.indexOf(instructor), 1) + }) } } \ No newline at end of file diff --git a/ClientApp/src/app/services/instructors-http-service.ts b/ClientApp/src/app/services/instructors-http-service.ts index 44ac374..cabfa23 100644 --- a/ClientApp/src/app/services/instructors-http-service.ts +++ b/ClientApp/src/app/services/instructors-http-service.ts @@ -1,6 +1,7 @@ import { Injectable, Inject } from '@angular/core'; import { HttpClient} from '@angular/common/http'; import { Instructor } from '../models/instructor'; +import { ResponseType } from '@angular/http'; @Injectable() export class InstructorsHttpService { @@ -11,7 +12,7 @@ export class InstructorsHttpService { } createInstructor(instructor: Instructor) { - return this.http.post(this.baseUrl + "api/v1/instructors/add", instructor) + return this.http.post(this.baseUrl + "api/v1/instructors/add", instructor) } updateInstructor(instructor: Instructor) {