Skip to content

Commit 50a9b78

Browse files
committed
customer details page added
1 parent 92890ee commit 50a9b78

File tree

7 files changed

+88
-4
lines changed

7 files changed

+88
-4
lines changed

src/AspnetRun.Api/Controllers/CustomerController.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using AspnetRun.Application.Interfaces;
1+
using AspnetRun.Api.Requests;
2+
using AspnetRun.Application.Interfaces;
23
using AspnetRun.Application.Models;
34
using MediatR;
45
using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -75,5 +76,28 @@ public async Task<ActionResult<IEnumerable<CustomerModel>>> GetCustomers()
7576

7677
return Ok(customers);
7778
}
79+
80+
[Route("[action]")]
81+
[HttpPost]
82+
[ProducesResponseType(typeof(CustomerModel), (int)HttpStatusCode.OK)]
83+
public async Task<ActionResult<CustomerModel>> GetCustomerById(GetCustomerByIdRequest request)
84+
{
85+
//var product = await _productService.GetProductById(request.Id);
86+
87+
var customer = new CustomerModel
88+
{
89+
Id = 1,
90+
FirstName = "mehmet",
91+
LastName = "ozkaya",
92+
Address = "gungoren",
93+
City = "istanbul",
94+
Description = "asdf",
95+
State = "success",
96+
Gender = "male",
97+
OrderTotal = 22.2
98+
};
99+
100+
return Ok(customer);
101+
}
78102
}
79103
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AspnetRun.Api.Requests
2+
{
3+
public class GetCustomerByIdRequest
4+
{
5+
public int Id { get; set; }
6+
}
7+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ export class CustomerDataService {
1111
getCustomers(): Observable<ICustomer[]> {
1212
return this.httpClient.get<ICustomer[]>(environment.apiUrl + '/Customer/GetCustomers');
1313
}
14+
15+
getCustomerById(id:number): Observable<ICustomer> {
16+
var request = { id: id };
17+
18+
return this.httpClient.post<ICustomer>(environment.apiUrl + '/Customer/GetCustomerById/', request);
19+
}
1420
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.details-image {
2+
height:100px;width:100px;margin-top:10px;
3+
}
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
<p>customer-detail works!</p>
1+
<div class="container" *ngIf="customer">
2+
<div class="row">
3+
<div class="col-md-2">
4+
<img src="assets/img/{{customer.gender | lowercase}}.png" class="details-image" />
5+
</div>
6+
<div class="col-md-10">
7+
<h4>
8+
{{ customer.firstName | capitalize }} {{ customer.lastName | capitalize }}&nbsp;
9+
</h4>
10+
<br />
11+
{{ customer.address }}
12+
<br />
13+
{{ customer.city }}, {{ customer.state.name }}
14+
</div>
15+
</div>
16+
<br /><br />
17+
<!-- <div class="row">
18+
<div class="col-md-12" *ngIf="customer && customer.latitude && customer.longitude">
19+
<cm-map [latitude]="customer.latitude"
20+
[longitude]="customer.longitude"
21+
[zoom]="10"
22+
[enabled]="mapEnabled"
23+
[markerText]="'<h3>' + customer.firstName + ' ' + customer.lastName + '</h3>' + customer.city + ', ' + customer.state.name"></cm-map>
24+
</div>
25+
</div> -->
26+
</div>
27+
<div *ngIf="!customer" class="container">
28+
No customer found
29+
</div>
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { ICustomer } from 'src/app/shared/interfaces';
3+
import { ActivatedRoute, Params } from '@angular/router';
4+
import { CustomerDataService } from 'src/app/core/services/customer-data.services';
25

36
@Component({
47
selector: 'app-customer-detail',
@@ -7,9 +10,22 @@ import { Component, OnInit } from '@angular/core';
710
})
811
export class CustomerDetailComponent implements OnInit {
912

10-
constructor() { }
13+
customer: ICustomer
14+
15+
constructor(private route: ActivatedRoute, private dataService: CustomerDataService) { }
1116

1217
ngOnInit() {
18+
19+
this.route.params.subscribe((params: Params) => {
20+
const id = +params['id'];
21+
if (id) {
22+
this.dataService.getCustomerById(id)
23+
.subscribe((customer: ICustomer) => {
24+
this.customer = customer;
25+
});
26+
}
27+
});
28+
1329
}
1430

1531
}

src/AspnetRun.Web/src/app/views/customer/customer-list/customer-grid/customer-grid.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<tr *ngFor="let customer of customers">
2020
<td><img src="assets/img/{{ customer.gender | lowercase }}.png"
2121
class="grid-image" alt="Customer Image" /></td>
22-
<td><a [routerLink]="['/customers',customer.id,'details']">{{ customer.firstName | capitalize }}</a></td>
22+
<td><a [routerLink]="['/customer/customer-detail',customer.id]">{{ customer.firstName | capitalize }}</a></td>
2323
<td>{{ customer.lastName | capitalize }}</td>
2424
<td>{{ customer.address }}</td>
2525
<td>{{ customer.city | trim }}</td>

0 commit comments

Comments
 (0)