public Int32 SaveDrugDispenseDetails(Entities.DrugDispense drugDispense) { var drugDispenseId = 0; var db = DBConnect.getDBConnection(); using (DbConnection conn = db.CreateConnection()) { conn.Open(); using (DbTransaction dbTransaction = conn.BeginTransaction()) { try { var drugDispenseDrugUtilisationId = 0; if (drugDispense != null) { if (drugDispense.DrugDispenseId == null || drugDispense.DrugDispenseId == 0) { drugDispenseId = AddDrugDispenseDetails(drugDispense, dbTransaction); } else if (drugDispense.ModifiedBy != null || drugDispense.ModifiedBy > 0) { drugDispenseId = UpdateDrugDispenseDetails(drugDispense, dbTransaction); } else if (drugDispense.IsDeleted == true) { var result = DeleteDrugDispenseDetails(drugDispense, dbTransaction); if (result) { drugDispenseId = (int)drugDispense.DrugDispenseId; } else { drugDispenseId = -1; } } if (drugDispenseId > 0) { if (drugDispense.IsDeleted == true) { DrugDispenseDrugUtilisation drugUtilisationDB = new DrugDispenseDrugUtilisation(); var result = drugUtilisationDB.DeleteDrugDispenseDrugUtilisationDetailsByDrugDispenseId((int)drugDispense.DrugDispenseId, (int)drugDispense.DeletedBy, drugDispense.DeletedByIP, dbTransaction); if (result) { drugDispenseDrugUtilisationId = (int)drugDispense.DrugDispenseId; } } if (drugDispense.DrugDispenseDrugUtilisations != null) { if (drugDispense.DrugDispenseDrugUtilisations.Count > 0) { foreach (Entities.DrugDispenseDrugUtilisation drugUtilisation in drugDispense.DrugDispenseDrugUtilisations) { DrugDispenseDrugUtilisation drugUtilisationDB = new DrugDispenseDrugUtilisation(); drugUtilisation.DrugDispenseId = drugDispenseId; drugDispenseDrugUtilisationId = drugUtilisationDB.SaveDrugDispenseDrugUtilisation(drugUtilisation, dbTransaction); if (drugDispenseDrugUtilisationId < 0) { drugDispenseId = -1; } } } } } } if (drugDispenseId > 0) { dbTransaction.Commit(); } else { dbTransaction.Rollback(); } } catch (Exception ex) { drugDispenseId = -1; dbTransaction.Rollback(); throw ex; } } return(drugDispenseId); } }
public List <Entities.DrugDispenseDrugUtilisation> GetDrugUtilisationByDrugDispenseId(Int32 drugDispenseId) { var drugDetails = new DrugDispenseDrugUtilisation(); return(drugDetails.GetDrugUtilisationByDrugDispenseId(drugDispenseId)); }