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
caf7e1cb
Commit
caf7e1cb
authored
Aug 17, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add create employee command
parent
a23dc773
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
161 additions
and
20 deletions
+161
-20
Application.csproj
Clinics.Backend/Application/Application.csproj
+4
-0
CreateEmployeeCommand.cs
...cation/Employees/Commands/Create/CreateEmployeeCommand.cs
+36
-0
CreateEmployeeCommandHandler.cs
...Employees/Commands/Create/CreateEmployeeCommandHandler.cs
+55
-0
Employee.cs
Clinics.Backend/Domain/Entities/People/Employees/Employee.cs
+1
-1
EmployeeAdditionalInfo.cs
...ntities/People/Employees/Shared/EmployeeAdditionalInfo.cs
+9
-1
IEmployeesRepository.cs
Clinics.Backend/Domain/Repositories/IEmployeesRepository.cs
+8
-0
Repositroy.cs
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
+1
-2
EmployeesRepository.cs
...s.Backend/Persistence/Repositories/EmployeesRepository.cs
+21
-0
EmployeesController.cs
...s.Backend/Presentation/Controllers/EmployeesController.cs
+26
-0
TestsController.cs
Clinics.Backend/Presentation/Controllers/TestsController.cs
+0
-16
No files found.
Clinics.Backend/Application/Application.csproj
View file @
caf7e1cb
...
@@ -13,4 +13,8 @@
...
@@ -13,4 +13,8 @@
<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<Folder Include="Employees\Queries\" />
</ItemGroup>
</Project>
</Project>
Clinics.Backend/Application/Employees/Commands/Create/CreateEmployeeCommand.cs
0 → 100644
View file @
caf7e1cb
using
Application.Abstractions.CQRS.Commands
;
namespace
Application.Employees.Commands.Create
;
public
class
CreateEmployeeCommand
:
ICommand
{
// Future update: Employees data will be fetched from ID system's API
#
region
Personal
info
public
string
FirstName
{
get
;
set
;
}
=
null
!;
public
string
MiddleName
{
get
;
set
;
}
=
null
!;
public
string
LastName
{
get
;
set
;
}
=
null
!;
#
endregion
#
region
Patient
info
public
DateOnly
DateOfBirth
{
get
;
set
;
}
public
string
Gender
{
get
;
set
;
}
=
null
!;
#
endregion
#
region
Employee
info
public
string
SerialNumber
{
get
;
set
;
}
=
null
!;
public
string
CenterStatus
{
get
;
set
;
}
=
null
!;
#
endregion
#
region
Optional
fields
public
DateOnly
?
StartDate
{
get
;
set
;
}
=
null
;
public
string
?
AcademicQualification
{
get
;
set
;
}
=
null
;
public
string
?
WorkPhone
{
get
;
set
;
}
=
null
;
public
string
?
Location
{
get
;
set
;
}
=
null
;
public
string
?
Specialization
{
get
;
set
;
}
=
null
;
public
string
?
JobStatus
{
get
;
set
;
}
=
null
;
#
endregion
}
Clinics.Backend/Application/Employees/Commands/Create/CreateEmployeeCommandHandler.cs
0 → 100644
View file @
caf7e1cb
using
Application.Abstractions.CQRS.Commands
;
using
Domain.Entities.People.Employees
;
using
Domain.Repositories
;
using
Domain.UnitOfWork
;
namespace
Application.Employees.Commands.Create
;
public
class
CreateEmployeeCommandHandler
:
ICommandHandler
<
CreateEmployeeCommand
>
{
#
region
CTOR
DI
private
readonly
IEmployeesRepository
_employeesRepository
;
private
readonly
IUnitOfWork
_unitOfWork
;
public
CreateEmployeeCommandHandler
(
IEmployeesRepository
employeesRepository
,
IUnitOfWork
unitOfWork
)
{
_employeesRepository
=
employeesRepository
;
_unitOfWork
=
unitOfWork
;
}
#
endregion
public
async
Task
Handle
(
CreateEmployeeCommand
request
,
CancellationToken
cancellationToken
)
{
#
region
Create
new
employee
Employee
employee
;
try
{
employee
=
Employee
.
Create
(
request
.
FirstName
,
request
.
MiddleName
,
request
.
LastName
,
// Personal info
request
.
DateOfBirth
,
request
.
Gender
,
// Patient info
request
.
SerialNumber
,
request
.
CenterStatus
,
false
,
// Employee info
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
);
await
_unitOfWork
.
SaveChangesAsync
();
}
catch
(
Exception
)
{
throw
;
}
#
endregion
}
}
Clinics.Backend/Domain/Entities/People/Employees/Employee.cs
View file @
caf7e1cb
...
@@ -95,7 +95,7 @@ public sealed class Employee : Entity
...
@@ -95,7 +95,7 @@ public sealed class Employee : Entity
#
endregion
#
endregion
#
region
Create
additional
info
#
region
Create
additional
info
EmployeeAdditionalInfo
additionalInfo
;
EmployeeAdditionalInfo
?
additionalInfo
;
try
try
{
{
additionalInfo
=
EmployeeAdditionalInfo
.
Create
(
startDate
,
academicQualification
,
additionalInfo
=
EmployeeAdditionalInfo
.
Create
(
startDate
,
academicQualification
,
...
...
Clinics.Backend/Domain/Entities/People/Employees/Shared/EmployeeAdditionalInfo.cs
View file @
caf7e1cb
...
@@ -54,7 +54,7 @@ public sealed class EmployeeAdditionalInfo : Entity
...
@@ -54,7 +54,7 @@ public sealed class EmployeeAdditionalInfo : Entity
#
region
Methods
#
region
Methods
#
region
Static
factory
#
region
Static
factory
public
static
EmployeeAdditionalInfo
Create
(
DateOnly
?
startDate
,
public
static
EmployeeAdditionalInfo
?
Create
(
DateOnly
?
startDate
,
string
?
academicQualification
,
string
?
academicQualification
,
string
?
workPhone
,
string
?
workPhone
,
string
?
location
,
string
?
location
,
...
@@ -62,6 +62,14 @@ public sealed class EmployeeAdditionalInfo : Entity
...
@@ -62,6 +62,14 @@ public sealed class EmployeeAdditionalInfo : Entity
string
?
jobStatus
,
string
?
jobStatus
,
string
?
imageUrl
)
string
?
imageUrl
)
{
{
if
(
startDate
is
null
&&
academicQualification
is
null
&&
workPhone
is
null
&&
location
is
null
&&
specialization
is
null
&&
jobStatus
is
null
&&
imageUrl
is
null
)
return
null
;
return
new
EmployeeAdditionalInfo
(
0
,
return
new
EmployeeAdditionalInfo
(
0
,
startDate
,
academicQualification
,
workPhone
,
location
,
specialization
,
jobStatus
,
imageUrl
);
startDate
,
academicQualification
,
workPhone
,
location
,
specialization
,
jobStatus
,
imageUrl
);
}
}
...
...
Clinics.Backend/Domain/Repositories/IEmployeesRepository.cs
0 → 100644
View file @
caf7e1cb
using
Domain.Entities.People.Employees
;
using
Domain.Repositories.Base
;
namespace
Domain.Repositories
;
public
interface
IEmployeesRepository
:
IRepository
<
Employee
>
{
}
Clinics.Backend/Persistence/Repositories/Base/Repositroy.cs
View file @
caf7e1cb
using
Domain.Primitives
;
using
Domain.Primitives
;
using
Domain.Repositories.Base
;
using
Domain.Repositories.Base
;
using
Domain.UnitOfWork
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Context
;
using
Persistence.Repositories.Specifications.Base
;
using
Persistence.Repositories.Specifications.Base
;
...
@@ -15,7 +14,7 @@ public class Repositroy<TEntity> : IRepository<TEntity> where TEntity : Entity
...
@@ -15,7 +14,7 @@ public class Repositroy<TEntity> : IRepository<TEntity> where TEntity : Entity
protected
readonly
ClinicsDbContext
_context
;
protected
readonly
ClinicsDbContext
_context
;
public
Repositroy
(
ClinicsDbContext
context
,
IUnitOfWork
unitOfWork
)
public
Repositroy
(
ClinicsDbContext
context
)
{
{
_context
=
context
;
_context
=
context
;
}
}
...
...
Clinics.Backend/Persistence/Repositories/EmployeesRepository.cs
0 → 100644
View file @
caf7e1cb
using
Domain.Entities.People.Employees
;
using
Domain.Repositories
;
using
Microsoft.EntityFrameworkCore
;
using
Persistence.Context
;
using
Persistence.Repositories.Base
;
namespace
Persistence.Repositories
;
public
class
EmployeesRepository
:
Repositroy
<
Employee
>,
IEmployeesRepository
{
public
EmployeesRepository
(
ClinicsDbContext
context
)
:
base
(
context
)
{}
#
region
Create
method
public
override
void
Create
(
Employee
entity
)
{
_context
.
Entry
(
entity
.
Patient
.
Gender
).
State
=
EntityState
.
Unchanged
;
_context
.
Set
<
Employee
>().
Add
(
entity
);
}
#
endregion
}
Clinics.Backend/Presentation/Controllers/EmployeesController.cs
0 → 100644
View file @
caf7e1cb
using
Application.Employees.Commands.Create
;
using
MediatR
;
using
Microsoft.AspNetCore.Mvc
;
namespace
Presentation.Controllers
;
[Route("api/[controller]
")]
[ApiController]
public
class
EmployeesController
:
ControllerBase
{
#
region
DI
for
MeditR
sender
private
readonly
ISender
_sender
;
public
EmployeesController
(
ISender
sender
)
{
_sender
=
sender
;
}
#
endregion
[
HttpPost
]
public
async
Task
<
IActionResult
>
Create
(
CreateEmployeeCommand
command
)
{
await
_sender
.
Send
(
command
);
return
Ok
();
}
}
Clinics.Backend/Presentation/Controllers/TestsController.cs
deleted
100644 → 0
View file @
a23dc773
using
Microsoft.AspNetCore.Mvc
;
namespace
Presentation.Controllers
{
[
Route
(
"api/[controller]"
)]
[
ApiController
]
public
class
TestsController
:
ControllerBase
{
[
HttpGet
]
public
ActionResult
Index
()
{
object
respone
=
new
{
Result
=
"Hello world!"
};
return
Ok
(
respone
);
}
}
}
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