public void Delete()
 {
     if (this.Context != null)
     {
         if (this.ObjDAL != null && this.ObjDAL.EntityKey != null)
         {
             if (this.ObjDAL.EntityState == System.Data.EntityState.Detached)
             {
                 this.Context.Context.Attach(this.ObjDAL);
                 this.Context.Context.DeleteObject(this.ObjDAL);
             }
             else
             {
                 this.Context.Context.DeleteObject(this.ObjDAL);
             }
         }
         else
         {
             Indico.DAL.DistributorEmailAddress obj = this.SetDAL(this.Context.Context);
             this.Context.Context.DeleteObject(obj);
         }
     }
     else
     {
         IndicoContext objContext = new IndicoContext();
         Indico.DAL.DistributorEmailAddress obj = this.SetDAL(objContext.Context);
         this.Context.Context.DeleteObject(obj);
         objContext.Context.SaveChanges();
         objContext.Dispose();
     }
 }
 public void Add()
 {
     if (this.Context != null)
     {
         this.Context.Context.AddToDistributorEmailAddress(this.ObjDAL);
     }
     else
     {
         IndicoContext objContext = new IndicoContext();
         Indico.DAL.DistributorEmailAddress obj = this.SetDAL(objContext.Context);
         objContext.Context.AddToDistributorEmailAddress(obj);
         objContext.SaveChanges();
         objContext.Dispose();
     }
 }
        /// <summary>
        /// Creates an instance of the DistributorEmailAddressBO class using the supplied Indico.DAL.DistributorEmailAddress.
        /// </summary>
        /// <param name="obj">a Indico.DAL.DistributorEmailAddress whose properties will be used to initialise the DistributorEmailAddressBO</param>
        internal DistributorEmailAddressBO(Indico.DAL.DistributorEmailAddress obj, ref IndicoContext context)
        {
            this._doNotUpdateDALObject = true;

            this.Context = context;

            // set the properties from the Indico.DAL.DistributorEmailAddress
            this.ID = obj.ID;

            this.Distributor = (obj.DistributorReference.EntityKey != null && obj.DistributorReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.DistributorReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.EmailAddress = obj.EmailAddress;

            this._doNotUpdateDALObject = false;
        }
        internal void SetBO(System.Data.Objects.DataClasses.EntityObject eObj)
        {
            this._doNotUpdateDALObject = true;

            // Check the received type
            if (eObj.GetType() != typeof(Indico.DAL.DistributorEmailAddress))
            {
                throw new FormatException("Received wrong parameter type...");
            }

            Indico.DAL.DistributorEmailAddress obj = (Indico.DAL.DistributorEmailAddress)eObj;

            // set the Indico.BusinessObjects.DistributorEmailAddressBO properties
            this.ID = obj.ID;

            this.EmailAddress = obj.EmailAddress;

            this.Distributor = (obj.DistributorReference.EntityKey != null && obj.DistributorReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.DistributorReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

            this._doNotUpdateDALObject = false;
        }
        internal Indico.DAL.DistributorEmailAddress SetDAL(IndicoEntities context)
        {
            this._doNotUpdateDALObject = true;

            // set the Indico.DAL.DistributorEmailAddress properties
            Indico.DAL.DistributorEmailAddress obj = new Indico.DAL.DistributorEmailAddress();

            if (this.ID > 0)
            {
                obj = context.DistributorEmailAddress.FirstOrDefault <DistributorEmailAddress>(o => o.ID == this.ID);
            }

            obj.EmailAddress = this.EmailAddress;

            if (this.Distributor > 0)
            {
                obj.Distributor = context.Company.FirstOrDefault(o => o.ID == this.Distributor);
            }


            this._doNotUpdateDALObject = false;

            return(obj);
        }