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
5e265cb2
Commit
5e265cb2
authored
Aug 18, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Validate duplicate serial number in create employee method
parent
041d69cc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
1 deletion
+33
-1
CreateEmployeeCommandHandler.cs
...Employees/Commands/Create/CreateEmployeeCommandHandler.cs
+9
-0
DomainErrors.cs
Clinics.Backend/Domain/Errors/DomainErrors.cs
+4
-1
PersistenceErrors.cs
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
+3
-0
IEmployeesRepository.cs
Clinics.Backend/Domain/Repositories/IEmployeesRepository.cs
+5
-0
EmployeesRepository.cs
...s.Backend/Persistence/Repositories/EmployeesRepository.cs
+12
-0
No files found.
Clinics.Backend/Application/Employees/Commands/Create/CreateEmployeeCommandHandler.cs
View file @
5e265cb2
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Entities.People.Employees
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
...
...
@@ -33,6 +34,14 @@ public class CreateEmployeeCommandHandler : ICommandHandler<CreateEmployeeComman
if
(
employeeResult
.
IsFailure
)
return
Result
.
Failure
(
employeeResult
.
Error
);
#
region
Check
existed
serial
number
Result
<
Employee
>
existedResult
=
await
_employeesRepository
.
GetEmployeeBySerialNumberAsync
(
request
.
SerialNumber
);
if
(
existedResult
.
IsSuccess
)
return
Result
.
Failure
(
DomainErrors
.
EmployeeAlreadyExist
);
#
endregion
try
{
_employeesRepository
.
Create
(
employeeResult
.
Value
);
...
...
Clinics.Backend/Domain/Errors/DomainErrors.cs
View file @
5e265cb2
...
...
@@ -25,6 +25,9 @@ public static class DomainErrors
public
static
Error
PhoneAlreadyExist
=>
new
(
"Domain.PhoneAlreadyExist"
,
"رقم الهاتف موجود بالفعل"
);
public
static
Error
EmployeeAlreadyExist
=>
new
(
"Domain.EmployeeAlreadyExist"
,
"الموظف موجود بالفعل"
);
public
static
Error
VisitAlreadyHasThisMedicine
=>
new
(
"Domain.VisitAlreadyHasThisMedicine"
,
"تحتوي الوصفة الطبية بالفعل على الدواء الذي تحاول اضافته"
);
...
...
@@ -32,6 +35,6 @@ public static class DomainErrors
new
(
"Domain.VisitAlreadyHasThisMedicalTest"
,
"تحتوي هذه الزيارة بالفعل على التحليل الطبي الذي تحاول اضافته"
);
public
static
Error
VisitAlreadyHasThisMedicalImage
=>
new
(
"Domain.PatientAlreadyHasThisMedicine"
,
"تحتوي هذه الزيارة بالفعل على الصورة التي تحاول اضافتها"
);
new
(
"Domain.PatientAlreadyHasThisMedicine"
,
"تحتوي هذه الزيارة بالفعل على الصورة التي تحاول اضافتها"
);
}
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
View file @
5e265cb2
...
...
@@ -6,4 +6,7 @@ public static class PersistenceErrors
{
public
static
Error
UnableToCompleteTransaction
=>
new
(
"Persistence.UnableToCompleteTransaction"
,
"حدثت مشكلة عند الاتصال مع قاعدة البيانات"
);
public
static
Error
NotFound
=>
new
(
"Persistence.NotFound"
,
"الغرض المطلوب غير موجود"
);
}
Clinics.Backend/Domain/Repositories/IEmployeesRepository.cs
View file @
5e265cb2
using
Domain.Entities.People.Employees
;
using
Domain.Repositories.Base
;
using
Domain.Shared
;
namespace
Domain.Repositories
;
public
interface
IEmployeesRepository
:
IRepository
<
Employee
>
{
#
region
Get
by
serial
number
public
Task
<
Result
<
Employee
>>
GetEmployeeBySerialNumberAsync
(
string
serialNumber
);
#
endregion
}
Clinics.Backend/Persistence/Repositories/EmployeesRepository.cs
View file @
5e265cb2
using
Domain.Entities.People.Employees
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Repositories.Base
;
...
...
@@ -18,4 +20,14 @@ public class EmployeesRepository : Repositroy<Employee>, IEmployeesRepository
}
#
endregion
#
region
Get
by
serial
Number
public
async
Task
<
Result
<
Employee
>>
GetEmployeeBySerialNumberAsync
(
string
serialNumber
)
{
var
all
=
await
_context
.
Set
<
Employee
>().
Where
(
employee
=>
employee
.
SerialNumber
==
serialNumber
).
ToListAsync
();
if
(
all
.
Count
!=
1
)
return
Result
.
Failure
<
Employee
>(
PersistenceErrors
.
NotFound
);
return
Result
.
Success
<
Employee
>(
all
.
First
());
}
#
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