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
f4b720d2
Commit
f4b720d2
authored
Aug 19, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add create with entity result to repos
parent
9c1bae96
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
IRepository.cs
Clinics.Backend/Domain/Repositories/Base/IRepository.cs
+3
-0
Repositroy.cs
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
+17
-1
No files found.
Clinics.Backend/Domain/Repositories/Base/IRepository.cs
View file @
f4b720d2
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Repositories.Base
{
...
...
@@ -13,6 +14,8 @@ namespace Domain.Repositories.Base
public
void
Create
(
TEntity
entity
);
public
Task
<
Result
<
TEntity
>>
CreateWithEntityResultAsync
(
TEntity
entity
);
#
endregion
#
region
Read
operations
...
...
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
View file @
f4b720d2
using
Domain.Primitives
;
using
Domain.Errors
;
using
Domain.Primitives
;
using
Domain.Repositories.Base
;
using
Domain.Shared
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Repositories.Specifications.Base
;
...
...
@@ -37,6 +39,20 @@ public class Repositroy<TEntity> : IRepository<TEntity> where TEntity : Entity
_context
.
Set
<
TEntity
>().
Add
(
entity
);
}
public
virtual
async
Task
<
Result
<
TEntity
>>
CreateWithEntityResultAsync
(
TEntity
entity
)
{
var
entry
=
await
_context
.
Set
<
TEntity
>().
AddAsync
(
entity
);
try
{
await
_context
.
SaveChangesAsync
();
}
catch
(
Exception
)
{
return
Result
.
Failure
<
TEntity
>(
PersistenceErrors
.
UnableToCompleteTransaction
);
}
return
Result
.
Success
<
TEntity
>(
entry
.
Entity
);
}
#
endregion
#
region
Read
operations
...
...
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