import { Component , OnInit } from '@angular/core' ; import { FormBuilder , FormGroup , Validators } from '@angular/forms' ; import { ToastrService } from 'ngx-toastr' ; import { DynamicDialogConfig , DynamicDialogRef } from 'primeng/dynamicdialog' ; import { Brand } from 'src/app/models/brand' ; import { BrandService } from 'src/app/services/brand.service' ; @ Component ( { selector : 'app-add-brand' , templateUrl : './add-brand.component.html' , styleUrls : [ './add-brand.component.css' ] } ) export class AddBrandComponent implements OnInit { brandAddForm : FormGroup ; constructor ( private ref , private config , private toastrService , private brandService , private formBuilder ) { } ngOnInit ( ) { this . createBrandAddForm ( ) ; } createBrandAddForm ( ) { this . brandAddForm = this . formBuilder . group ( { name : [ "" , Validators . required ] , } ) ; } addBrand ( ) { if ( this . brandAddForm . valid ) { let brandModel = Object . assign ( { } , this . brandAddForm . value ) ; this . brandService . addBrand ( brandModel ) . subscribe ( response => { this . toastrService . success ( response . message , "Başarılı" ) ; setTimeout ( function ( ) { location . reload ( ) ; } , 400 ) ; } , responseError => { console . log ( responseError ) ; if ( responseError . error . ValidationErrors . length > 0 ) { for ( let i = 0 ; i < responseError . error . ValidationErrors . length ; i ++ ) { this . toastrService . error ( responseError . error . ValidationErrors [ i ] . ErrorMessage , "Doğrulama hatası" ) ; } } } ) ; } else { this . toastrService . error ( "Formu doldurmanız gerekli" , "Hata" ) ; } } }