Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
webinar63
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
Нурбек Созоев
webinar63
Commits
0d71f7e0
Commit
0d71f7e0
authored
Jun 19, 2019
by
Нурбек Созоев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавил реализацию репозитория для работы с БД
parent
a8a13abd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
CityRepository.cs
MyCities/Repositories/CityRepository.cs
+24
-0
Startup.cs
MyCities/Startup.cs
+2
-2
No files found.
MyCities/Repositories/CityRepository.cs
0 → 100644
View file @
0d71f7e0
using
System.Collections.Generic
;
using
System.Linq
;
using
MyCities.Models
;
namespace
MyCities.Repositories
{
public
class
CityRepository
:
ICityRepository
{
private
MyCitiesDbContext
_dbContext
;
public
List
<
City
>
Cities
=>
_dbContext
.
Cities
.
ToList
();
public
CityRepository
(
MyCitiesDbContext
dbContext
)
{
_dbContext
=
dbContext
;
}
public
void
Add
(
City
city
)
{
_dbContext
.
Cities
.
Add
(
city
);
_dbContext
.
SaveChanges
();
}
}
}
MyCities/Startup.cs
View file @
0d71f7e0
...
@@ -32,8 +32,8 @@ namespace MyCities
...
@@ -32,8 +32,8 @@ namespace MyCities
string
connectionString
=
Configuration
.
GetConnectionString
(
"Default"
);
string
connectionString
=
Configuration
.
GetConnectionString
(
"Default"
);
services
.
AddDbContext
<
MyCitiesDbContext
>(
options
=>
options
.
UseNpgsql
(
connectionString
));
services
.
AddDbContext
<
MyCitiesDbContext
>(
options
=>
options
.
UseNpgsql
(
connectionString
));
services
.
Add
Singleton
<
ICityRepository
,
InMemory
CityRepository
>();
services
.
Add
Transient
<
ICityRepository
,
CityRepository
>();
services
.
Add
Singleton
<
IPersonRepository
,
InMemoryPersonRepository
>();
services
.
Add
Transient
<
IPersonRepository
,
InMemoryPersonRepository
>();
services
.
AddMvc
().
SetCompatibilityVersion
(
CompatibilityVersion
.
Version_2_1
);
services
.
AddMvc
().
SetCompatibilityVersion
(
CompatibilityVersion
.
Version_2_1
);
}
}
...
...
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