Commit 356661c5 authored by hasan khaddour's avatar hasan khaddour

update ingredient service

parent cbdb40d0
...@@ -10,7 +10,7 @@ namespace ApplicationCore.Interfaces.IServices ...@@ -10,7 +10,7 @@ namespace ApplicationCore.Interfaces.IServices
{ {
public interface IIngredientService : IService<IngredientModel> public interface IIngredientService : IService<IngredientModel>
{ {
public void AddToMedicine(MedicineIngredientModel medicineIngredientModel); public Task<MedicineIngredientModel> AddToMedicine(MedicineIngredientModel medicineIngredientModel);
public void RemoveFromMedicine(MedicineIngredientModel medicineIngredientModel); public void RemoveFromMedicine(MedicineIngredientModel medicineIngredientModel);
} }
......
...@@ -24,7 +24,7 @@ namespace ApplicationCore.Services ...@@ -24,7 +24,7 @@ namespace ApplicationCore.Services
} }
public async void AddToMedicine(MedicineIngredientModel medicineIngredientModel) { public async Task<MedicineIngredientModel> AddToMedicine(MedicineIngredientModel medicineIngredientModel) {
var medicine = await _unitOfWork.Entity.GetById(medicineIngredientModel.IngredientId,_specification); var medicine = await _unitOfWork.Entity.GetById(medicineIngredientModel.IngredientId,_specification);
MedicineIngredient medicineIngredient = _mapper.Map<MedicineIngredient>(medicineIngredientModel); MedicineIngredient medicineIngredient = _mapper.Map<MedicineIngredient>(medicineIngredientModel);
medicine.MedicineIngredients.Add( medicine.MedicineIngredients.Add(
...@@ -32,14 +32,17 @@ namespace ApplicationCore.Services ...@@ -32,14 +32,17 @@ namespace ApplicationCore.Services
); );
_unitOfWork.Entity.Update(medicine); _unitOfWork.Entity.Update(medicine);
_unitOfWork.Commit(); _unitOfWork.Commit();
return medicineIngredientModel;
} }
public async void RemoveFromMedicine(MedicineIngredientModel medicineIngredientModel) public async void RemoveFromMedicine(MedicineIngredientModel medicineIngredientModel)
{ {
var medicine = await _unitOfWork.Entity.GetById(medicineIngredientModel.IngredientId, _specification); var ingredient = await _unitOfWork.Ingredients.GetById(medicineIngredientModel.IngredientId, _specification);
MedicineIngredient medicineIngredient = _mapper.Map<MedicineIngredient>(medicineIngredientModel); MedicineIngredient medicineIngredient = _mapper.Map<MedicineIngredient>(medicineIngredientModel);
var m =medicine.MedicineIngredients.Where(p => p.IngredientId == medicineIngredientModel.IngredientId).FirstOrDefault(); var m =ingredient.MedicineIngredients.Where(p => p.MedicineId == medicineIngredientModel.MedicineId).FirstOrDefault();
medicine.MedicineIngredients.Remove(m); ingredient.MedicineIngredients.Remove(m);
_unitOfWork.Entity.Update(medicine);
_unitOfWork.Entity.Update(ingredient);
_unitOfWork.Commit(); _unitOfWork.Commit();
} }
......
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