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

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

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

            obj.Extension = this.Extension;
            obj.Filename  = this.Filename;
            obj.Size      = this.Size;

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


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

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

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

            this.Extension = obj.Extension;
            this.Filename  = obj.Filename;
            this.Size      = obj.Size;

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

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

            this.Context = context;

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

            this.Extension = obj.Extension;
            this.Filename  = obj.Filename;
            this.Item      = (obj.ItemReference.EntityKey != null && obj.ItemReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.ItemReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.Size = obj.Size;

            this._doNotUpdateDALObject = false;
        }