Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
webinar62
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Нурбек Созоев
webinar62
Commits
9ad3dc36
Commit
9ad3dc36
authored
Jun 15, 2019
by
Нурбек Созоев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил repository для модели Person
parent
3de5d1f9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
10 deletions
+45
-10
PersonController.cs
MyCities/Controllers/PersonController.cs
+7
-1
IPersonRepository.cs
MyCities/Repositories/IPersonRepository.cs
+11
-0
InMemoryPersonRepository.cs
MyCities/Repositories/InMemoryPersonRepository.cs
+17
-0
Startup.cs
MyCities/Startup.cs
+1
-0
Index.cshtml
MyCities/Views/Person/Index.cshtml
+9
-9
No files found.
MyCities/Controllers/PersonController.cs
View file @
9ad3dc36
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
MyCities.Repositories
;
namespace
MyCities.Controllers
namespace
MyCities.Controllers
{
{
public
class
PersonController
:
Controller
public
class
PersonController
:
Controller
{
{
private
IPersonRepository
_repository
;
public
PersonController
(
IPersonRepository
repository
)
{
_repository
=
repository
;
}
// GET
// GET
public
IActionResult
Index
()
public
IActionResult
Index
()
{
{
return
View
();
return
View
(
_repository
.
Persons
);
}
}
}
}
}
}
MyCities/Repositories/IPersonRepository.cs
0 → 100644
View file @
9ad3dc36
using
System.Collections.Generic
;
using
MyCities.Models
;
namespace
MyCities.Repositories
{
public
interface
IPersonRepository
{
List
<
Person
>
Persons
{
get
;
}
void
Add
(
Person
person
);
}
}
MyCities/Repositories/InMemoryPersonRepository.cs
0 → 100644
View file @
9ad3dc36
using
System.Collections.Generic
;
using
MyCities.Models
;
namespace
MyCities.Repositories
{
public
class
InMemoryPersonRepository
:
IPersonRepository
{
private
List
<
Person
>
_persons
=
new
List
<
Person
>();
public
List
<
Person
>
Persons
=>
_persons
;
public
void
Add
(
Person
person
)
{
_persons
.
Add
(
person
);
}
}
}
MyCities/Startup.cs
View file @
9ad3dc36
...
@@ -34,6 +34,7 @@ namespace MyCities
...
@@ -34,6 +34,7 @@ namespace MyCities
});
});
services
.
AddSingleton
<
ICityRepository
,
InMemoryCityRepository
>();
services
.
AddSingleton
<
ICityRepository
,
InMemoryCityRepository
>();
services
.
AddSingleton
<
IPersonRepository
,
InMemoryPersonRepository
>();
services
.
AddMvc
().
SetCompatibilityVersion
(
CompatibilityVersion
.
Version_2_1
);
services
.
AddMvc
().
SetCompatibilityVersion
(
CompatibilityVersion
.
Version_2_1
);
}
}
...
...
MyCities/Views/Person/Index.cshtml
View file @
9ad3dc36
@model IEnumerable<MyCities.Models.
City
>
@model IEnumerable<MyCities.Models.
Person
>
@{ Layout = "_Layout";}
@{ Layout = "_Layout";}
<table class="table small table-bordered">
<table class="table small table-bordered">
<thead>
<thead>
<tr>
<tr>
<th>Name</th>
<th>
Full
Name</th>
<th>
Counry
</th>
<th>
NickName
</th>
<th>
Population
</th>
<th>
Avatar
</th>
</tr>
</tr>
</thead>
</thead>
<tbody>
<tbody>
@foreach (var
city
in Model)
@foreach (var
person
in Model)
{
{
<tr>
<tr>
<td>@
city.
Name</td>
<td>@
person.Full
Name</td>
<td>@
city.Country
</td>
<td>@
person.NickName
</td>
<td>
@city.Population.ToString("#,###")
</td>
<td>
<img src="@person.AvatarImagePath" width="250" height="250"/>
</td>
</tr>
</tr>
}
}
</tbody>
</tbody>
</table>
</table>
<a href="/
Home/Create" class="btn btn-primary">Create city
</a>
<a href="/
Person/Create" class="btn btn-primary">Create person
</a>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment