Building Single Page Application Using ASP.NET Core & Angular by Chander Dhall & Rahul Sahay

Building Single Page Application Using ASP.NET Core & Angular by Chander Dhall & Rahul Sahay

Author:Chander Dhall & Rahul Sahay [Dhall, Chander]
Language: eng
Format: azw3
Published: 2018-02-21T16:00:00+00:00


@Component({

selector: 'app-new-review',

templateUrl: './new-review.component.html',

styleUrls: ['./new-review.component.css']

})

export class NewReviewComponent implements OnInit {

review:Review=new Review();

constructor(private reviewsService: ReviewsService,

private toastyService: ToastyService,

private route: ActivatedRoute,

private router: Router) {

route.params.subscribe(p => {

this.review.movieId = +p['id'];

});

}

ngOnInit() {

}

onSubmit(form: NgForm) {

var formData = this.review;

formData.id = 0;

formData.reviewerName = this.review.reviewerName.toString();

formData.reviewerComments = this.review.reviewerComments.toString();

formData.reviewerRating = this.review.reviewerRating;

formData.movieId = this.review.movieId;

console.log(formData);

this.reviewsService.createReview(this.review.movieId, formData)

.subscribe(x => {

console.log(x);

this.toastyService.success({

title: 'Success',

msg: 'New Review Created!',

theme: 'bootstrap',

showClose: true,

timeout: 5000

});

this.router.navigate(['/movies']);

},

err => {

Raven.captureException(err.originalError || err);

this.toastyService.error({

title: 'Error',

msg: 'An unexpected error occured while creating new Review!',

theme: 'bootstrap',

showClose: true,

timeout: 5000

});

});

}

}

Corresponding to this, I have also created an equivalent method in reviews.service.ts.

import { Injectable, Inject } from '@angular/core';

import { Http } from '@angular/http';

import 'rxjs/add/operator/map';



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.