Skip to content

Commit 0d55237

Browse files
author
breno.dev
committed
Seller details and eager loading
1 parent 1c4079f commit 0d55237

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

SalesWebMvc/Controllers/SellersController.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,20 @@ public IActionResult Delete(int id)
6666
return RedirectToAction(nameof(Index));
6767
}
6868

69+
public IActionResult Details(int? id)
70+
{
71+
if (id == null)
72+
{
73+
return NotFound();
74+
}
75+
76+
var obj = _sellerService.FindById(id.Value);
77+
if (obj == null)
78+
{
79+
return NotFound();
80+
}
81+
return View(obj);
82+
}
83+
6984
}
7085
}

SalesWebMvc/Services/SellerService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using SalesWebMvc.Models;
6+
using Microsoft.EntityFrameworkCore;
67

78
namespace SalesWebMvc.Services
89
{
@@ -28,7 +29,7 @@ public void Insert(Seller obj)
2829

2930
public Seller FindById(int id)
3031
{
31-
return _context.Seller.FirstOrDefault(obj => obj.Id == id);
32+
return _context.Seller.Include(obj => obj.Department).FirstOrDefault(obj => obj.Id == id);
3233
}
3334

3435
public void Remove(int id)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
@model SalesWebMvc.Models.Seller
2+
3+
@{
4+
ViewData["Title"] = "Details";
5+
}
6+
7+
<h2>@ViewData["Title"]</h2>
8+
9+
10+
<div>
11+
<h4>Seller</h4>
12+
<hr />
13+
<dl class="dl-horizontal">
14+
<dt>
15+
@Html.DisplayNameFor(model => model.Name)
16+
</dt>
17+
<dd>
18+
@Html.DisplayFor(model => model.Name)
19+
</dd>
20+
21+
<dt>
22+
@Html.DisplayNameFor(model => model.Email)
23+
</dt>
24+
<dd>
25+
@Html.DisplayFor(model => model.Email)
26+
</dd>
27+
28+
<dt>
29+
@Html.DisplayNameFor(model => model.BirthDate)
30+
</dt>
31+
<dd>
32+
@Html.DisplayFor(model => model.BirthDate)
33+
</dd>
34+
35+
<dt>
36+
@Html.DisplayNameFor(model => model.BaseSalary)
37+
</dt>
38+
<dd>
39+
@Html.DisplayFor(model => model.BaseSalary)
40+
</dd>
41+
<dt>
42+
@Html.DisplayNameFor(model => model.Department)
43+
</dt>
44+
<dd>
45+
@Html.DisplayFor(model => model.Department.Name)
46+
</dd>
47+
</dl>
48+
49+
50+
</div>
51+
<div>
52+
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-default">Edit</a>
53+
<a asp-action="Index">Back to list</a>
54+
</div>

0 commit comments

Comments
 (0)