Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Medic
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
hasan.bahjat
Medic
Commits
d57d3621
Commit
d57d3621
authored
Jun 19, 2024
by
hasan khaddour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update services responsabilites
parent
60ef3ecb
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
55 deletions
+58
-55
IIngredientService.cs
ApplicationCore/Interfaces/IServices/IIngredientService.cs
+2
-0
IMedicalStateService.cs
ApplicationCore/Interfaces/IServices/IMedicalStateService.cs
+1
-1
IPatientService.cs
ApplicationCore/Interfaces/IServices/IPatientService.cs
+2
-2
ServiceBase.cs
ApplicationCore/Services/Base/ServiceBase.cs
+11
-6
IngredientService.cs
...ationCore/Services/IngredientService/IngredientService.cs
+12
-4
MedicalStateService.cs
...nCore/Services/MedicalStateService/MedicalStateService.cs
+11
-14
MedicineService.cs
ApplicationCore/Services/MedicineService/MedicineService.cs
+5
-14
PatientService.cs
ApplicationCore/Services/PatientService/PatientService.cs
+14
-14
No files found.
ApplicationCore/Interfaces/IServices/IIngredientService.cs
View file @
d57d3621
...
...
@@ -11,5 +11,7 @@ namespace ApplicationCore.Interfaces.IServices
public
interface
IIngredientService
:
IService
<
IngredientModel
>
{
public
void
AddToMedicine
(
MedicineIngredientModel
medicineIngredientModel
);
public
void
RemoveFromMedicine
(
MedicineIngredientModel
medicineIngredientModel
);
}
}
ApplicationCore/Interfaces/IServices/IMedicalStateService.cs
View file @
d57d3621
...
...
@@ -10,7 +10,7 @@ namespace ApplicationCore.Interfaces.IServices
{
public
interface
IMedicalStateService
:
IService
<
MedicalStateModel
>
{
public
IEnumerable
<
MedicalStateModel
>
GetAllPatientMedicalStates
(
int
patientId
);
public
Task
<
IEnumerable
<
MedicalStateModel
>
>
GetAllPatientMedicalStates
(
int
patientId
);
public
MedicalStateModel
AddToPateint
(
int
patientId
,
MedicalStateModel
medicalState
);
...
...
ApplicationCore/Interfaces/IServices/IPatientService.cs
View file @
d57d3621
...
...
@@ -12,9 +12,9 @@ namespace ApplicationCore.Interfaces.IServices
public
interface
IPatientService
:
IService
<
PatientModel
>
{
public
IEnumerable
<
MedicalStateModel
>
GetPatientMedicalStates
(
int
patientId
);
public
Task
<
IEnumerable
<
MedicalStateModel
>
>
GetPatientMedicalStates
(
int
patientId
);
public
Task
<
MedicalStateModel
>
GetMedicalStateDetails
(
int
id
);
public
Task
<
Patient
>
GetByUserID
(
String
id
);
public
Task
<
Patient
Model
>
GetByUserEmail
(
String
email
);
// public Task<IEnumerable<PatientModel>>GetAll();
public
void
AddMedicalState
(
int
patientId
,
MedicalStateModel
medicalState
);
// public Patient GetDetails(int id);
...
...
ApplicationCore/Services/Base/ServiceBase.cs
View file @
d57d3621
using
ApplicationCore.DomainModel
;
using
ApplicationCore.Interfaces
;
using
ApplicationDomain.Abstraction
;
using
ApplicationDomain.Exceptions
;
using
ApplicationDomain.Entities
;
using
AutoMapper
;
using
System
;
...
...
@@ -21,7 +22,7 @@ namespace ApplicationCore.Services
public
ServiceBase
(
IUnitOfWork
<
TEntity
>
unitOfWork
,
IMapper
mapper
IMapper
mapper
)
{
_unitOfWork
=
unitOfWork
;
...
...
@@ -39,7 +40,7 @@ namespace ApplicationCore.Services
{
TEntity
entity
=
_unitOfWork
.
Entity
.
Insert
(
_mapper
.
Map
<
TEntity
>(
model
));
_unitOfWork
.
Save
();
_unitOfWork
.
Commit
();
return
_mapper
.
Map
<
TModel
>(
entity
);
}
...
...
@@ -47,22 +48,26 @@ namespace ApplicationCore.Services
{
TEntity
entity
=
_unitOfWork
.
Entity
.
Update
(
_mapper
.
Map
<
TEntity
>(
model
));
_unitOfWork
.
Save
();
_unitOfWork
.
Commit
();
return
_mapper
.
Map
<
TModel
>(
entity
);
}
public
async
Task
<
TModel
>
GetDetails
(
int
id
)
{
return
_mapper
.
Map
<
TModel
>(
await
_unitOfWork
.
Entity
.
GetById
(
id
,
_specification
));
var
model
=
await
_unitOfWork
.
Entity
.
GetById
(
id
,
_specification
);
if
(
model
is
null
)
{
throw
new
NotFoundException
();
}
return
_mapper
.
Map
<
TModel
>(
model
);
}
public
void
Delete
(
int
id
)
{
_unitOfWork
.
Entity
.
Delete
(
id
);
_unitOfWork
.
Save
();
_unitOfWork
.
Commit
();
}
...
...
ApplicationCore/Services/IngredientService/IngredientService.cs
View file @
d57d3621
...
...
@@ -16,9 +16,9 @@ namespace ApplicationCore.Services
public
class
IngredientService
:
ServiceBase
<
Ingredient
,
IngredientModel
>
,
IIngredientService
{
public
IngredientService
(
IUnitOfWork
<
Ingredient
>
ingredientU
nitOfWork
,
IUnitOfWork
<
Ingredient
>
u
nitOfWork
,
IMapper
mapper
):
base
(
ingredientU
nitOfWork
,
mapper
)
):
base
(
u
nitOfWork
,
mapper
)
{
_specification
=
new
IngredientWithMedicinesSpecification
();
}
...
...
@@ -30,9 +30,17 @@ namespace ApplicationCore.Services
medicine
.
MedicineIngredients
.
Add
(
medicineIngredient
);
_unitOfWork
.
Entity
.
Update
(
medicine
);
_unitOfWork
.
Save
();
_unitOfWork
.
Commit
();
}
public
async
void
RemoveFromMedicine
(
MedicineIngredientModel
medicineIngredientModel
)
{
var
medicine
=
await
_unitOfWork
.
Entity
.
GetById
(
medicineIngredientModel
.
IngredientId
,
_specification
);
MedicineIngredient
medicineIngredient
=
_mapper
.
Map
<
MedicineIngredient
>(
medicineIngredientModel
);
var
m
=
medicine
.
MedicineIngredients
.
Where
(
p
=>
p
.
IngredientId
==
medicineIngredientModel
.
IngredientId
).
FirstOrDefault
();
medicine
.
MedicineIngredients
.
Remove
(
m
);
_unitOfWork
.
Entity
.
Update
(
medicine
);
_unitOfWork
.
Commit
();
}
}
...
...
ApplicationCore/Services/MedicalStateService/MedicalStateService.cs
View file @
d57d3621
...
...
@@ -11,21 +11,14 @@ namespace ApplicationCore.Services
{
public
class
MedicalStateService
:
ServiceBase
<
MedicalState
,
MedicalStateModel
>,
IMedicalStateService
{
private
readonly
PatientService
_patientService
;
private
readonly
IUnitOfWork
<
Medicine
>
_medicineUnitOfWork
;
private
readonly
MedicineWithIngredientsSpecification
_medicineSpecification
;
public
MedicalStateService
(
IUnitOfWork
<
MedicalState
>
medicalUnitOfWork
,
IUnitOfWork
<
Medicine
>
medicineUnitOfWork
,
IUnitOfWork
<
Patient
>
patientUnitOfWork
,
IMapper
Mapper
):
base
(
medicalUnitOfWork
,
Mapper
)
IUnitOfWork
<
MedicalState
>
unitOfWork
,
IMapper
Mapper
):
base
(
unitOfWork
,
Mapper
)
{
_specification
=
new
MedicalStateWithMedicinesSpecification
();
_medicineUnitOfWork
=
medicineUnitOfWork
;
_patientService
=
new
PatientService
(
patientUnitOfWork
,
medicalUnitOfWork
,
Mapper
);
_medicineSpecification
=
new
MedicineWithIngredientsSpecification
();
}
public
MedicalStateModel
AddToPateint
(
int
patientId
,
MedicalStateModel
medicalStateModel
)
{
...
...
@@ -34,14 +27,18 @@ namespace ApplicationCore.Services
var
im
=
medicalStateModel
;
var
r
=
_unitOfWork
.
Entity
.
Insert
(
_mapper
.
Map
<
MedicalState
>(
im
));
_unitOfWork
.
Save
();
_unitOfWork
.
Commit
();
return
_mapper
.
Map
<
MedicalStateModel
>(
r
);
}
public
IEnumerable
<
MedicalStateModel
>
GetAllPatientMedicalStates
(
int
patientId
)
public
async
Task
<
IEnumerable
<
MedicalStateModel
>
>
GetAllPatientMedicalStates
(
int
patientId
)
{
return
_mapper
.
Map
<
IEnumerable
<
MedicalStateModel
>>(
_patientService
.
GetPatientMedicalStates
(
patientId
));
return
_mapper
.
Map
<
IEnumerable
<
MedicalStateModel
>>(
await
_unitOfWork
.
MedicalStates
.
GetByPatient
(
patientId
,
_specification
)
);
}
...
...
ApplicationCore/Services/MedicineService/MedicineService.cs
View file @
d57d3621
using
ApplicationDomain.Entities
;
using
ApplicationCore.Interfaces
;
using
ApplicationCore.Interfaces.IServices
;
using
ApplicationDomain.Abstraction
;
using
ApplicationDomain.Specification
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
ApplicationCore.Mapper
;
using
AutoMapper
;
using
ApplicationCore.DomainModel
;
...
...
@@ -16,17 +10,13 @@ namespace ApplicationCore.Services
{
public
class
MedicineService
:
ServiceBase
<
Medicine
,
MedicineModel
>,
IMedicineService
{
private
IUnitOfWork
<
MedicalState
>
_medicalStateUnitOfWork
;
private
MedicalStateWithMedicinesSpecification
_medicalSpecification
;
public
MedicineService
(
IUnitOfWork
<
Medicine
>
medicineUnitOfWork
,
IUnitOfWork
<
MedicalState
>
medicalStateUnitOfWork
,
IMapper
Mapper
)
:
base
(
medicineUnitOfWork
,
Mapper
)
{
_medicalStateUnitOfWork
=
medicalStateUnitOfWork
;
_specification
=
new
MedicineWithIngredientsSpecification
();
_medicalSpecification
=
new
MedicalStateWithMedicinesSpecification
();
}
...
...
@@ -50,23 +40,24 @@ namespace ApplicationCore.Services
_unitOfWork
.
Entity
.
Update
(
medicine
);
_unitOfWork
.
Save
();
_unitOfWork
.
Commit
();
}
public
void
RemoveFromMedicalState
(
MedicalStateMedicineModel
medicalStateMedicineModel
)
{
var
m
=
_
medicalStateUnitOfWork
.
Entity
.
GetById
(
medicalStateMedicineModel
.
MedicalStateId
,
_medicalSpecification
).
Result
;
var
m
=
_
unitOfWork
.
MedicalStates
.
GetById
(
medicalStateMedicineModel
.
MedicalStateId
,
_medicalSpecification
).
Result
;
//// throw an exception
//if (m.Medicines is null)
// m.Medicines = new List<Medicine>();
var
d
=
_unitOfWork
.
Entity
.
GetById
(
medicalStateMedicineModel
.
MedicineId
,
_specification
).
Result
;
m
.
Medicines
.
Remove
(
d
);
_
medicalStateUnitOfWork
.
Entity
.
Update
(
m
);
_
medicalStateUnitOfWork
.
Save
();
_
unitOfWork
.
MedicalStates
.
Update
(
m
);
_
unitOfWork
.
Commit
();
}
public
MedicineModel
GetMedicineIngredentisDetails
(
int
medicineId
)
{
return
_mapper
.
Map
<
MedicineModel
>(
_unitOfWork
.
Entity
.
GetById
(
medicineId
,
_specification
));
...
...
ApplicationCore/Services/PatientService/PatientService.cs
View file @
d57d3621
...
...
@@ -16,35 +16,35 @@ namespace ApplicationCore.Services
{
public
class
PatientService
:
ServiceBase
<
Patient
,
PatientModel
>
,
IPatientService
{
private
readonly
IUnitOfWork
<
MedicalState
>
_medicalStateUnitOfWork
;
private
MedicalStateWithMedicinesSpecification
_medicalStateSpecification
;
public
PatientService
(
IUnitOfWork
<
Patient
>
patientUnitOfWork
,
IUnitOfWork
<
MedicalState
>
medicalStateUnitOfWork
,
IMapper
mapper
)
:
base
(
patientUnitOfWork
,
mapper
)
{
_medicalStateUnitOfWork
=
medicalStateUnitOfWork
;
_specification
=
new
PatientWithMedicinesSpecification
();
_medicalStateSpecification
=
new
MedicalStateWithMedicinesSpecification
();
}
public
IEnumerable
<
MedicalStateModel
>
GetPatientMedicalStates
(
int
patientId
)
{
return
_mapper
.
Map
<
IEnumerable
<
MedicalStateModel
>>(
_unitOfWork
.
Entity
.
GetById
(
patientId
,
_specification
).
Result
.
MedicalStates
.
AsEnumerable
());
public
async
Task
<
IEnumerable
<
MedicalStateModel
>>
GetPatientMedicalStates
(
int
patientId
)
{
return
_mapper
.
Map
<
IEnumerable
<
MedicalStateModel
>>(
await
_unitOfWork
.
MedicalStates
.
GetByPatient
(
patientId
,
_medicalStateSpecification
));
}
public
async
Task
<
MedicalStateModel
>
GetMedicalStateDetails
(
int
id
)
{
return
_mapper
.
Map
<
MedicalStateModel
>(
await
_
medicalStateUnitOfWork
.
Entity
.
GetById
(
id
,
_medicalStateSpecification
));
return
_mapper
.
Map
<
MedicalStateModel
>(
await
_
unitOfWork
.
MedicalStates
.
GetById
(
id
,
_medicalStateSpecification
));
}
public
void
AddMedicalState
(
int
patientId
,
MedicalStateModel
medicalState
)
{
var
ptient
=
_unitOfWork
.
Entity
.
GetById
(
patientId
,
_specification
).
Result
;
...
...
@@ -52,7 +52,7 @@ namespace ApplicationCore.Services
ptient
.
MedicalStates
.
Add
(
_mapper
.
Map
<
MedicalState
>(
medicalState
));
_unitOfWork
.
Entity
.
Update
(
ptient
);
_unitOfWork
.
Save
();
_unitOfWork
.
Commit
();
}
public
bool
PatientExists
(
int
id
)
...
...
@@ -60,10 +60,10 @@ namespace ApplicationCore.Services
return
_unitOfWork
.
Entity
.
GetById
(
id
)
is
null
?
false
:
true
;
}
public
async
Task
<
Patient
>
GetByUserID
(
string
id
)
public
async
Task
<
Patient
Model
>
GetByUserEmail
(
string
email
)
{
var
ps
=
await
_unitOfWork
.
Entity
.
GetAll
(
_specification
);
return
ps
.
Where
(
p
=>
p
.
UserId
==
id
).
FirstOrDefault
(
);
return
_mapper
.
Map
<
PatientModel
>(
ps
.
Where
(
p
=>
p
.
User
.
Email
==
email
).
FirstOrDefault
()
);
}
}
...
...
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