public void UnassignIngredient(int p_Medication_OID, System.Collections.Generic.IList <int> p_ingredient_OIDs)
        {
            try
            {
                SessionInitializeTransaction();
                ChroniGenNHibernate.EN.Chroni.MedicationEN medicationEN = null;
                medicationEN = (MedicationEN)session.Load(typeof(MedicationEN), p_Medication_OID);

                ChroniGenNHibernate.EN.Chroni.IngredientEN ingredientENAux = null;
                if (medicationEN.Ingredient != null)
                {
                    foreach (int item in p_ingredient_OIDs)
                    {
                        ingredientENAux = (ChroniGenNHibernate.EN.Chroni.IngredientEN)session.Load(typeof(ChroniGenNHibernate.EN.Chroni.IngredientEN), item);
                        if (medicationEN.Ingredient.Contains(ingredientENAux) == true)
                        {
                            medicationEN.Ingredient.Remove(ingredientENAux);
                            ingredientENAux.Medication.Remove(medicationEN);
                        }
                        else
                        {
                            throw new ModelException("The identifier " + item + " in p_ingredient_OIDs you are trying to unrelationer, doesn't exist in MedicationEN");
                        }
                    }
                }

                session.Update(medicationEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is ChroniGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new ChroniGenNHibernate.Exceptions.DataLayerException("Error in MedicationCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
        public void AssignIngredient(int p_Medication_OID, System.Collections.Generic.IList <int> p_ingredient_OIDs)
        {
            ChroniGenNHibernate.EN.Chroni.MedicationEN medicationEN = null;
            try
            {
                SessionInitializeTransaction();
                medicationEN = (MedicationEN)session.Load(typeof(MedicationEN), p_Medication_OID);
                ChroniGenNHibernate.EN.Chroni.IngredientEN ingredientENAux = null;
                if (medicationEN.Ingredient == null)
                {
                    medicationEN.Ingredient = new System.Collections.Generic.List <ChroniGenNHibernate.EN.Chroni.IngredientEN>();
                }

                foreach (int item in p_ingredient_OIDs)
                {
                    ingredientENAux = new ChroniGenNHibernate.EN.Chroni.IngredientEN();
                    ingredientENAux = (ChroniGenNHibernate.EN.Chroni.IngredientEN)session.Load(typeof(ChroniGenNHibernate.EN.Chroni.IngredientEN), item);
                    ingredientENAux.Medication.Add(medicationEN);

                    medicationEN.Ingredient.Add(ingredientENAux);
                }


                session.Update(medicationEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is ChroniGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new ChroniGenNHibernate.Exceptions.DataLayerException("Error in MedicationCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            IngredientEN t = obj as IngredientEN;

            if (t == null)
            {
                return(false);
            }
            if (Identifier.Equals(t.Identifier))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public IngredientEN(IngredientEN ingredient)
 {
     this.init(Identifier, ingredient.Amount, ingredient.Medication, ingredient.IsActive, ingredient.SubstanceCode);
 }