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
ec58ab00
Unverified
Commit
ec58ab00
authored
Aug 18, 2024
by
Almouhannad Hafez
Committed by
GitHub
Aug 18, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7 from Almouhannad/B_Add-result-pattern
B add result pattern
parents
caf7e1cb
6fea5553
Changes
39
Hide whitespace changes
Inline
Side-by-side
Showing
39 changed files
with
710 additions
and
361 deletions
+710
-361
ICommand.cs
...ackend/Application/Abstractions/CQRS/Commands/ICommand.cs
+4
-3
ICommandHandler.cs
...Application/Abstractions/CQRS/Commands/ICommandHandler.cs
+4
-3
IQuery.cs
...s.Backend/Application/Abstractions/CQRS/Queries/IQuery.cs
+3
-2
IQueryHandler.cs
...nd/Application/Abstractions/CQRS/Queries/IQueryHandler.cs
+3
-2
CreateEmployeeCommandHandler.cs
...Employees/Commands/Create/CreateEmployeeCommandHandler.cs
+20
-23
Disease.cs
Clinics.Backend/Domain/Entities/Medicals/Diseases/Disease.cs
+4
-4
Hospital.cs
...cs.Backend/Domain/Entities/Medicals/Hospitals/Hospital.cs
+5
-5
MedicalImage.cs
...nd/Domain/Entities/Medicals/MedicalImages/MedicalImage.cs
+6
-6
MedicalTest.cs
...kend/Domain/Entities/Medicals/MedicalTests/MedicalTest.cs
+6
-6
Medicine.cs
...cs.Backend/Domain/Entities/Medicals/Medicines/Medicine.cs
+13
-12
MedicineForm.cs
...ies/Medicals/Medicines/MedicineFormValues/MedicineForm.cs
+6
-6
MedicineForms.cs
...es/Medicals/Medicines/MedicineFormValues/MedicineForms.cs
+24
-4
Doctor.cs
Clinics.Backend/Domain/Entities/People/Doctors/Doctor.cs
+28
-28
DoctorPhone.cs
...kend/Domain/Entities/People/Doctors/Shared/DoctorPhone.cs
+6
-6
DoctorStatus.cs
.../People/Doctors/Shared/DoctorStatusValues/DoctorStatus.cs
+7
-6
DoctorStatuses.cs
...eople/Doctors/Shared/DoctorStatusValues/DoctorStatuses.cs
+34
-5
Employee.cs
Clinics.Backend/Domain/Entities/People/Employees/Employee.cs
+69
-41
EmployeeFamilyMember.cs
...s/Relations/EmployeeFamilyMembers/EmployeeFamilyMember.cs
+17
-18
FamilyRole.cs
...ions/EmployeeFamilyMembers/FamilyRoleValues/FamilyRole.cs
+6
-6
FamilyRoles.cs
...ons/EmployeeFamilyMembers/FamilyRoleValues/FamilyRoles.cs
+43
-5
FamilyMember.cs
...kend/Domain/Entities/People/FamilyMembers/FamilyMember.cs
+7
-13
Patient.cs
Clinics.Backend/Domain/Entities/People/Patients/Patient.cs
+36
-44
PatientDisease.cs
...ople/Patients/Relations/PatientDiseases/PatientDisease.cs
+7
-7
PatientMedicine.cs
...le/Patients/Relations/PatientMedicines/PatientMedicine.cs
+8
-8
Gender.cs
...kend/Domain/Entities/People/Shared/GenderValues/Gender.cs
+5
-5
Genders.cs
...end/Domain/Entities/People/Shared/GenderValues/Genders.cs
+24
-4
PersonalInfo.cs
...ics.Backend/Domain/Entities/People/Shared/PersonalInfo.cs
+4
-4
VisitMedicalImage.cs
.../Visits/Relations/VisitMedicalImages/VisitMedicalImage.cs
+11
-10
VisitMedicalTest.cs
...es/Visits/Relations/VisitMedicalTests/VisitMedicalTest.cs
+11
-11
VisitMedicine.cs
...Entities/Visits/Relations/VisitMedicines/VisitMedicine.cs
+8
-8
Visit.cs
Clinics.Backend/Domain/Entities/Visits/Visit.cs
+56
-48
WaitingListRecord.cs
....Backend/Domain/Entities/WaitingList/WaitingListRecord.cs
+7
-5
DomainErrors.cs
Clinics.Backend/Domain/Errors/DomainErrors.cs
+37
-0
PersistenceErrors.cs
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
+9
-0
Error.cs
Clinics.Backend/Domain/Shared/Error.cs
+65
-0
Result.cs
Clinics.Backend/Domain/Shared/Result.cs
+56
-0
ResultT.cs
Clinics.Backend/Domain/Shared/ResultT.cs
+46
-0
UnitOfWork.cs
Clinics.Backend/Persistence/UnitOfWork/UnitOfWork.cs
+1
-1
EmployeesController.cs
...s.Backend/Presentation/Controllers/EmployeesController.cs
+4
-2
No files found.
Clinics.Backend/Application/Abstractions/CQRS/Commands/ICommand.cs
View file @
ec58ab00
using
MediatR
;
using
Domain.Shared
;
using
MediatR
;
namespace
Application.Abstractions.CQRS.Commands
;
// No response
public
interface
ICommand
:
IRequest
public
interface
ICommand
:
IRequest
<
Result
>
{
}
// With response
public
interface
ICommand
<
TResponse
>
:
IRequest
<
TResponse
>
public
interface
ICommand
<
TResponse
>
:
IRequest
<
Result
<
TResponse
>
>
{
}
Clinics.Backend/Application/Abstractions/CQRS/Commands/ICommandHandler.cs
View file @
ec58ab00
using
MediatR
;
using
Domain.Shared
;
using
MediatR
;
namespace
Application.Abstractions.CQRS.Commands
;
// No response
public
interface
ICommandHandler
<
TCommand
>
:
IRequestHandler
<
TCommand
>
public
interface
ICommandHandler
<
TCommand
>
:
IRequestHandler
<
TCommand
,
Result
>
where
TCommand
:
ICommand
{
}
// With response
public
interface
ICommandHandler
<
TCommand
,
TResponse
>
:
IRequestHandler
<
TCommand
,
TResponse
>
:
IRequestHandler
<
TCommand
,
Result
<
TResponse
>
>
where
TCommand
:
ICommand
<
TResponse
>
{
}
\ No newline at end of file
Clinics.Backend/Application/Abstractions/CQRS/Queries/IQuery.cs
View file @
ec58ab00
using
MediatR
;
using
Domain.Shared
;
using
MediatR
;
namespace
Application.Abstractions.CQRS.Queries
;
public
interface
IQuery
<
TResponse
>
:
IRequest
<
TResponse
>
public
interface
IQuery
<
TResponse
>
:
IRequest
<
Result
<
TResponse
>
>
{
}
Clinics.Backend/Application/Abstractions/CQRS/Queries/IQueryHandler.cs
View file @
ec58ab00
using
MediatR
;
using
Domain.Shared
;
using
MediatR
;
namespace
Application.Abstractions.CQRS.Queries
;
public
interface
IQueryHandler
<
TQuery
,
TResponse
>
:
IRequestHandler
<
TQuery
,
TResponse
>
:
IRequestHandler
<
TQuery
,
Result
<
TResponse
>
>
where
TQuery
:
IQuery
<
TResponse
>
{
}
Clinics.Backend/Application/Employees/Commands/Create/CreateEmployeeCommandHandler.cs
View file @
ec58ab00
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Entities.People.Employees
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.Employees.Commands.Create
;
...
...
@@ -17,39 +18,35 @@ public class CreateEmployeeCommandHandler : ICommandHandler<CreateEmployeeComman
}
#
endregion
public
async
Task
Handle
(
CreateEmployeeCommand
request
,
CancellationToken
cancellationToken
)
public
async
Task
<
Result
>
Handle
(
CreateEmployeeCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
Create
new
employee
Employee
employee
;
try
{
employee
=
Employee
.
Create
(
request
.
FirstName
,
request
.
MiddleName
,
request
.
LastName
,
// Personal info
Result
<
Employee
>
employeeResult
=
Employee
.
Create
(
request
.
FirstName
,
request
.
MiddleName
,
request
.
LastName
,
request
.
DateOfBirth
,
request
.
Gender
,
// Patient info
request
.
DateOfBirth
,
request
.
Gender
,
request
.
SerialNumber
,
request
.
CenterStatus
,
false
,
request
.
SerialNumber
,
request
.
CenterStatus
,
false
,
// Employee info
request
.
StartDate
,
request
.
AcademicQualification
,
request
.
WorkPhone
,
request
.
Location
,
request
.
Specialization
,
request
.
JobStatus
);
if
(
employeeResult
.
IsFailure
)
return
Result
.
Failure
(
employeeResult
.
Error
);
request
.
StartDate
,
request
.
AcademicQualification
,
request
.
WorkPhone
,
// additional
request
.
Location
,
request
.
Specialization
,
request
.
JobStatus
);
}
catch
(
Exception
)
{
throw
;
}
#
endregion
#
region
Add
to
DB
try
{
_employeesRepository
.
Create
(
employee
);
_employeesRepository
.
Create
(
employee
Result
.
Value
);
await
_unitOfWork
.
SaveChangesAsync
();
}
catch
(
Exception
)
catch
(
Exception
exp
)
{
throw
;
// For debugging
//return Result.Failure(new Error("Persistence.UnableToSaveTransaction", exp.Message));
// For deployment
return
Result
.
Failure
(
Domain
.
Errors
.
PersistenceErrors
.
UnableToCompleteTransaction
);
}
#
endregion
return
Result
.
Success
();
}
}
Clinics.Backend/Domain/Entities/Medicals/Diseases/Disease.cs
View file @
ec58ab00
using
Domain.Entities.People.Patients.Relations.PatientDiseases
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.Medicals.Diseases
;
...
...
@@ -18,7 +18,7 @@ public sealed class Disease : Entity
#
region
Properties
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
#
region
Navigations
...
...
@@ -35,10 +35,10 @@ public sealed class Disease : Entity
#
region
Methods
#
region
Static
factory
public
static
Disease
Create
(
string
name
)
public
static
Result
<
Disease
>
Create
(
string
name
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
Disease
>(
);
return
Result
.
Failure
<
Disease
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
Disease
(
0
,
name
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/Medicals/Hospitals/Hospital.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.Medicals.Hospitals
;
...
...
@@ -18,17 +18,17 @@ public sealed class Hospital : Entity
#
region
Properties
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Methods
#
region
Static
factory
public
static
Hospital
Create
(
string
name
)
public
static
Result
<
Hospital
>
Create
(
string
name
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
Hospital
>(
);
return
Result
.
Failure
<
Hospital
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
Hospital
(
0
,
name
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/Medicals/MedicalImages/MedicalImage.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.Medicals.MedicalImages
;
...
...
@@ -17,19 +17,19 @@ public sealed class MedicalImage : Entity
#
region
Properties
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
public
string
?
Description
{
get
;
set
;
}
public
string
?
Description
{
get
;
private
set
;
}
#
endregion
#
region
Methods
#
region
Static
factory
public
static
MedicalImage
Create
(
string
name
,
string
?
description
=
null
)
public
static
Result
<
MedicalImage
>
Create
(
string
name
,
string
?
description
=
null
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
MedicalImage
>(
);
return
Result
.
Failure
<
MedicalImage
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
MedicalImage
(
0
,
name
,
description
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/Medicals/MedicalTests/MedicalTest.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.Medicals.MedicalTests
;
...
...
@@ -17,19 +17,19 @@ public sealed class MedicalTest : Entity
#
region
Properties
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
public
string
?
Description
{
get
;
set
;
}
public
string
?
Description
{
get
;
private
set
;
}
#
endregion
#
region
Methods
#
region
Static
factory
public
static
MedicalTest
Create
(
string
name
,
string
description
)
public
static
Result
<
MedicalTest
>
Create
(
string
name
,
string
description
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
MedicalTest
>(
);
return
Result
.
Failure
<
MedicalTest
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
MedicalTest
(
0
,
name
,
description
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/Medicals/Medicines/Medicine.cs
View file @
ec58ab00
using
Domain.Entities.Medicals.Medicines.MedicineFormValues
;
using
Domain.Entities.People.Patients.Relations.PatientMedicines
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.Medicals.Medicines
;
...
...
@@ -24,13 +24,13 @@ public sealed class Medicine : Entity
#
region
Properties
public
MedicineForm
MedicineForm
{
get
;
set
;
}
=
null
!;
public
MedicineForm
MedicineForm
{
get
;
private
set
;
}
=
null
!;
public
int
Amount
{
get
;
set
;
}
public
int
Amount
{
get
;
private
set
;
}
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
public
decimal
Dosage
{
get
;
set
;
}
public
decimal
Dosage
{
get
;
private
set
;
}
#
region
Navigations
...
...
@@ -48,26 +48,27 @@ public sealed class Medicine : Entity
#
region
Methods
#
region
Static
factory
public
static
Medicine
Create
(
string
form
,
int
amount
,
string
name
,
decimal
dosage
)
public
static
Result
<
Medicine
>
Create
(
string
form
,
int
amount
,
string
name
,
decimal
dosage
)
{
if
(
form
is
null
||
name
is
null
||
amount
<
0
||
dosage
<
0
)
throw
new
InvalidValuesDomainException
<
Medicine
>(
);
return
Result
.
Failure
<
Medicine
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
region
Check
form
MedicineForm
selectedMedicineForm
;
Result
<
MedicineForm
>
selectedMedicineForm
=
new
(
null
,
false
,
Errors
.
DomainErrors
.
InvalidValuesError
)
;
MedicineForm
tablet
=
MedicineForms
.
Tablet
;
MedicineForm
syrup
=
MedicineForms
.
Syrup
;
if
(
form
==
tablet
.
Name
)
selectedMedicineForm
=
tablet
;
selectedMedicineForm
=
Result
.
Success
<
MedicineForm
>(
tablet
)
;
else
if
(
form
==
syrup
.
Name
)
selectedMedicineForm
=
syrup
;
else
throw
new
InvalidValuesDomainException
<
MedicineForm
>();
selectedMedicineForm
=
Result
.
Success
<
MedicineForm
>(
syrup
);
if
(
selectedMedicineForm
.
IsFailure
)
return
Result
.
Failure
<
Medicine
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
return
new
Medicine
(
0
,
selectedMedicineForm
,
amount
,
name
,
dosage
);
return
new
Medicine
(
0
,
selectedMedicineForm
.
Value
,
amount
,
name
,
dosage
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/Medicals/Medicines/MedicineFormValues/MedicineForm.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.Medicals.Medicines.MedicineFormValues
;
...
...
@@ -16,22 +16,22 @@ public sealed class MedicineForm : Entity
#
region
Properties
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Methods
#
region
Static
factory
public
static
MedicineForm
Create
(
string
name
,
int
?
id
)
public
static
Result
<
MedicineForm
>
Create
(
string
name
,
int
?
id
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
MedicineForm
>(
);
return
Result
.
Failure
<
MedicineForm
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
if
(
id
is
not
null
)
{
if
(
id
<
0
)
throw
new
InvalidValuesDomainException
<
MedicineForm
>(
);
return
Result
.
Failure
<
MedicineForm
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
MedicineForm
(
id
.
Value
,
name
);
}
return
new
MedicineForm
(
0
,
name
);
...
...
Clinics.Backend/Domain/Entities/Medicals/Medicines/MedicineFormValues/MedicineForms.cs
View file @
ec58ab00
namespace
Domain.Entities.Medicals.Medicines.MedicineFormValues
;
using
Domain.Exceptions.InvalidValue
;
namespace
Domain.Entities.Medicals.Medicines.MedicineFormValues
;
public
static
class
MedicineForms
{
#
region
Constant
id
values
#
region
Constant
values
public
static
MedicineForm
Tablet
=>
MedicineForm
.
Create
(
"حبوب"
,
1
);
public
static
MedicineForm
Tablet
{
get
{
var
result
=
MedicineForm
.
Create
(
"حبوب"
,
1
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
MedicineForm
>();
return
result
.
Value
;
}
}
public
static
MedicineForm
Syrup
=>
MedicineForm
.
Create
(
"شراب"
,
2
);
public
static
MedicineForm
Syrup
{
get
{
var
result
=
MedicineForm
.
Create
(
"شراب"
,
2
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
MedicineForm
>();
return
result
.
Value
;
}
}
#
endregion
}
Clinics.Backend/Domain/Entities/People/Doctors/Doctor.cs
View file @
ec58ab00
using
Domain.Entities.People.Doctors.Shared
;
using
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
using
Domain.Entities.People.Shared
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.Doctors
;
...
...
@@ -22,9 +22,9 @@ public sealed class Doctor : Entity
#
region
Properties
public
PersonalInfo
PersonalInfo
{
get
;
set
;
}
=
null
!;
public
PersonalInfo
PersonalInfo
{
get
;
private
set
;
}
=
null
!;
public
DoctorStatus
Status
{
get
;
set
;
}
=
null
!;
public
DoctorStatus
Status
{
get
;
private
set
;
}
=
null
!;
#
region
Navigations
...
...
@@ -41,45 +41,45 @@ public sealed class Doctor : Entity
#
region
Methods
#
region
Static
factory
public
static
Doctor
Create
(
string
firstName
,
string
middleName
,
string
lastName
)
public
static
Result
<
Doctor
>
Create
(
string
firstName
,
string
middleName
,
string
lastName
)
{
PersonalInfo
personalInfo
;
try
{
personalInfo
=
PersonalInfo
.
Create
(
firstName
,
middleName
,
lastName
);
}
catch
{
throw
;
}
Result
<
PersonalInfo
>
personalInfo
=
PersonalInfo
.
Create
(
firstName
,
middleName
,
lastName
);
if
(
personalInfo
.
IsFailure
)
return
Result
.
Failure
<
Doctor
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
Doctor
(
0
,
personalInfo
);
return
new
Doctor
(
0
,
personalInfo
.
Value
);
}
#
endregion
#
region
Add
phone
public
void
AddPhone
(
string
phone
,
string
?
number
=
null
)
public
Result
AddPhone
(
string
phone
,
string
?
name
=
null
)
{
DoctorPhone
doctorPhone
;
try
{
doctorPhone
=
DoctorPhone
.
Create
(
phone
,
number
);
}
catch
{
throw
;
}
_phones
.
Add
(
doctorPhone
);
#
region
Create
number
to
attach
Result
<
DoctorPhone
>
doctorPhone
=
DoctorPhone
.
Create
(
phone
,
name
);
if
(
doctorPhone
.
IsFailure
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Check
duplicate
if
(
Phones
.
Where
(
p
=>
p
.
Phone
==
phone
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
PhoneAlreadyExist
);
#
endregion
_phones
.
Add
(
doctorPhone
.
Value
);
return
Result
.
Success
();
}
#
endregion
#
region
Change
status
public
void
ChangeStatusTo
(
DoctorStatus
status
)
public
Result
ChangeStatusTo
(
DoctorStatus
status
)
{
if
(
status
==
DoctorStatuses
.
Available
||
status
==
DoctorStatuses
.
Busy
||
status
==
DoctorStatuses
.
Working
)
{
Status
=
status
;
throw
new
InvalidValuesDomainException
<
DoctorStatus
>();
return
Result
.
Success
();
}
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/People/Doctors/Shared/DoctorPhone.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.People.Doctors.Shared
;
...
...
@@ -18,9 +18,9 @@ public sealed class DoctorPhone : Entity
#
region
Properties
public
string
?
Name
{
get
;
set
;
}
public
string
?
Name
{
get
;
private
set
;
}
public
string
Phone
{
get
;
set
;
}
=
null
!;
public
string
Phone
{
get
;
private
set
;
}
=
null
!;
#
endregion
...
...
@@ -28,10 +28,10 @@ public sealed class DoctorPhone : Entity
#
region
Static
factory
public
static
DoctorPhone
Create
(
string
phone
,
string
?
name
)
public
static
Result
<
DoctorPhone
>
Create
(
string
phone
,
string
?
name
)
{
if
(
phone
is
null
)
throw
new
InvalidValuesDomainException
<
DoctorPhone
>(
);
return
Result
.
Failure
<
DoctorPhone
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
DoctorPhone
(
0
,
phone
,
name
);
}
...
...
Clinics.Backend/Domain/Entities/People/Doctors/Shared/DoctorStatusValues/DoctorStatus.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
...
...
@@ -19,21 +19,22 @@ public sealed class DoctorStatus : Entity
#
region
Properties
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Methods
#
region
Static
factory
public
static
DoctorStatus
Create
(
string
name
,
int
?
id
)
public
static
Result
<
DoctorStatus
>
Create
(
string
name
,
int
?
id
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
DoctorStatus
>(
);
return
Result
.
Failure
<
DoctorStatus
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
if
(
id
is
not
null
)
{
if
(
id
<
0
)
throw
new
InvalidValuesDomainException
<
DoctorStatus
>();
return
Result
.
Failure
<
DoctorStatus
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
DoctorStatus
(
id
.
Value
,
name
);
}
...
...
Clinics.Backend/Domain/Entities/People/Doctors/Shared/DoctorStatusValues/DoctorStatuses.cs
View file @
ec58ab00
namespace
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
using
Domain.Exceptions.InvalidValue
;
namespace
Domain.Entities.People.Doctors.Shared.Constants.DoctorStatusValues
;
public
static
class
DoctorStatuses
{
#
region
Constant
id
values
#
region
Constant
values
public
static
DoctorStatus
Available
=>
DoctorStatus
.
Create
(
"متاح"
,
1
);
public
static
DoctorStatus
Available
{
get
{
var
result
=
DoctorStatus
.
Create
(
"متاح"
,
1
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
DoctorStatus
>();
return
result
.
Value
;
}
}
public
static
DoctorStatus
Working
=>
DoctorStatus
.
Create
(
"لديه مريض"
,
1
);
public
static
DoctorStatus
Working
{
get
{
var
result
=
DoctorStatus
.
Create
(
"لديه مريض"
,
1
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
DoctorStatus
>();
return
result
.
Value
;
}
}
public
static
DoctorStatus
Busy
=>
DoctorStatus
.
Create
(
"مشغول"
,
1
);
public
static
DoctorStatus
Busy
{
get
{
var
result
=
DoctorStatus
.
Create
(
"مشغول"
,
1
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
DoctorStatus
>();
return
result
.
Value
;
}
}
#
endregion
}
Clinics.Backend/Domain/Entities/People/Employees/Employee.cs
View file @
ec58ab00
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers
;
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
using
Domain.Entities.People.Employees.Shared
;
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Entities.People.Patients
;
using
Domain.E
xceptions.InvalidValue
;
using
Domain.E
ntities.People.Shared.GenderValues
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.Employees
;
...
...
@@ -30,15 +32,15 @@ public sealed class Employee : Entity
#
region
Properties
public
Patient
Patient
{
get
;
set
;
}
=
null
!;
public
Patient
Patient
{
get
;
private
set
;
}
=
null
!;
public
EmployeeAdditionalInfo
?
AdditionalInfo
{
get
;
set
;
}
public
EmployeeAdditionalInfo
?
AdditionalInfo
{
get
;
private
set
;
}
public
string
SerialNumber
{
get
;
set
;
}
=
null
!;
public
string
SerialNumber
{
get
;
private
set
;
}
=
null
!;
public
string
CenterStatus
{
get
;
set
;
}
=
null
!;
public
string
CenterStatus
{
get
;
private
set
;
}
=
null
!;
public
bool
IsMarried
{
get
;
set
;
}
public
bool
IsMarried
{
get
;
private
set
;
}
#
region
Navigations
...
...
@@ -65,7 +67,7 @@ public sealed class Employee : Entity
#
region
Methods
#
region
Static
factory
public
static
Employee
Create
(
public
static
Result
<
Employee
>
Create
(
string
firstName
,
string
middleName
,
string
lastName
,
DateOnly
dateOfBirth
,
string
gender
,
string
serialNumber
,
string
centerStatus
,
bool
isMarried
=
false
,
...
...
@@ -75,64 +77,90 @@ public sealed class Employee : Entity
)
{
#
region
Create
patient
Patient
patient
;
try
{
patient
=
Patient
.
Create
(
firstName
,
middleName
,
lastName
,
dateOfBirth
,
gender
);
}
catch
{
throw
;
}
Result
<
Patient
>
patient
=
Patient
.
Create
(
firstName
,
middleName
,
lastName
,
dateOfBirth
,
gender
);
if
(
patient
.
IsFailure
)
return
Result
.
Failure
<
Employee
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Check
employee
'
s
required
details
if
(
serialNumber
is
null
||
centerStatus
is
null
)
throw
new
InvalidValuesDomainException
<
Employee
>(
);
return
Result
.
Failure
<
Employee
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Create
additional
info
EmployeeAdditionalInfo
?
additionalInfo
;
try
{
additionalInfo
=
EmployeeAdditionalInfo
.
Create
(
startDate
,
academicQualification
,
workPhone
,
location
,
specialization
,
jobStatus
,
imageUrl
);
}
catch
{
throw
;
}
EmployeeAdditionalInfo
?
additionalInfo
=
EmployeeAdditionalInfo
.
Create
(
startDate
,
academicQualification
,
workPhone
,
location
,
specialization
,
jobStatus
,
imageUrl
);
#
endregion
return
new
Employee
(
0
,
patient
,
serialNumber
,
centerStatus
,
isMarried
,
additionalInfo
);
return
new
Employee
(
0
,
patient
.
Value
,
serialNumber
,
centerStatus
,
isMarried
,
additionalInfo
);
}
#
endregion
#
region
Add
family
member
public
void
AddFamilyMember
(
FamilyMember
familyMember
,
string
role
)
public
Result
AddFamilyMember
(
FamilyMember
familyMember
,
string
role
)
{
EmployeeFamilyMember
employeeFamilyMember
;
try
{
employeeFamilyMember
=
EmployeeFamilyMember
.
Create
(
Id
,
familyMember
.
Id
,
role
);
}
catch
{
throw
;
}
#
region
Create
family
member
to
attach
Result
<
EmployeeFamilyMember
>
employeeFamilyMember
=
EmployeeFamilyMember
.
Create
(
Id
,
familyMember
.
Id
,
role
);
if
(
employeeFamilyMember
.
IsFailure
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Check
valid
relation
_familyMembers
.
Add
(
employeeFamilyMember
);
if
(
role
==
FamilyRoles
.
Husband
.
Name
&&
Patient
.
Gender
==
Genders
.
Male
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidHusbandRole
);
if
(
role
==
FamilyRoles
.
Wife
.
Name
&&
Patient
.
Gender
==
Genders
.
Female
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidWifeRole
);
#
endregion
#
region
Check
duplicate
if
(
FamilyMembers
.
Where
(
fm
=>
fm
.
FamilyMember
==
familyMember
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
RelationAlreadyExist
);
#
endregion
_familyMembers
.
Add
(
employeeFamilyMember
.
Value
);
IsMarried
=
true
;
return
Result
.
Success
();
}
#
endregion
#
region
Add
related
employee
public
void
AddRelatedEmployee
(
Employee
employee
)
public
Result
AddRelatedEmployee
(
Employee
employee
)
{
#
region
Check
valid
relation
if
(
Patient
.
Gender
==
Genders
.
Male
&&
employee
.
Patient
.
Gender
==
Genders
.
Male
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidHusbandRole
);
if
(
Patient
.
Gender
==
Genders
.
Female
&&
employee
.
Patient
.
Gender
==
Genders
.
Female
)
{
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidWifeRole
);
}
#
endregion
#
region
Check
duplicate
if
(
RelatedEmployees
.
Where
(
re
=>
re
==
employee
).
ToList
().
Count
>
0
||
RelatedTo
.
Where
(
rt
=>
rt
==
employee
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
RelationAlreadyExist
);
#
endregion
_relatedEmployees
.
Add
(
employee
);
IsMarried
=
true
;
return
Result
.
Success
();
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/People/Employees/Relations/EmployeeFamilyMembers/EmployeeFamilyMember.cs
View file @
ec58ab00
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers
;
...
...
@@ -18,26 +18,26 @@ public sealed class EmployeeFamilyMember : Entity
Role
=
role
;
}
#
endregion
#
region
Properties
#
region
Employee
public
int
EmployeeId
{
get
;
set
;
}
public
Employee
Employee
{
get
;
set
;
}
=
null
!;
public
int
EmployeeId
{
get
;
private
set
;
}
public
Employee
Employee
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Family
member
public
int
FamilyMemberId
{
get
;
set
;
}
public
FamilyMember
FamilyMember
{
get
;
set
;
}
=
null
!;
public
int
FamilyMemberId
{
get
;
private
set
;
}
public
FamilyMember
FamilyMember
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Additional
public
FamilyRole
Role
{
get
;
set
;
}
=
null
!;
public
FamilyRole
Role
{
get
;
private
set
;
}
=
null
!;
#
endregion
...
...
@@ -46,13 +46,13 @@ public sealed class EmployeeFamilyMember : Entity
#
region
Methods
#
region
Static
factory
public
static
EmployeeFamilyMember
Create
(
int
employeeId
,
int
familyMemberId
,
string
role
)
public
static
Result
<
EmployeeFamilyMember
>
Create
(
int
employeeId
,
int
familyMemberId
,
string
role
)
{
if
(
employeeId
<=
0
||
familyMemberId
<=
0
||
role
is
null
)
throw
new
InvalidValuesDomainException
<
EmployeeFamilyMember
>(
);
return
Result
.
Failure
<
EmployeeFamilyMember
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
region
Check
role
FamilyRole
?
selectedRole
;
Result
<
FamilyRole
>
selectedRole
=
new
(
null
,
false
,
Errors
.
DomainErrors
.
InvalidValuesError
)
;
FamilyRole
husband
=
FamilyRoles
.
Husband
;
FamilyRole
wife
=
FamilyRoles
.
Wife
;
...
...
@@ -60,21 +60,20 @@ public sealed class EmployeeFamilyMember : Entity
FamilyRole
daughter
=
FamilyRoles
.
Daughter
;
if
(
role
==
husband
.
Name
)
selectedRole
=
husband
;
selectedRole
=
Result
.
Success
<
FamilyRole
>(
husband
)
;
else
if
(
role
==
wife
.
Name
)
selectedRole
=
wife
;
selectedRole
=
Result
.
Success
<
FamilyRole
>(
wife
)
;
else
if
(
role
==
son
.
Name
)
selectedRole
=
son
;
selectedRole
=
Result
.
Success
<
FamilyRole
>(
son
)
;
else
if
(
role
==
daughter
.
Name
)
selectedRole
=
daughter
;
else
selectedRole
=
null
;
selectedRole
=
Result
.
Success
<
FamilyRole
>(
daughter
);
if
(
selectedRole
is
null
)
throw
new
InvalidValuesDomainException
<
FamilyRole
>(
);
if
(
selectedRole
.
IsFailure
)
return
Result
.
Failure
<
EmployeeFamilyMember
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
return
new
EmployeeFamilyMember
(
0
,
employeeId
,
familyMemberId
,
selectedRole
);
return
new
EmployeeFamilyMember
(
0
,
employeeId
,
familyMemberId
,
selectedRole
.
Value
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/People/Employees/Relations/EmployeeFamilyMembers/FamilyRoleValues/FamilyRole.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
...
...
@@ -19,21 +19,21 @@ public sealed class FamilyRole : Entity
#
region
Properties
public
string
Name
{
get
;
set
;
}
=
null
!;
public
string
Name
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Methods
#
region
Static
factory
public
static
FamilyRole
Create
(
string
name
,
int
?
id
)
public
static
Result
<
FamilyRole
>
Create
(
string
name
,
int
?
id
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
FamilyRole
>(
);
return
Result
.
Failure
<
FamilyRole
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
if
(
id
is
not
null
)
{
if
(
id
<
0
)
throw
new
InvalidValuesDomainException
<
FamilyRole
>(
);
return
Result
.
Failure
<
FamilyRole
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
FamilyRole
(
id
.
Value
,
name
);
}
...
...
Clinics.Backend/Domain/Entities/People/Employees/Relations/EmployeeFamilyMembers/FamilyRoleValues/FamilyRoles.cs
View file @
ec58ab00
namespace
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
using
Domain.Exceptions.InvalidValue
;
namespace
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
public
static
class
FamilyRoles
{
#
region
Constant
id
values
public
static
FamilyRole
Husband
=>
FamilyRole
.
Create
(
"زوج"
,
1
);
public
static
FamilyRole
Husband
{
get
{
var
result
=
FamilyRole
.
Create
(
"زوج"
,
1
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
FamilyRole
>();
return
result
.
Value
;
}
}
public
static
FamilyRole
Wife
=>
FamilyRole
.
Create
(
"زوجة"
,
2
);
public
static
FamilyRole
Wife
{
get
{
var
result
=
FamilyRole
.
Create
(
"زوجة"
,
2
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
FamilyRole
>();
return
result
.
Value
;
}
}
public
static
FamilyRole
Son
=>
FamilyRole
.
Create
(
"ابن"
,
3
);
public
static
FamilyRole
Son
{
get
{
var
result
=
FamilyRole
.
Create
(
"ابن"
,
3
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
FamilyRole
>();
return
result
.
Value
;
}
}
public
static
FamilyRole
Daughter
=>
FamilyRole
.
Create
(
"ابنة"
,
4
);
public
static
FamilyRole
Daughter
{
get
{
var
result
=
FamilyRole
.
Create
(
"ابنة"
,
4
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
FamilyRole
>();
return
result
.
Value
;
}
}
#
endregion
}
Clinics.Backend/Domain/Entities/People/FamilyMembers/FamilyMember.cs
View file @
ec58ab00
using
Domain.Entities.People.Patients
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.FamilyMembers
;
...
...
@@ -18,32 +19,25 @@ public sealed class FamilyMember : Entity
#
region
Properties
public
Patient
Patient
{
get
;
set
;
}
=
null
!;
public
Patient
Patient
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Methods
#
region
Static
factory
public
static
FamilyMember
Create
(
string
firstName
,
string
middleName
,
string
lastName
,
public
static
Result
<
FamilyMember
>
Create
(
string
firstName
,
string
middleName
,
string
lastName
,
DateOnly
dateOfBirth
,
string
gender
)
{
#
region
Create
patient
Patient
patient
;
try
{
patient
=
Patient
.
Create
(
firstName
,
middleName
,
lastName
,
dateOfBirth
,
gender
);
}
catch
{
throw
;
}
Result
<
Patient
>
patient
=
Patient
.
Create
(
firstName
,
middleName
,
lastName
,
dateOfBirth
,
gender
);
if
(
patient
.
IsFailure
)
return
Result
.
Failure
<
FamilyMember
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
return
new
FamilyMember
(
0
,
patient
);
return
new
FamilyMember
(
0
,
patient
.
Value
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/People/Patients/Patient.cs
View file @
ec58ab00
...
...
@@ -5,8 +5,8 @@ using Domain.Entities.People.Patients.Relations.PatientMedicines;
using
Domain.Entities.People.Shared
;
using
Domain.Entities.People.Shared.GenderValues
;
using
Domain.Entities.Visits
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.Patients
;
...
...
@@ -75,80 +75,72 @@ public sealed class Patient : Entity
#
region
Methods
#
region
Static
factory
public
static
Patient
Create
(
string
firstName
,
string
middleName
,
string
lastName
,
public
static
Result
<
Patient
>
Create
(
string
firstName
,
string
middleName
,
string
lastName
,
DateOnly
dateOfBirth
,
string
gender
)
{
#
region
Personal
info
PersonalInfo
?
personalInfo
;
try
{
personalInfo
=
PersonalInfo
.
Create
(
firstName
,
middleName
,
lastName
);
}
catch
{
throw
;
}
Result
<
PersonalInfo
>
personalInfo
=
PersonalInfo
.
Create
(
firstName
,
middleName
,
lastName
);
if
(
personalInfo
.
IsFailure
)
return
Result
.
Failure
<
Patient
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Gender
if
(
gender
is
null
)
throw
new
InvalidValuesDomainException
<
Gender
>();
Gender
?
selectedGender
;
Result
<
Gender
>
selectedGender
=
new
(
null
,
false
,
Errors
.
DomainErrors
.
InvalidValuesError
);
Gender
male
=
Genders
.
Male
;
Gender
female
=
Genders
.
Female
;
if
(
gender
==
male
.
Name
)
selectedGender
=
male
;
selectedGender
=
Result
.
Success
<
Gender
>(
male
)
;
else
if
(
gender
==
female
.
Name
)
selectedGender
=
female
;
else
selectedGender
=
null
;
selectedGender
=
Result
.
Success
<
Gender
>(
female
);
if
(
selectedGender
is
null
)
throw
new
InvalidValuesDomainException
<
Gender
>(
);
if
(
selectedGender
.
IsFailure
)
return
Result
.
Failure
<
Patient
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
return
new
Patient
(
0
,
personalInfo
,
dateOfBirth
,
selectedGender
);
return
new
Patient
(
0
,
personalInfo
.
Value
,
dateOfBirth
,
selectedGender
.
Value
);
}
#
endregion
#
region
Add
medicine
public
void
AddMedicine
(
Medicine
medicine
,
int
number
)
public
Result
AddMedicine
(
Medicine
medicine
,
int
number
)
{
PatientMedicine
entry
;
#
region
Create
medicine
to
attach
Result
<
PatientMedicine
>
entry
=
PatientMedicine
.
Create
(
Id
,
medicine
.
Id
,
number
);
if
(
entry
.
IsFailure
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
try
{
entry
=
PatientMedicine
.
Create
(
Id
,
medicine
.
Id
,
number
);
}
catch
{
throw
;
}
#
region
Check
duplication
if
(
Medicines
.
Where
(
m
=>
m
.
MedicineId
==
medicine
.
Id
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
PatientAlreadyHasThisMedicine
);
#
endregion
_medicines
.
Add
(
entry
);
_medicines
.
Add
(
entry
.
Value
);
return
Result
.
Success
();
}
#
endregion
#
region
Add
disease
public
void
AddDisease
(
Disease
disease
)
public
Result
AddDisease
(
Disease
disease
)
{
PatientDisease
entry
;
try
{
entry
=
PatientDisease
.
Create
(
Id
,
disease
.
Id
);
}
catch
{
throw
;
}
#
region
Create
disease
to
attach
Result
<
PatientDisease
>
entry
=
PatientDisease
.
Create
(
Id
,
disease
.
Id
);
if
(
entry
.
IsFailure
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Check
duplication
if
(
Diseases
.
Where
(
d
=>
d
.
DiseaseId
==
disease
.
Id
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
PatientAlreadyHasThisDisease
);
#
endregion
_diseases
.
Add
(
entry
);
_diseases
.
Add
(
entry
.
Value
);
return
Result
.
Success
();
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/People/Patients/Relations/PatientDiseases/PatientDisease.cs
View file @
ec58ab00
using
Domain.Entities.Medicals.Diseases
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.Patients.Relations.PatientDiseases
;
...
...
@@ -22,15 +22,15 @@ public sealed class PatientDisease : Entity
#
region
Patient
public
int
PatientId
{
get
;
set
;
}
public
Patient
Patient
{
get
;
set
;
}
=
null
!;
public
int
PatientId
{
get
;
private
set
;
}
public
Patient
Patient
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Disease
public
int
DiseaseId
{
get
;
set
;
}
public
Disease
Disease
{
get
;
set
;
}
=
null
!;
public
int
DiseaseId
{
get
;
private
set
;
}
public
Disease
Disease
{
get
;
private
set
;
}
=
null
!;
#
endregion
...
...
@@ -43,10 +43,10 @@ public sealed class PatientDisease : Entity
#
region
Methods
#
region
Static
factory
public
static
PatientDisease
Create
(
int
patientId
,
int
diseaseId
)
public
static
Result
<
PatientDisease
>
Create
(
int
patientId
,
int
diseaseId
)
{
if
(
patientId
<=
0
||
diseaseId
<=
0
)
throw
new
InvalidValuesDomainException
<
PatientDisease
>(
);
return
Result
.
Failure
<
PatientDisease
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
PatientDisease
(
0
,
patientId
,
diseaseId
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/People/Patients/Relations/PatientMedicines/PatientMedicine.cs
View file @
ec58ab00
using
Domain.Entities.Medicals.Medicines
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.People.Patients.Relations.PatientMedicines
;
...
...
@@ -25,21 +25,21 @@ public sealed class PatientMedicine : Entity
#
region
Patient
public
int
PatientId
{
get
;
set
;
}
public
Patient
Patient
{
get
;
set
;
}
=
null
!;
public
int
PatientId
{
get
;
private
set
;
}
public
Patient
Patient
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Medicine
public
int
MedicineId
{
get
;
set
;
}
public
Medicine
Medicine
{
get
;
set
;
}
=
null
!;
public
int
MedicineId
{
get
;
private
set
;
}
public
Medicine
Medicine
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Additional
public
int
Number
{
get
;
set
;
}
public
int
Number
{
get
;
private
set
;
}
#
endregion
...
...
@@ -49,10 +49,10 @@ public sealed class PatientMedicine : Entity
#
region
Methods
#
region
Static
factory
public
static
PatientMedicine
Create
(
int
patientId
,
int
medicineId
,
int
number
)
public
static
Result
<
PatientMedicine
>
Create
(
int
patientId
,
int
medicineId
,
int
number
)
{
if
(
patientId
<=
0
||
medicineId
<=
0
||
number
<=
0
)
throw
new
InvalidValuesDomainException
<
PatientMedicine
>(
);
return
Result
.
Failure
<
PatientMedicine
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
PatientMedicine
(
0
,
patientId
,
medicineId
,
number
);
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/People/Shared/GenderValues/Gender.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.People.Shared.GenderValues
;
...
...
@@ -26,15 +26,15 @@ public sealed class Gender : Entity
#
region
Methods
#
region
Static
factory
public
static
Gender
Create
(
string
name
,
int
?
id
)
public
static
Result
<
Gender
>
Create
(
string
name
,
int
?
id
)
{
if
(
name
is
null
)
throw
new
InvalidValuesDomainException
<
Gender
>(
);
return
Result
.
Failure
<
Gender
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
if
(
id
is
not
null
)
{
if
(
id
<
0
)
throw
new
InvalidValuesDomainException
<
Gender
>(
);
return
Result
.
Failure
<
Gender
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
Gender
(
id
.
Value
,
name
);
}
...
...
Clinics.Backend/Domain/Entities/People/Shared/GenderValues/Genders.cs
View file @
ec58ab00
namespace
Domain.Entities.People.Shared.GenderValues
;
using
Domain.Exceptions.InvalidValue
;
namespace
Domain.Entities.People.Shared.GenderValues
;
public
static
class
Genders
{
#
region
Constant
id
values
#
region
Constant
values
public
static
Gender
Male
=>
Gender
.
Create
(
"ذكر"
,
1
);
public
static
Gender
Male
{
get
{
var
result
=
Gender
.
Create
(
"ذكر"
,
1
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
Gender
>();
return
result
.
Value
;
}
}
public
static
Gender
Female
=>
Gender
.
Create
(
"أنثى"
,
2
);
public
static
Gender
Female
{
get
{
var
result
=
Gender
.
Create
(
"أنثى"
,
2
);
if
(
result
.
IsFailure
)
throw
new
InvalidValuesDomainException
<
Gender
>();
return
result
.
Value
;
}
}
#
endregion
}
Clinics.Backend/Domain/Entities/People/Shared/PersonalInfo.cs
View file @
ec58ab00
using
Domain.
Exceptions.InvalidValue
;
using
Domain.
Primitives
;
using
Domain.
Primitives
;
using
Domain.
Shared
;
namespace
Domain.Entities.People.Shared
;
...
...
@@ -41,10 +41,10 @@ public sealed class PersonalInfo : Entity
#
region
Methods
#
region
Static
factory
public
static
PersonalInfo
Create
(
string
firstName
,
string
middleName
,
string
lastName
)
public
static
Result
<
PersonalInfo
>
Create
(
string
firstName
,
string
middleName
,
string
lastName
)
{
if
(
firstName
is
null
||
middleName
is
null
||
lastName
is
null
)
throw
new
InvalidValuesDomainException
<
PersonalInfo
>(
);
return
Result
.
Failure
<
PersonalInfo
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
PersonalInfo
(
0
,
firstName
,
middleName
,
lastName
);
}
...
...
Clinics.Backend/Domain/Entities/Visits/Relations/VisitMedicalImages/VisitMedicalImage.cs
View file @
ec58ab00
using
Domain.Entities.Medicals.MedicalImages
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.Visits.Relations.VisitMedicalImages
;
...
...
@@ -25,21 +25,21 @@ public sealed class VisitMedicalImage : Entity
#
region
Visit
public
int
VisitId
{
get
;
set
;
}
public
Visit
Visit
{
get
;
set
;
}
=
null
!;
public
int
VisitId
{
get
;
private
set
;
}
public
Visit
Visit
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Medical
image
public
int
MedicalImageId
{
get
;
set
;
}
public
MedicalImage
MedicalImage
{
get
;
set
;
}
=
null
!;
public
int
MedicalImageId
{
get
;
private
set
;
}
public
MedicalImage
MedicalImage
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Additional
public
string
?
Result
{
get
;
set
;
}
public
string
?
Result
{
get
;
private
set
;
}
#
endregion
...
...
@@ -48,22 +48,23 @@ public sealed class VisitMedicalImage : Entity
#
region
Methods
#
region
Static
factory
public
static
VisitMedicalImage
Create
(
int
visitId
,
int
medicalImageId
)
public
static
Result
<
VisitMedicalImage
>
Create
(
int
visitId
,
int
medicalImageId
)
{
if
(
visitId
<=
0
||
medicalImageId
<=
0
)
throw
new
InvalidValuesDomainException
<
VisitMedicalImage
>(
);
return
Shared
.
Result
.
Failure
<
VisitMedicalImage
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
VisitMedicalImage
(
0
,
visitId
,
medicalImageId
);
}
#
endregion
#
region
Add
result
public
void
AddResult
(
string
result
)
public
Result
AddResult
(
string
result
)
{
if
(
result
is
null
)
throw
new
InvalidValuesDomainException
<
VisitMedicalImage
>(
);
return
Shared
.
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
Result
=
result
;
return
Shared
.
Result
.
Success
();
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/Visits/Relations/VisitMedicalTests/VisitMedicalTest.cs
View file @
ec58ab00
using
Domain.Entities.Medicals.MedicalTests
;
using
Domain.Entities.Visits.Relations.VisitMedicalImages
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.Visits.Relations.VisitMedicalTests
;
...
...
@@ -26,21 +25,21 @@ public sealed class VisitMedicalTest : Entity
#
region
Visit
public
int
VisitId
{
get
;
set
;
}
public
Visit
Visit
{
get
;
set
;
}
=
null
!;
public
int
VisitId
{
get
;
private
set
;
}
public
Visit
Visit
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Medical
test
public
int
MedicalTestId
{
get
;
set
;
}
public
MedicalTest
MedicalTest
{
get
;
set
;
}
=
null
!;
public
int
MedicalTestId
{
get
;
private
set
;
}
public
MedicalTest
MedicalTest
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Additional
public
string
?
Result
{
get
;
set
;
}
public
string
?
Result
{
get
;
private
set
;
}
#
endregion
...
...
@@ -49,22 +48,23 @@ public sealed class VisitMedicalTest : Entity
#
region
Methods
#
region
Static
factory
public
static
VisitMedicalTest
Create
(
int
visitId
,
int
medicalTestId
)
public
static
Result
<
VisitMedicalTest
>
Create
(
int
visitId
,
int
medicalTestId
)
{
if
(
visitId
<=
0
||
medicalTestId
<=
0
)
throw
new
InvalidValuesDomainException
<
VisitMedicalTest
>(
);
return
Shared
.
Result
.
Failure
<
VisitMedicalTest
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
VisitMedicalTest
(
0
,
visitId
,
medicalTestId
);
}
#
endregion
#
region
Add
result
public
void
AddResult
(
string
result
)
public
Result
AddResult
(
string
result
)
{
if
(
result
is
null
)
throw
new
InvalidValuesDomainException
<
VisitMedicalTest
>(
);
return
Shared
.
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
Result
=
result
;
return
Shared
.
Result
.
Success
();
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/Visits/Relations/VisitMedicines/VisitMedicine.cs
View file @
ec58ab00
using
Domain.Entities.Medicals.Medicines
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.Visits.Relations.VisitMedicines
;
...
...
@@ -23,21 +23,21 @@ public sealed class VisitMedicine : Entity
#
region
Visit
public
int
VisitId
{
get
;
set
;
}
public
Visit
Visit
{
get
;
set
;
}
=
null
!;
public
int
VisitId
{
get
;
private
set
;
}
public
Visit
Visit
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Medicine
public
int
MedicineId
{
get
;
set
;
}
public
Medicine
Medicine
{
get
;
set
;
}
=
null
!;
public
int
MedicineId
{
get
;
private
set
;
}
public
Medicine
Medicine
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Additional
public
int
Number
{
get
;
set
;
}
public
int
Number
{
get
;
private
set
;
}
#
endregion
...
...
@@ -46,10 +46,10 @@ public sealed class VisitMedicine : Entity
#
region
Methods
#
region
Static
factory
public
static
VisitMedicine
Create
(
int
visitId
,
int
medicineId
,
int
number
)
public
static
Result
<
VisitMedicine
>
Create
(
int
visitId
,
int
medicineId
,
int
number
)
{
if
(
visitId
<=
0
||
medicineId
<=
0
||
number
<=
0
)
throw
new
InvalidValuesDomainException
<
VisitMedicine
>(
);
return
Result
.
Failure
<
VisitMedicine
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
VisitMedicine
(
0
,
visitId
,
medicineId
,
number
);
}
...
...
Clinics.Backend/Domain/Entities/Visits/Visit.cs
View file @
ec58ab00
...
...
@@ -7,8 +7,8 @@ using Domain.Entities.People.Patients;
using
Domain.Entities.Visits.Relations.VisitMedicalImages
;
using
Domain.Entities.Visits.Relations.VisitMedicalTests
;
using
Domain.Entities.Visits.Relations.VisitMedicines
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.Visits
;
...
...
@@ -34,23 +34,23 @@ public sealed class Visit : Entity
#
region
Patient
public
int
PatientId
{
get
;
set
;
}
public
Patient
Patient
{
get
;
set
;
}
=
null
!;
public
int
PatientId
{
get
;
private
set
;
}
public
Patient
Patient
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Doctor
public
int
DoctorId
{
get
;
set
;
}
public
Doctor
Doctor
{
get
;
set
;
}
=
null
!;
public
int
DoctorId
{
get
;
private
set
;
}
public
Doctor
Doctor
{
get
;
private
set
;
}
=
null
!;
#
endregion
#
region
Additional
public
DateOnly
Date
{
get
;
set
;
}
public
DateOnly
Date
{
get
;
private
set
;
}
public
string
Diagnosis
{
get
;
set
;
}
=
null
!;
public
string
Diagnosis
{
get
;
private
set
;
}
=
null
!;
#
region
Hospital
...
...
@@ -88,73 +88,81 @@ public sealed class Visit : Entity
#
region
Methods
#
region
Static
factory
public
static
Visit
Create
(
int
patientId
,
int
doctorId
,
DateOnly
date
,
string
diagnosis
)
public
static
Result
<
Visit
>
Create
(
int
patientId
,
int
doctorId
,
DateOnly
date
,
string
diagnosis
)
{
if
(
patientId
<=
0
||
doctorId
<=
0
||
diagnosis
is
null
)
throw
new
InvalidValuesDomainException
<
Visit
>(
);
return
Result
.
Failure
<
Visit
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
Visit
(
0
,
patientId
,
doctorId
,
date
,
diagnosis
);
}
#
endregion
#
region
Add
medical
image
public
void
AddMedicalImage
(
MedicalImage
medicalImage
)
public
Result
AddMedicalImage
(
MedicalImage
medicalImage
)
{
VisitMedicalImage
entry
;
try
{
entry
=
VisitMedicalImage
.
Create
(
Id
,
medicalImage
.
Id
);
}
catch
{
throw
;
}
_medicalImages
.
Add
(
entry
);
#
region
Create
medical
image
to
attach
Result
<
VisitMedicalImage
>
entry
=
VisitMedicalImage
.
Create
(
Id
,
medicalImage
.
Id
);
if
(
entry
.
IsFailure
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Check
duplicate
if
(
MedicalImages
.
Where
(
mi
=>
mi
.
MedicalImage
==
medicalImage
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
VisitAlreadyHasThisMedicalImage
);
#
endregion
_medicalImages
.
Add
(
entry
.
Value
);
return
Result
.
Success
();
}
#
endregion
#
region
Add
medical
test
public
void
AddMedicalTest
(
MedicalTest
medicalTest
)
public
Result
AddMedicalTest
(
MedicalTest
medicalTest
)
{
VisitMedicalTest
entry
;
try
{
entry
=
VisitMedicalTest
.
Create
(
Id
,
medicalTest
.
Id
);
}
catch
{
throw
;
}
_medicalTests
.
Add
(
entry
);
#
region
Create
medical
test
to
attach
Result
<
VisitMedicalTest
>
entry
=
VisitMedicalTest
.
Create
(
Id
,
medicalTest
.
Id
);
if
(
entry
.
IsFailure
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Check
duplicate
if
(
MedicalTests
.
Where
(
mt
=>
mt
.
MedicalTest
==
medicalTest
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
VisitAlreadyHasThisMedicalTest
);
#
endregion
_medicalTests
.
Add
(
entry
.
Value
);
return
Result
.
Success
();
}
#
endregion
#
region
Add
medicine
public
void
AddMedicine
(
Medicine
medicine
,
int
number
)
public
Result
AddMedicine
(
Medicine
medicine
,
int
number
)
{
VisitMedicine
entry
;
try
{
entry
=
VisitMedicine
.
Create
(
Id
,
medicine
.
Id
,
number
);
}
catch
{
throw
;
}
_medicines
.
Add
(
entry
);
#
region
Create
medicine
to
attach
Result
<
VisitMedicine
>
entry
=
VisitMedicine
.
Create
(
Id
,
medicine
.
Id
,
number
);
if
(
entry
.
IsFailure
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
endregion
#
region
Check
duplicate
if
(
Medicines
.
Where
(
m
=>
m
.
Medicine
==
medicine
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
VisitAlreadyHasThisMedicine
);
#
endregion
_medicines
.
Add
(
entry
.
Value
);
return
Result
.
Success
();
}
#
endregion
#
region
Add
hospital
public
void
AddHospital
(
Hospital
hospital
)
public
Result
AddHospital
(
Hospital
hospital
)
{
if
(
hospital
is
null
)
throw
new
InvalidValuesDomainException
<
Visit
>();
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
Hospital
=
hospital
;
HospitalId
=
hospital
.
Id
;
return
Result
.
Success
();
}
#
endregion
...
...
Clinics.Backend/Domain/Entities/WaitingList/WaitingListRecord.cs
View file @
ec58ab00
using
Domain.Entities.People.Doctors
;
using
Domain.Entities.People.Patients
;
using
Domain.Exceptions.InvalidValue
;
using
Domain.Primitives
;
using
Domain.Shared
;
namespace
Domain.Entities.WaitingList
;
...
...
@@ -46,21 +46,23 @@ public sealed class WaitingListRecord : Entity
#
region
Static
factory
public
static
WaitingListRecord
Create
(
int
patientId
)
public
static
Result
<
WaitingListRecord
>
Create
(
int
patientId
)
{
if
(
patientId
<=
0
)
throw
new
InvalidValuesDomainException
<
WaitingListRecord
>(
);
return
Result
.
Failure
<
WaitingListRecord
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
new
WaitingListRecord
(
0
,
patientId
);
}
#
endregion
#
region
Link
to
doctor
public
void
LinkToDoctor
(
int
doctorId
)
public
Result
LinkToDoctor
(
int
doctorId
)
{
if
(
doctorId
<=
0
)
throw
new
InvalidValuesDomainException
<
WaitingListRecord
>();
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidValuesError
);
DoctorId
=
doctorId
;
return
Result
.
Success
();
}
#
endregion
...
...
Clinics.Backend/Domain/Errors/DomainErrors.cs
0 → 100644
View file @
ec58ab00
using
Domain.Shared
;
namespace
Domain.Errors
;
public
static
class
DomainErrors
{
public
static
Error
InvalidValuesError
=>
new
(
"Domain.InvalidValues"
,
"القيم المدخلة غير صالحة"
);
public
static
Error
PatientAlreadyHasThisMedicine
=>
new
(
"Domain.PatientAlreadyHasThisMedicine"
,
"المريض لديه بالفعل الدواء الذي تحاول اضافته"
);
public
static
Error
PatientAlreadyHasThisDisease
=>
new
(
"Domain.PatientAlreadyHasThisDisease"
,
"المريض لديه بالفعل المرض الذي تحاول اضافته"
);
public
static
Error
InvalidHusbandRole
=>
new
(
"Domain.InvalidHusbandRole"
,
"لا يمكن للموظف أن يكون له زوج"
);
public
static
Error
InvalidWifeRole
=>
new
(
"Domain.InvalidWifeRole"
,
"لا يمكن للموظفة أن يكون لها زوجة"
);
public
static
Error
RelationAlreadyExist
=>
new
(
"Domain.RelationAlreadyExist"
,
"العلاقة موجودة بالفعل"
);
public
static
Error
PhoneAlreadyExist
=>
new
(
"Domain.PhoneAlreadyExist"
,
"رقم الهاتف موجود بالفعل"
);
public
static
Error
VisitAlreadyHasThisMedicine
=>
new
(
"Domain.VisitAlreadyHasThisMedicine"
,
"تحتوي الوصفة الطبية بالفعل على الدواء الذي تحاول اضافته"
);
public
static
Error
VisitAlreadyHasThisMedicalTest
=>
new
(
"Domain.VisitAlreadyHasThisMedicalTest"
,
"تحتوي هذه الزيارة بالفعل على التحليل الطبي الذي تحاول اضافته"
);
public
static
Error
VisitAlreadyHasThisMedicalImage
=>
new
(
"Domain.PatientAlreadyHasThisMedicine"
,
"تحتوي هذه الزيارة بالفعل على الصورة التي تحاول اضافتها"
);
}
Clinics.Backend/Domain/Errors/PersistenceErrors.cs
0 → 100644
View file @
ec58ab00
using
Domain.Shared
;
namespace
Domain.Errors
;
public
static
class
PersistenceErrors
{
public
static
Error
UnableToCompleteTransaction
=>
new
(
"Persistence.UnableToCompleteTransaction"
,
"حدثت مشكلة عند الاتصال مع قاعدة البيانات"
);
}
Clinics.Backend/Domain/Shared/Error.cs
0 → 100644
View file @
ec58ab00
namespace
Domain.Shared
;
public
class
Error
:
IEquatable
<
Error
>
{
#
region
Ctor
public
Error
(
string
code
,
string
message
)
{
Code
=
code
;
Message
=
message
;
}
#
endregion
#
region
Properties
public
string
Code
{
get
;
}
public
string
Message
{
get
;
}
#
endregion
#
region
Methods
#
region
Equality
by
value
public
static
bool
operator
==(
Error
?
a
,
Error
?
b
)
{
if
(
a
is
null
&&
b
is
null
)
{
return
true
;
}
if
(
a
is
null
||
b
is
null
)
{
return
false
;
}
return
a
.
Equals
(
b
);
}
public
static
bool
operator
!=(
Error
?
a
,
Error
?
b
)
=>
!(
a
==
b
);
public
virtual
bool
Equals
(
Error
?
other
)
{
if
(
other
is
null
)
{
return
false
;
}
return
Code
==
other
.
Code
&&
Message
==
other
.
Message
;
}
public
override
bool
Equals
(
object
?
obj
)
=>
obj
is
Error
error
&&
Equals
(
error
);
#
endregion
#
region
Hash
code
public
override
int
GetHashCode
()
=>
HashCode
.
Combine
(
Code
,
Message
);
#
endregion
public
static
implicit
operator
string
(
Error
error
)
=>
error
.
Code
;
public
override
string
ToString
()
=>
Code
;
#
endregion
#
region
Statics
public
static
readonly
Error
None
=
new
(
string
.
Empty
,
string
.
Empty
);
public
static
readonly
Error
NullValue
=
new
(
"Error.NullValue"
,
"The specified result value is null."
);
#
endregion
}
Clinics.Backend/Domain/Shared/Result.cs
0 → 100644
View file @
ec58ab00
namespace
Domain.Shared
;
public
class
Result
{
#
region
Ctor
public
Result
(
bool
isSuccess
,
Error
error
)
{
IsSuccess
=
isSuccess
;
Error
=
error
;
}
#
endregion
#
region
Properties
public
bool
IsSuccess
{
get
;
}
public
bool
IsFailure
=>
!
IsSuccess
;
public
Error
Error
{
get
;
}
#
endregion
#
region
Methods
#
region
Static
factory
public
static
Result
Create
(
bool
isSuccess
,
Error
error
)
{
if
(
isSuccess
&&
error
!=
Error
.
None
)
{
throw
new
InvalidOperationException
();
}
if
(!
isSuccess
&&
error
==
Error
.
None
)
{
throw
new
InvalidOperationException
();
}
return
new
Result
(
isSuccess
,
error
);
}
#
endregion
#
endregion
#
region
Statics
public
static
Result
Success
()
=>
new
(
true
,
Error
.
None
);
public
static
Result
<
TValue
>
Success
<
TValue
>(
TValue
value
)
=>
new
(
value
,
true
,
Error
.
None
);
public
static
Result
Failure
(
Error
error
)
=>
new
(
false
,
error
);
public
static
Result
<
TValue
>
Failure
<
TValue
>(
Error
error
)
=>
new
(
default
,
false
,
error
);
public
static
Result
<
TValue
>
Create
<
TValue
>(
TValue
?
value
)
=>
value
is
not
null
?
Success
(
value
)
:
Failure
<
TValue
>(
Error
.
NullValue
);
#
endregion
}
Clinics.Backend/Domain/Shared/ResultT.cs
0 → 100644
View file @
ec58ab00
namespace
Domain.Shared
;
public
class
Result
<
TValue
>
:
Result
{
#
region
Ctor
public
Result
(
TValue
?
value
,
bool
isSuccess
,
Error
error
)
:
base
(
isSuccess
,
error
)
{
_value
=
value
;
}
#
endregion
#
region
Properties
private
readonly
TValue
?
_value
;
public
TValue
Value
=>
IsSuccess
?
_value
!
:
throw
new
InvalidOperationException
(
"The value of a failure result can not be accessed."
);
#
endregion
#
region
Methods
#
region
Static
factory
public
static
Result
<
TValue
>
Create
(
TValue
?
value
,
bool
isSuccess
,
Error
error
)
{
try
{
Result
.
Create
(
isSuccess
,
error
);
}
catch
(
Exception
)
{
throw
;
}
return
new
Result
<
TValue
>(
value
,
isSuccess
,
error
);
}
#
endregion
#
endregion
// To allow returning a result without required castring
public
static
implicit
operator
Result
<
TValue
>(
TValue
?
value
)
=>
Create
(
value
);
}
Clinics.Backend/Persistence/UnitOfWork/UnitOfWork.cs
View file @
ec58ab00
...
...
@@ -21,7 +21,7 @@ public class UnitOfWork : IUnitOfWork
catch
(
Exception
)
{
// TODO: Log errors using ILogger
//
throw;
throw
;
}
}
}
Clinics.Backend/Presentation/Controllers/EmployeesController.cs
View file @
ec58ab00
...
...
@@ -20,7 +20,9 @@ public class EmployeesController : ControllerBase
[
HttpPost
]
public
async
Task
<
IActionResult
>
Create
(
CreateEmployeeCommand
command
)
{
await
_sender
.
Send
(
command
);
return
Ok
();
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsSuccess
)
return
Created
();
else
return
BadRequest
(
result
.
Error
.
Message
);
}
}
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