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.ArtWorktAccessory obj = this.SetDAL(this.Context.Context);
             this.Context.Context.DeleteObject(obj);
         }
     }
     else
     {
         IndicoContext objContext         = new IndicoContext();
         Indico.DAL.ArtWorktAccessory obj = this.SetDAL(objContext.Context);
         this.Context.Context.DeleteObject(obj);
         objContext.Context.SaveChanges();
         objContext.Dispose();
     }
 }
        internal Indico.DAL.ArtWorktAccessory SetDAL(IndicoEntities context)
        {
            this._doNotUpdateDALObject = true;

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

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


            if (this.Accessory != null && this.Accessory > 0)
            {
                obj.Accessory = context.Accessory.FirstOrDefault(o => o.ID == this.Accessory);
            }
            if (this.AccessoryColor != null && this.AccessoryColor > 0)
            {
                obj.AccessoryColor = context.AccessoryColor.FirstOrDefault(o => o.ID == this.AccessoryColor);
            }
            if (this.ArtWork > 0)
            {
                obj.ArtWork = context.ArtWork.FirstOrDefault(o => o.ID == this.ArtWork);
            }


            this._doNotUpdateDALObject = false;

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

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

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

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


            this.Accessory = (obj.AccessoryReference.EntityKey != null && obj.AccessoryReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.AccessoryReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.AccessoryColor = (obj.AccessoryColorReference.EntityKey != null && obj.AccessoryColorReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.AccessoryColorReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.ArtWork = (obj.ArtWorkReference.EntityKey != null && obj.ArtWorkReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.ArtWorkReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

            this._doNotUpdateDALObject = false;
        }
 public void Add()
 {
     if (this.Context != null)
     {
         this.Context.Context.AddToArtWorktAccessory(this.ObjDAL);
     }
     else
     {
         IndicoContext objContext         = new IndicoContext();
         Indico.DAL.ArtWorktAccessory obj = this.SetDAL(objContext.Context);
         objContext.Context.AddToArtWorktAccessory(obj);
         objContext.SaveChanges();
         objContext.Dispose();
     }
 }
        /// <summary>
        /// Creates an instance of the ArtWorktAccessoryBO class using the supplied Indico.DAL.ArtWorktAccessory.
        /// </summary>
        /// <param name="obj">a Indico.DAL.ArtWorktAccessory whose properties will be used to initialise the ArtWorktAccessoryBO</param>
        internal ArtWorktAccessoryBO(Indico.DAL.ArtWorktAccessory obj, ref IndicoContext context)
        {
            this._doNotUpdateDALObject = true;

            this.Context = context;

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

            this.Accessory = (obj.AccessoryReference.EntityKey != null && obj.AccessoryReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.AccessoryReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.AccessoryColor = (obj.AccessoryColorReference.EntityKey != null && obj.AccessoryColorReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.AccessoryColorReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.ArtWork = (obj.ArtWorkReference.EntityKey != null && obj.ArtWorkReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.ArtWorkReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

            this._doNotUpdateDALObject = false;
        }