Commit 97bb368d authored by hasan khaddour's avatar hasan khaddour

modi. services

parent 3160c673
using ApplicationCore.Entities;
using ApplicationCore.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ApplicationCore.Services.IngredientService
{
public class IngredientService
{
private readonly IUnitOfWork<Ingredient> _ingredientUnitOfWork;
public IngredientService(IUnitOfWork<Ingredient> ingredientUnitOfWork)
{
_ingredientUnitOfWork = ingredientUnitOfWork;
}
public IEnumerable<Ingredient> GetAllIngredients()
{
return _ingredientUnitOfWork.Entity.GetAll(
p=>p.MedicineIngredients
);
}
public void AddIngredient(Ingredient ingredient)
{
_ingredientUnitOfWork.Entity.Insert(ingredient);
_ingredientUnitOfWork.Save();
}
public Ingredient Update(Ingredient ingredient)
{
var r = _ingredientUnitOfWork.Entity.Update(ingredient);
_ingredientUnitOfWork.Save();
return r;
}
public Ingredient GetIngredientDetails(int id)
{
return _ingredientUnitOfWork.Entity.GetById(id,
i => i.MedicineIngredients,
i => i.Medicines
);
}
public void Delete(int id)
{
_ingredientUnitOfWork.Entity.Delete(id);
_ingredientUnitOfWork.Save();
}
}
}
...@@ -24,6 +24,7 @@ namespace ApplicationCore.Services.MedicineService ...@@ -24,6 +24,7 @@ namespace ApplicationCore.Services.MedicineService
); );
} }
public void AddMedicine(Medicine medicine) { public void AddMedicine(Medicine medicine) {
_medicineUnitOfWork.Entity.Insert(medicine); _medicineUnitOfWork.Entity.Insert(medicine);
_medicineUnitOfWork.Save(); _medicineUnitOfWork.Save();
...@@ -49,6 +50,20 @@ namespace ApplicationCore.Services.MedicineService ...@@ -49,6 +50,20 @@ namespace ApplicationCore.Services.MedicineService
return _medicineUnitOfWork.Entity.GetById(id , i => i.MedicineIngredients , i => i.Ingredients,c => c.Category ); return _medicineUnitOfWork.Entity.GetById(id , i => i.MedicineIngredients , i => i.Ingredients,c => c.Category );
} }
public Medicine GetMedicineIngredentisDetails(int medicineId) {
return _medicineUnitOfWork.Entity
.GetById(medicineId ,
i => i.MedicineIngredients,
i => i.Ingredients,
c => c.Category);
}
public void AddIngredient(int medicineId, int ratio ,Ingredient ingredient) {
var m = GetMedicineIngredentisDetails(medicineId);
m.AddIngredient(ingredient ,ratio );
_medicineUnitOfWork.Entity.Update(m);
_medicineUnitOfWork.Save();
}
public void Delete(int id) { public void Delete(int id) {
_medicineUnitOfWork.Entity.Delete(id); _medicineUnitOfWork.Entity.Delete(id);
_medicineUnitOfWork.Save(); _medicineUnitOfWork.Save();
......
...@@ -35,8 +35,11 @@ namespace ApplicationCore.Services.PatientService ...@@ -35,8 +35,11 @@ namespace ApplicationCore.Services.PatientService
return _patientUnitOfWork.Entity.GetAll(includeProperties); return _patientUnitOfWork.Entity.GetAll(includeProperties);
} }
public void AddMedicine(int patientId, Medicine medicine) { public void AddMedicine(int patientId, Medicine medicine) {
var ptient = _patientUnitOfWork.Entity.GetById(patientId, p => p.Medicines); var ptient = _patientUnitOfWork.Entity.GetById(patientId);
ptient.Medicines.Add(medicine); ptient.Medicines.Add(medicine);
_patientUnitOfWork.Entity.Update(ptient);
_patientUnitOfWork.Save();
} }
public Patient getById(int id, params Expression<Func<Patient, object>>[] includeProperties) public Patient getById(int id, params Expression<Func<Patient, object>>[] includeProperties)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment