Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HIAST-Clinics
Project
Project
Details
Activity
Releases
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
almohanad.hafez
HIAST-Clinics
Commits
d42c6ffd
Commit
d42c6ffd
authored
Aug 16, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add base repositories
parent
ebcadca6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
0 deletions
+111
-0
IRepository.cs
Clinics.Backend/Domain/Repositories/Base/IRepository.cs
+36
-0
Repositroy.cs
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
+75
-0
No files found.
Clinics.Backend/Domain/Repositories/Base/IRepository.cs
0 → 100644
View file @
d42c6ffd
using
Domain.Primitives
;
namespace
Domain.Repositories.Base
{
// CRUD operations
public
interface
IRepository
<
TEntity
>
where
TEntity
:
Entity
{
#
region
Create
operation
public
Task
<
TEntity
>
CreateAsync
(
TEntity
entity
);
#
endregion
#
region
Read
operations
public
Task
<
TEntity
?>
GetByIdAsync
(
int
id
);
public
Task
<
ICollection
<
TEntity
>>
GetAllAsync
();
#
endregion
#
region
Update
oprtation
public
Task
<
TEntity
>
UpdateAsync
(
TEntity
entity
);
#
endregion
#
region
Delete
operation
public
Task
DeleteAsync
(
int
id
);
#
endregion
}
}
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
0 → 100644
View file @
d42c6ffd
using
Domain.Primitives
;
using
Domain.Repositories.Base
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
namespace
Persistence.Repositories.Base
;
public
class
Repositroy
<
TEntity
>
:
IRepository
<
TEntity
>
where
TEntity
:
Entity
{
#
region
Ctor
DI
for
context
private
readonly
ClinicsDbContext
_context
;
public
Repositroy
(
ClinicsDbContext
context
)
{
_context
=
context
;
}
#
endregion
#
region
Create
operation
public
async
Task
<
TEntity
>
CreateAsync
(
TEntity
entity
)
{
return
await
_context
.
Set
<
TEntity
>().
FirstAsync
(
e
=>
e
.
Id
==
entity
.
Id
);
}
#
endregion
#
region
Read
operations
public
async
Task
<
TEntity
?>
GetByIdAsync
(
int
id
)
{
return
await
_context
.
Set
<
TEntity
>().
FindAsync
(
id
);
}
public
async
Task
<
ICollection
<
TEntity
>>
GetAllAsync
()
{
return
await
_context
.
Set
<
TEntity
>().
ToListAsync
<
TEntity
>();
}
#
endregion
#
region
Update
operation
public
async
Task
<
TEntity
>
UpdateAsync
(
TEntity
entity
)
{
var
query
=
_context
.
Set
<
TEntity
>().
Update
(
entity
);
await
_context
.
SaveChangesAsync
();
return
query
.
Entity
;
}
#
endregion
#
region
Delete
operation
public
async
Task
DeleteAsync
(
int
id
)
{
var
entity
=
await
GetByIdAsync
(
id
);
if
(
entity
is
not
null
)
_context
.
Set
<
TEntity
>().
Remove
(
entity
);
await
_context
.
SaveChangesAsync
();
}
#
endregion
}
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