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
400a6cbb
Commit
400a6cbb
authored
Aug 19, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) update attach family member to employee feature
parent
c339ee49
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
127 additions
and
35 deletions
+127
-35
CommandHandlerBase.cs
...lication/Abstractions/CQRS/Commands/CommandHandlerBase.cs
+4
-4
AttachFamilyMemberToEmployeeCommandHandler.cs
...rToEmployee/AttachFamilyMemberToEmployeeCommandHandler.cs
+64
-7
CreateEmployeeCommandHandler.cs
...s/Commands/CreateEmployee/CreateEmployeeCommandHandler.cs
+1
-1
Employee.cs
Clinics.Backend/Domain/Entities/People/Employees/Employee.cs
+8
-17
EmployeeFamilyMember.cs
...s/Relations/EmployeeFamilyMembers/EmployeeFamilyMember.cs
+6
-6
IEmployeeFamilyMembersRepository.cs
...d/Domain/Repositories/IEmployeeFamilyMembersRepository.cs
+8
-0
EmployeeFamilyMembersRepository.cs
...rsistence/Repositories/EmployeeFamilyMembersRepository.cs
+26
-0
FamilyMembersRepository.cs
...ckend/Persistence/Repositories/FamilyMembersRepository.cs
+10
-0
No files found.
Clinics.Backend/Application/Abstractions/CQRS/Commands/CommandHandler.cs
→
Clinics.Backend/Application/Abstractions/CQRS/Commands/CommandHandler
Base
.cs
View file @
400a6cbb
...
@@ -4,12 +4,12 @@ using Domain.UnitOfWork;
...
@@ -4,12 +4,12 @@ using Domain.UnitOfWork;
namespace
Application.Abstractions.CQRS.Commands
;
namespace
Application.Abstractions.CQRS.Commands
;
public
abstract
class
CommandHandler
<
TCommand
>
:
ICommandHandler
<
TCommand
>
public
abstract
class
CommandHandler
Base
<
TCommand
>
:
ICommandHandler
<
TCommand
>
where
TCommand
:
ICommand
where
TCommand
:
ICommand
{
{
protected
readonly
IUnitOfWork
_unitOfWork
;
protected
readonly
IUnitOfWork
_unitOfWork
;
protected
CommandHandler
(
IUnitOfWork
unitOfWork
)
protected
CommandHandler
Base
(
IUnitOfWork
unitOfWork
)
{
{
_unitOfWork
=
unitOfWork
;
_unitOfWork
=
unitOfWork
;
}
}
...
@@ -36,11 +36,11 @@ public abstract class CommandHandler<TCommand> : ICommandHandler<TCommand>
...
@@ -36,11 +36,11 @@ public abstract class CommandHandler<TCommand> : ICommandHandler<TCommand>
}
}
public
abstract
class
CommandHandler
<
TCommand
,
TResponse
>
:
ICommandHandler
<
TCommand
,
TResponse
>
public
abstract
class
CommandHandler
Base
<
TCommand
,
TResponse
>
:
ICommandHandler
<
TCommand
,
TResponse
>
where
TCommand
:
ICommand
<
TResponse
>
where
TCommand
:
ICommand
<
TResponse
>
{
{
protected
readonly
IUnitOfWork
_unitOfWork
;
protected
readonly
IUnitOfWork
_unitOfWork
;
protected
CommandHandler
(
IUnitOfWork
unitOfWork
)
protected
CommandHandler
Base
(
IUnitOfWork
unitOfWork
)
{
{
_unitOfWork
=
unitOfWork
;
_unitOfWork
=
unitOfWork
;
}
}
...
...
Clinics.Backend/Application/Employees/Commands/AttachFamilyMemberToEmployee/AttachFamilyMemberToEmployeeCommandHandler.cs
View file @
400a6cbb
using
Application.Abstractions.CQRS.Commands
;
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Entities.People.Employees
;
using
Domain.Entities.People.Employees
.Relations.EmployeeFamilyMembers
;
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
using
Domain.UnitOfWork
;
namespace
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
namespace
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
public
class
AttachFamilyMemberToEmployeeCommandHandler
:
ICommandHandler
<
AttachFamilyMemberToEmployeeCommand
>
public
class
AttachFamilyMemberToEmployeeCommandHandler
:
CommandHandlerBase
<
AttachFamilyMemberToEmployeeCommand
>
{
{
#
region
CTOR
DI
#
region
CTOR
DI
private
readonly
IFamilyMembersRepository
_familyMembersRepository
;
private
readonly
IEmployeeFamilyMembersRepository
_employeeFamilyMembersRepository
;
private
readonly
IEmployeesRepository
_employeesRepository
;
private
readonly
IEmployeesRepository
_employeesRepository
;
private
readonly
IUnitOfWork
_unitOfWork
;
public
AttachFamilyMemberToEmployeeCommandHandler
(
I
EmployeesRepository
employeesRepository
,
IUnitOfWork
unitOfWork
)
public
AttachFamilyMemberToEmployeeCommandHandler
(
I
UnitOfWork
unitOfWork
,
IFamilyMembersRepository
familyMembersRepository
,
IEmployeesRepository
employeesRepository
,
IEmployeeFamilyMembersRepository
employeeFamilyMembersRepository
)
:
base
(
unitOfWork
)
{
{
_familyMembersRepository
=
familyMembersRepository
;
_employeesRepository
=
employeesRepository
;
_employeesRepository
=
employeesRepository
;
_
unitOfWork
=
unitOfWork
;
_
employeeFamilyMembersRepository
=
employeeFamilyMembersRepository
;
}
}
#
endregion
#
endregion
public
async
Task
<
Result
>
Handle
(
AttachFamilyMemberToEmployeeCommand
request
,
CancellationToken
cancellationToken
)
public
override
async
Task
<
Result
>
HandleHelper
(
AttachFamilyMemberToEmployeeCommand
request
,
CancellationToken
cancellationToken
)
{
{
#
region
1.
Create
family
member
var
createdFamilyMemberResult
=
FamilyMember
.
Create
(
request
.
FirstName
,
request
.
MiddleName
,
request
.
LastName
,
request
.
DateOfBirth
,
request
.
Gender
);
if
(
createdFamilyMemberResult
.
IsFailure
)
return
Result
.
Failure
(
createdFamilyMemberResult
.
Error
);
#
endregion
#
region
2.
Add
family
member
to
DB
var
addedFamilyMemberResult
=
await
_familyMembersRepository
.
CreateAsync
(
createdFamilyMemberResult
.
Value
);
if
(
addedFamilyMemberResult
.
IsFailure
)
return
Result
.
Failure
(
addedFamilyMemberResult
.
Error
);
#
endregion
#
region
3.
Get
employee
from
DB
var
employeeResult
=
await
_employeesRepository
.
GetEmployeeBySerialNumberAsync
(
request
.
EmployeeSerialNumber
);
if
(
employeeResult
.
IsFailure
)
return
Result
.
Failure
(
employeeResult
.
Error
);
#
endregion
#
region
4.
Create
relation
var
employee
=
employeeResult
.
Value
;
var
familyMember
=
addedFamilyMemberResult
.
Value
;
var
employeeFamilyMemberResult
=
EmployeeFamilyMember
.
Create
(
employee
,
familyMember
,
request
.
FamilyRole
);
if
(
employeeFamilyMemberResult
.
IsFailure
)
return
Result
.
Failure
(
employeeFamilyMemberResult
.
Error
);
#
endregion
#
region
5.
Add
reltion
to
DB
var
addedEmployeeFamilyMemberResult
=
await
_employeeFamilyMembersRepository
.
CreateAsync
(
employeeFamilyMemberResult
.
Value
);
if
(
addedEmployeeFamilyMemberResult
.
IsFailure
)
return
Result
.
Failure
(
addedEmployeeFamilyMemberResult
.
Error
);
#
endregion
#
region
6.
Attach
family
member
to
employee
var
employeeFamilyMember
=
addedEmployeeFamilyMemberResult
.
Value
;
var
attachResult
=
employee
.
AddFamilyMember
(
employeeFamilyMember
);
if
(
attachResult
.
IsFailure
)
return
Result
.
Failure
(
attachResult
.
Error
);
#
endregion
#
region
7.
Confirm
update
var
updateResult
=
await
_employeesRepository
.
UpdateAsync
(
employee
);
if
(
updateResult
.
IsFailure
)
return
Result
.
Failure
(
updateResult
.
Error
);
#
endregion
return
Result
.
Success
();
return
Result
.
Success
();
}
}
...
...
Clinics.Backend/Application/Employees/Commands/CreateEmployee/CreateEmployeeCommandHandler.cs
View file @
400a6cbb
...
@@ -7,7 +7,7 @@ using Domain.UnitOfWork;
...
@@ -7,7 +7,7 @@ using Domain.UnitOfWork;
namespace
Application.Employees.Commands.CreateEmployee
;
namespace
Application.Employees.Commands.CreateEmployee
;
public
class
CreateEmployeeCommandHandler
:
CommandHandler
<
CreateEmployeeCommand
>
public
class
CreateEmployeeCommandHandler
:
CommandHandler
Base
<
CreateEmployeeCommand
>
{
{
#
region
CTOR
DI
#
region
CTOR
DI
private
readonly
IEmployeesRepository
_employeesRepository
;
private
readonly
IEmployeesRepository
_employeesRepository
;
...
...
Clinics.Backend/Domain/Entities/People/Employees/Employee.cs
View file @
400a6cbb
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers
;
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers
;
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers.FamilyRoleValues
;
using
Domain.Entities.People.Employees.Shared
;
using
Domain.Entities.People.Employees.Shared
;
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Entities.People.Patients
;
using
Domain.Entities.People.Patients
;
using
Domain.Entities.People.Shared.GenderValues
;
using
Domain.Entities.People.Shared.GenderValues
;
using
Domain.Primitives
;
using
Domain.Primitives
;
...
@@ -103,32 +102,24 @@ public sealed class Employee : Entity
...
@@ -103,32 +102,24 @@ public sealed class Employee : Entity
#
endregion
#
endregion
#
region
Add
family
member
#
region
Add
family
member
public
Result
AddFamilyMember
(
FamilyMember
familyMember
,
string
role
)
public
Result
AddFamilyMember
(
EmployeeFamilyMember
employeeFamilyMember
)
{
{
#
region
Create
family
member
to
attach
Result
<
EmployeeFamilyMember
>
employeeFamilyMember
=
EmployeeFamilyMember
.
Create
(
Id
,
familyMember
.
Id
,
role
);
if
(
employeeFamilyMember
.
IsFailure
)
return
Result
.
Failure
(
employeeFamilyMember
.
Error
);
#
endregion
#
region
Check
valid
relation
#
region
Check
valid
relation
if
(
role
==
FamilyRoles
.
Husband
.
Name
&&
Patient
.
Gender
==
Genders
.
Male
)
if
(
employeeFamilyMember
.
Role
==
FamilyRoles
.
Husband
&&
employeeFamilyMember
.
FamilyMember
.
Patient
.
Gender
==
Genders
.
Male
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidHusbandRole
);
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidHusbandRole
);
if
(
role
==
FamilyRoles
.
Wife
.
Name
&&
Patient
.
Gender
==
Genders
.
Female
)
if
(
employeeFamilyMember
.
Role
==
FamilyRoles
.
Wife
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidWifeRole
);
&&
Patient
.
Gender
==
Genders
.
Female
)
#
endregion
return
Result
.
Failure
(
Errors
.
DomainErrors
.
InvalidWifeRole
);
#
region
Check
duplicate
if
(
FamilyMembers
.
Where
(
fm
=>
fm
.
FamilyMember
==
familyMember
).
ToList
().
Count
>
0
)
return
Result
.
Failure
(
Errors
.
DomainErrors
.
RelationAlreadyExist
);
#
endregion
#
endregion
_familyMembers
.
Add
(
employeeFamilyMember
.
Value
);
_familyMembers
.
Add
(
employeeFamilyMember
);
IsMarried
=
true
;
IsMarried
=
true
;
return
Result
.
Success
();
return
Result
.
Success
();
}
}
...
...
Clinics.Backend/Domain/Entities/People/Employees/Relations/EmployeeFamilyMembers/EmployeeFamilyMember.cs
View file @
400a6cbb
...
@@ -11,10 +11,10 @@ public sealed class EmployeeFamilyMember : Entity
...
@@ -11,10 +11,10 @@ public sealed class EmployeeFamilyMember : Entity
private
EmployeeFamilyMember
(
int
id
)
:
base
(
id
)
private
EmployeeFamilyMember
(
int
id
)
:
base
(
id
)
{
{
}
}
private
EmployeeFamilyMember
(
int
id
,
int
employeeId
,
int
familyMemberId
,
FamilyRole
role
)
:
base
(
id
)
private
EmployeeFamilyMember
(
int
id
,
Employee
employee
,
FamilyMember
familyMember
,
FamilyRole
role
)
:
base
(
id
)
{
{
Employee
Id
=
employeeId
;
Employee
=
employee
;
FamilyMember
Id
=
familyMemberId
;
FamilyMember
=
familyMember
;
Role
=
role
;
Role
=
role
;
}
}
#
endregion
#
endregion
...
@@ -46,9 +46,9 @@ public sealed class EmployeeFamilyMember : Entity
...
@@ -46,9 +46,9 @@ public sealed class EmployeeFamilyMember : Entity
#
region
Methods
#
region
Methods
#
region
Static
factory
#
region
Static
factory
public
static
Result
<
EmployeeFamilyMember
>
Create
(
int
employeeId
,
int
familyMemberId
,
string
role
)
public
static
Result
<
EmployeeFamilyMember
>
Create
(
Employee
employee
,
FamilyMember
familyMember
,
string
role
)
{
{
if
(
employee
Id
<=
0
||
familyMemberId
<=
0
||
role
is
null
)
if
(
employee
is
null
||
familyMember
is
null
||
role
is
null
)
return
Result
.
Failure
<
EmployeeFamilyMember
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
return
Result
.
Failure
<
EmployeeFamilyMember
>(
Errors
.
DomainErrors
.
InvalidValuesError
);
#
region
Check
role
#
region
Check
role
...
@@ -73,7 +73,7 @@ public sealed class EmployeeFamilyMember : Entity
...
@@ -73,7 +73,7 @@ public sealed class EmployeeFamilyMember : Entity
#
endregion
#
endregion
return
new
EmployeeFamilyMember
(
0
,
employee
Id
,
familyMemberId
,
selectedRole
.
Value
);
return
new
EmployeeFamilyMember
(
0
,
employee
,
familyMember
,
selectedRole
.
Value
);
}
}
#
endregion
#
endregion
...
...
Clinics.Backend/Domain/Repositories/IEmployeeFamilyMembersRepository.cs
0 → 100644
View file @
400a6cbb
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers
;
using
Domain.Repositories.Base
;
namespace
Domain.Repositories
;
public
interface
IEmployeeFamilyMembersRepository
:
IRepository
<
EmployeeFamilyMember
>
{
}
Clinics.Backend/Persistence/Repositories/EmployeeFamilyMembersRepository.cs
0 → 100644
View file @
400a6cbb
using
Domain.Entities.People.Employees.Relations.EmployeeFamilyMembers
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Repositories.Base
;
namespace
Persistence.Repositories
;
public
class
EmployeeFamilyMembersRepository
:
Repositroy
<
EmployeeFamilyMember
>,
IEmployeeFamilyMembersRepository
{
#
region
CTOR
DI
for
context
public
EmployeeFamilyMembersRepository
(
ClinicsDbContext
context
)
:
base
(
context
)
{
}
#
endregion
#
region
Create
method
public
override
Task
<
Result
<
EmployeeFamilyMember
>>
CreateAsync
(
EmployeeFamilyMember
entity
)
{
_context
.
Entry
(
entity
.
Role
).
State
=
EntityState
.
Unchanged
;
return
base
.
CreateAsync
(
entity
);
}
#
endregion
}
Clinics.Backend/Persistence/Repositories/FamilyMembersRepository.cs
View file @
400a6cbb
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Repositories
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Context
;
using
Persistence.Repositories.Base
;
using
Persistence.Repositories.Base
;
...
@@ -11,4 +13,12 @@ public class FamilyMembersRepository : Repositroy<FamilyMember>, IFamilyMembersR
...
@@ -11,4 +13,12 @@ public class FamilyMembersRepository : Repositroy<FamilyMember>, IFamilyMembersR
public
FamilyMembersRepository
(
ClinicsDbContext
context
)
:
base
(
context
)
{}
public
FamilyMembersRepository
(
ClinicsDbContext
context
)
:
base
(
context
)
{}
#
endregion
#
endregion
#
region
Create
method
public
override
Task
<
Result
<
FamilyMember
>>
CreateAsync
(
FamilyMember
entity
)
{
_context
.
Entry
(
entity
.
Patient
.
Gender
).
State
=
EntityState
.
Unchanged
;
return
base
.
CreateAsync
(
entity
);
}
#
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