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
9ed541c5
Commit
9ed541c5
authored
Aug 19, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Update repos
parent
825ca353
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
31 deletions
+63
-31
PersistenceErrors.cs
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
+9
-0
IRepository.cs
Clinics.Backend/Domain/Repositories/Base/IRepository.cs
+5
-9
Repositroy.cs
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
+49
-22
No files found.
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
View file @
9ed541c5
...
...
@@ -7,6 +7,15 @@ public static class PersistenceErrors
public
static
Error
UnableToCompleteTransaction
=>
new
(
"Persistence.UnableToCompleteTransaction"
,
"حدثت مشكلة عند الاتصال مع قاعدة البيانات"
);
public
static
Error
UnableToCreate
=>
new
(
"Persistence.UnableToCreate"
,
"فشلت عملية الإضافة"
);
public
static
Error
UnableToUpdate
=>
new
(
"Persistence.UnableToUpdate"
,
"فشلت عملية التعديل"
);
public
static
Error
UnableToDelete
=>
new
(
"Persistence.UnableToDelete"
,
"فشلت عملية الحذف"
);
public
static
Error
NotFound
=>
new
(
"Persistence.NotFound"
,
"الغرض المطلوب غير موجود"
);
}
Clinics.Backend/Domain/Repositories/Base/IRepository.cs
View file @
9ed541c5
...
...
@@ -3,8 +3,6 @@ using Domain.Shared;
namespace
Domain.Repositories.Base
{
// Note that queries are async, but commands are NOT
// Since the persist operation is done by UnitOfWork
public
interface
IRepository
<
TEntity
>
where
TEntity
:
Entity
{
...
...
@@ -12,29 +10,27 @@ namespace Domain.Repositories.Base
#
region
Create
operation
public
void
Create
(
TEntity
entity
);
public
Task
<
Result
<
TEntity
>>
CreateWithEntityResultAsync
(
TEntity
entity
);
public
Task
<
Result
<
TEntity
>>
CreateAsync
(
TEntity
entity
);
#
endregion
#
region
Read
operations
public
Task
<
TEntity
?
>
GetByIdAsync
(
int
id
);
public
Task
<
Result
<
TEntity
>
>
GetByIdAsync
(
int
id
);
public
Task
<
ICollection
<
TEntity
>>
GetAllAsync
();
public
Task
<
Result
<
ICollection
<
TEntity
>
>>
GetAllAsync
();
#
endregion
#
region
Update
oprtation
public
void
Update
(
TEntity
entity
);
public
Task
<
Result
>
UpdateAsync
(
TEntity
entity
);
#
endregion
#
region
Delete
operation
public
void
Delete
(
TEntity
entity
);
public
Task
<
Result
>
DeleteAsync
(
TEntity
entity
);
#
endregion
}
...
...
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
View file @
9ed541c5
...
...
@@ -24,7 +24,7 @@ public class Repositroy<TEntity> : IRepository<TEntity> where TEntity : Entity
#
endregion
#
region
Apply
specification
protected
IQueryable
<
TEntity
>
ApplySpecification
(
Specification
<
TEntity
>
specification
)
protected
IQueryable
<
TEntity
>
ApplySpecification
(
Specification
<
TEntity
>
specification
)
{
return
SpecificationEvaluator
.
GetQuery
(
_context
.
Set
<
TEntity
>(),
specification
);
}
...
...
@@ -34,57 +34,84 @@ public class Repositroy<TEntity> : IRepository<TEntity> where TEntity : Entity
#
region
Create
operation
public
virtual
void
Create
(
TEntity
entity
)
public
async
Task
<
Result
<
TEntity
>>
CreateAsync
(
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
{
var
createdEntity
=
await
_context
.
Set
<
TEntity
>().
AddAsync
(
entity
);
await
_context
.
SaveChangesAsync
();
return
Result
.
Success
<
TEntity
>(
createdEntity
.
Entity
);
}
catch
(
Exception
)
{
return
Result
.
Failure
<
TEntity
>(
PersistenceErrors
.
UnableToC
ompleteTransaction
);
return
Result
.
Failure
<
TEntity
>(
PersistenceErrors
.
UnableToC
reate
);
}
return
Result
.
Success
<
TEntity
>(
entry
.
Entity
);
}
#
endregion
#
region
Read
operations
public
virtual
async
Task
<
TEntity
?>
GetByIdAsync
(
int
id
)
public
async
Task
<
Result
<
TEntity
>>
GetByIdAsync
(
int
id
)
{
try
{
return
await
_context
.
Set
<
TEntity
>().
FindAsync
(
id
);
var
entity
=
await
_context
.
Set
<
TEntity
>().
FirstAsync
(
e
=>
e
.
Id
==
id
);
return
Result
.
Success
<
TEntity
>(
entity
);
}
catch
(
Exception
)
{
return
Result
.
Failure
<
TEntity
>(
PersistenceErrors
.
NotFound
);
}
}
public
virtual
async
Task
<
ICollection
<
TEntity
>>
GetAllAsync
()
public
async
Task
<
Result
<
ICollection
<
TEntity
>>>
GetAllAsync
()
{
try
{
return
await
_context
.
Set
<
TEntity
>().
ToListAsync
();
var
entites
=
await
_context
.
Set
<
TEntity
>().
ToListAsync
();
return
Result
.
Success
<
ICollection
<
TEntity
>>(
entites
);
}
catch
(
Exception
)
{
return
Result
.
Failure
<
ICollection
<
TEntity
>>(
PersistenceErrors
.
NotFound
);
}
}
#
endregion
#
region
Update
operation
public
virtual
void
Update
(
TEntity
entity
)
public
async
Task
<
Result
>
UpdateAsync
(
TEntity
entity
)
{
try
{
_context
.
Set
<
TEntity
>().
Update
(
entity
);
await
_context
.
SaveChangesAsync
();
return
Result
.
Success
();
}
catch
(
Exception
)
{
return
Result
.
Failure
(
PersistenceErrors
.
UnableToUpdate
);
}
}
#
endregion
#
region
Delete
operation
public
virtual
void
Delete
(
TEntity
entity
)
public
async
Task
<
Result
>
DeleteAsync
(
TEntity
entity
)
{
try
{
_context
.
Set
<
TEntity
>().
Remove
(
entity
);
await
_context
.
SaveChangesAsync
();
return
Result
.
Success
();
}
catch
(
Exception
)
{
return
Result
.
Failure
(
PersistenceErrors
.
UnableToDelete
);
}
}
#
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