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

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

            if (this.ID > 0)
            {
                obj = context.VisualLayoutAccessory.FirstOrDefault <VisualLayoutAccessory>(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.VisualLayout > 0)
            {
                obj.VisualLayout = context.VisualLayout.FirstOrDefault(o => o.ID == this.VisualLayout);
            }


            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.VisualLayoutAccessory))
            {
                throw new FormatException("Received wrong parameter type...");
            }

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

            // set the Indico.BusinessObjects.VisualLayoutAccessoryBO 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.VisualLayout = (obj.VisualLayoutReference.EntityKey != null && obj.VisualLayoutReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.VisualLayoutReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

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

            this.Context = context;

            // set the properties from the Indico.DAL.VisualLayoutAccessory
            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.VisualLayout = (obj.VisualLayoutReference.EntityKey != null && obj.VisualLayoutReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.VisualLayoutReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

            this._doNotUpdateDALObject = false;
        }