public void UnassignMedication(int p_Activity_OID, System.Collections.Generic.IList <int> p_medication_OIDs)
        {
            try
            {
                SessionInitializeTransaction();
                ChroniGenNHibernate.EN.Chroni.ActivityEN activityEN = null;
                activityEN = (ActivityEN)session.Load(typeof(ActivityEN), p_Activity_OID);

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

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

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


            finally
            {
                SessionClose();
            }
        }
        public void AssignMedication(int p_Activity_OID, System.Collections.Generic.IList <int> p_medication_OIDs)
        {
            ChroniGenNHibernate.EN.Chroni.ActivityEN activityEN = null;
            try
            {
                SessionInitializeTransaction();
                activityEN = (ActivityEN)session.Load(typeof(ActivityEN), p_Activity_OID);
                ChroniGenNHibernate.EN.Chroni.MedicationEN medicationENAux = null;
                if (activityEN.Medication == null)
                {
                    activityEN.Medication = new System.Collections.Generic.List <ChroniGenNHibernate.EN.Chroni.MedicationEN>();
                }

                foreach (int item in p_medication_OIDs)
                {
                    medicationENAux = new ChroniGenNHibernate.EN.Chroni.MedicationEN();
                    medicationENAux = (ChroniGenNHibernate.EN.Chroni.MedicationEN)session.Load(typeof(ChroniGenNHibernate.EN.Chroni.MedicationEN), item);
                    medicationENAux.Activity.Add(activityEN);

                    activityEN.Medication.Add(medicationENAux);
                }


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

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


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

            if (t == null)
            {
                return(false);
            }
            if (Identifier.Equals(t.Identifier))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public ActivityEN(ActivityEN activity)
 {
     this.init(Identifier, activity.Progress, activity.Description, activity.CarePlan, activity.StartDate, activity.EndDate, activity.Medication);
 }