Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cc3d97f

Browse files
customer edit form
1 parent bb156b5 commit cc3d97f

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

‎src/AspnetRun.Api/Controllers/CustomerController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<ActionResult<IEnumerable<CustomerModel>>> GetCustomers()
4646
Description = "asdf",
4747
State = "success",
4848
Gender = "male",
49-
OrderTotal = 22.2
49+
OrderTotal = 22.2
5050
},
5151
new CustomerModel
5252
{

‎src/AspnetRun.Web/src/app/core/services/customer-data.services.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { HttpClient } from '@angular/common/http';
33
import { Observable } from 'rxjs';
44
import { environment } from 'src/environments/environment';
55
import { ICustomer } from 'src/app/shared/interfaces';
6+
import { map } from 'rxjs/operators';
67

78
@Injectable()
89
export class CustomerDataService {
10+
911
constructor(private httpClient: HttpClient) { }
1012

1113
getCustomers(): Observable<ICustomer[]> {
@@ -17,4 +19,18 @@ export class CustomerDataService {
1719

1820
return this.httpClient.post<ICustomer>(environment.apiUrl + '/Customer/GetCustomerById/', request);
1921
}
22+
23+
deleteCustomer(id: number) {
24+
return this.httpClient.delete<boolean>(environment.apiUrl + '/' + id)
25+
.pipe(
26+
map(res => true)
27+
);
28+
}
29+
30+
updateCustomer(customer: ICustomer): Observable<boolean> {
31+
return this.httpClient.delete<boolean>(environment.apiUrl + '/' + id)
32+
.pipe(
33+
map(res => true)
34+
);
35+
}
2036
}

‎src/AspnetRun.Web/src/app/views/customer/customer-edit/customer-edit.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
<div class="pull-right" *ngIf="!deleteMessageEnabled">
4040
<button class="btn btn-default" (click)="cancel($event)">Cancel</button>&nbsp;&nbsp;
41-
<button type="submit" class="btn btn-success" [disabled]="customerForm.pristine || !customerForm.valid">{{ operationText }}</button>
41+
<button type="submit" class="btn btn-success" [disabled]="!customerForm.valid">{{ operationText }}</button>
4242
</div>
4343
</div>
4444
<div class="alert alert-danger" *ngIf="errorMessage != null">{{ errorMessage }}</div>

‎src/AspnetRun.Web/src/app/views/customer/customer-edit/customer-edit.component.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NgForm } from '@angular/forms';
55

66
import { ICustomer, IState } from 'src/app/shared/interfaces';
77
import { CustomerDataService } from 'src/app/core/services/customer-data.services';
8+
import { LoggerService } from 'src/app/core/services/logger.service';
89

910
@Component({
1011
templateUrl: './customer-edit.component.html',
@@ -34,7 +35,8 @@ export class CustomerEditComponent implements OnInit {
3435

3536
constructor(private router: Router,
3637
private route: ActivatedRoute,
37-
private dataService: CustomerDataService) { }
38+
private dataService: CustomerDataService,
39+
private logger: LoggerService) { }
3840

3941
ngOnInit() {
4042
this.route.params.subscribe((params: Params) => {
@@ -52,4 +54,31 @@ export class CustomerEditComponent implements OnInit {
5254
});
5355
}
5456

57+
cancel(event: Event) {
58+
event.preventDefault();
59+
this.router.navigate(['/customer']);
60+
}
61+
62+
delete(event: Event) {
63+
event.preventDefault();
64+
65+
this.dataService.deleteCustomer(this.customer.id)
66+
.subscribe((status: boolean) => {
67+
if (status) {
68+
this.router.navigate(['/customer']);
69+
} else {
70+
this.errorMessage = 'Unable to delete customer';
71+
}
72+
},
73+
(err) => this.logger.log(err));
74+
}
75+
76+
submit() {
77+
if (this.customer.id === 0) {
78+
this.router.navigate(['/customer']);
79+
} else {
80+
this.router.navigate(['/customer']);
81+
}
82+
}
83+
5584
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /