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
9c1bae96
Commit
9c1bae96
authored
Aug 19, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add attach family member to employee feature
parent
f55bf66c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
93 additions
and
3 deletions
+93
-3
Application.csproj
Clinics.Backend/Application/Application.csproj
+0
-1
AttachFamilyMemberToEmployeeCommand.cs
...lyMemberToEmployee/AttachFamilyMemberToEmployeeCommand.cs
+17
-0
AttachFamilyMemberToEmployeeCommandHandler.cs
...rToEmployee/AttachFamilyMemberToEmployeeCommandHandler.cs
+64
-0
EmployeesController.cs
...s.Backend/Presentation/Controllers/EmployeesController.cs
+12
-2
No files found.
Clinics.Backend/Application/Application.csproj
View file @
9c1bae96
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Folder Include="Employees\Commands\AttachFamilyMemberToEmployee\" />
<Folder Include="Employees\Queries\" />
<Folder Include="Employees\Queries\" />
</ItemGroup>
</ItemGroup>
</Project>
</Project>
Clinics.Backend/Application/Employees/Commands/AttachFamilyMemberToEmployee/AttachFamilyMemberToEmployeeCommand.cs
0 → 100644
View file @
9c1bae96
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
public
class
AttachFamilyMemberToEmployeeCommand
:
ICommand
{
public
string
EmployeeSerialNumber
{
get
;
set
;
}
=
null
!;
public
string
FirstName
{
get
;
set
;
}
=
null
!;
public
string
MiddleName
{
get
;
set
;
}
=
null
!;
public
string
LastName
{
get
;
set
;
}
=
null
!;
public
DateOnly
DateOfBirth
{
get
;
set
;
}
public
string
Gender
{
get
;
set
;
}
=
null
!;
public
string
FamilyRole
{
get
;
set
;
}
=
null
!;
}
Clinics.Backend/Application/Employees/Commands/AttachFamilyMemberToEmployee/AttachFamilyMemberToEmployeeCommandHandler.cs
0 → 100644
View file @
9c1bae96
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Entities.People.Employees
;
using
Domain.Entities.People.FamilyMembers
;
using
Domain.Errors
;
using
Domain.Repositories
;
using
Domain.Shared
;
using
Domain.UnitOfWork
;
namespace
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
public
class
AttachFamilyMemberToEmployeeCommandHandler
:
ICommandHandler
<
AttachFamilyMemberToEmployeeCommand
>
{
#
region
CTOR
DI
private
readonly
IEmployeesRepository
_employeesRepository
;
private
readonly
IUnitOfWork
_unitOfWork
;
public
AttachFamilyMemberToEmployeeCommandHandler
(
IEmployeesRepository
employeesRepository
,
IUnitOfWork
unitOfWork
)
{
_employeesRepository
=
employeesRepository
;
_unitOfWork
=
unitOfWork
;
}
#
endregion
public
async
Task
<
Result
>
Handle
(
AttachFamilyMemberToEmployeeCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
1.
Create
family
member
Result
<
FamilyMember
>
familyMemberResult
=
FamilyMember
.
Create
(
request
.
FirstName
,
request
.
MiddleName
,
request
.
LastName
,
request
.
DateOfBirth
,
request
.
Gender
);
if
(
familyMemberResult
.
IsFailure
)
return
Result
.
Failure
(
familyMemberResult
.
Error
);
#
endregion
#
region
2.
Get
employee
by
serial
number
Result
<
Employee
>
employeeResult
=
await
_employeesRepository
.
GetEmployeeBySerialNumberAsync
(
request
.
EmployeeSerialNumber
);
if
(
employeeResult
.
IsFailure
)
return
Result
.
Failure
(
employeeResult
.
Error
);
#
endregion
#
region
3.
Attach
family
member
to
employee
Result
attachFamilyMemberResult
=
employeeResult
.
Value
.
AddFamilyMember
(
familyMemberResult
.
Value
,
request
.
FamilyRole
);
if
(
attachFamilyMemberResult
.
IsFailure
)
return
Result
.
Failure
(
attachFamilyMemberResult
.
Error
);
#
endregion
#
region
4.
Confirm
update
try
{
_employeesRepository
.
Update
(
employeeResult
.
Value
);
await
_unitOfWork
.
SaveChangesAsync
();
}
catch
(
Exception
)
{
return
Result
.
Failure
(
PersistenceErrors
.
UnableToCompleteTransaction
);
}
return
Result
.
Success
();
#
endregion
}
}
Clinics.Backend/Presentation/Controllers/EmployeesController.cs
View file @
9c1bae96
using
Application.Employees.Commands.CreateEmployee
;
using
Application.Employees.Commands.AttachFamilyMemberToEmployee
;
using
Application.Employees.Commands.CreateEmployee
;
using
MediatR
;
using
MediatR
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Presentation.Controllers.Base
;
using
Presentation.Controllers.Base
;
...
@@ -17,11 +18,20 @@ public class EmployeesController : ApiController
...
@@ -17,11 +18,20 @@ public class EmployeesController : ApiController
[
HttpPost
]
[
HttpPost
]
public
async
Task
<
IActionResult
>
Create
(
CreateEmployeeCommand
command
)
public
async
Task
<
IActionResult
>
Create
(
[
FromBody
]
CreateEmployeeCommand
command
)
{
{
var
result
=
await
_sender
.
Send
(
command
);
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsFailure
)
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
HandleFailure
(
result
);
return
Created
();
return
Created
();
}
}
[
HttpPut
(
"FamilyMembers"
)]
public
async
Task
<
IActionResult
>
AttachFamilyMember
([
FromBody
]
AttachFamilyMemberToEmployeeCommand
command
)
{
var
result
=
await
_sender
.
Send
(
command
);
if
(
result
.
IsFailure
)
return
HandleFailure
(
result
);
return
Ok
();
}
}
}
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