示例#1
0
 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.ItemAttribute obj = this.SetDAL(this.Context.Context);
             this.Context.Context.DeleteObject(obj);
         }
     }
     else
     {
         IndicoContext            objContext = new IndicoContext();
         Indico.DAL.ItemAttribute obj        = this.SetDAL(objContext.Context);
         this.Context.Context.DeleteObject(obj);
         objContext.Context.SaveChanges();
         objContext.Dispose();
     }
 }
示例#2
0
        internal void SetBO(System.Data.Objects.DataClasses.EntityObject eObj)
        {
            this._doNotUpdateDALObject = true;

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

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

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

            this.Description = obj.Description;
            this.Name        = obj.Name;

            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.Parent = (obj.ParentReference.EntityKey != null && obj.ParentReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.ParentReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

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

            this.Context = context;

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

            this.Description = obj.Description;
            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.Name   = obj.Name;
            this.Parent = (obj.ParentReference.EntityKey != null && obj.ParentReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.ParentReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

            this._doNotUpdateDALObject = false;
        }
示例#5
0
 void ItemAttributesWhereThisIsParentList_OnBeforeRemove(object sender, EventArgs e)
 {
     Indico.DAL.ItemAttribute obj = null;
     if (this.Context != null)
     {
         if (((IndicoList <Indico.BusinessObjects.ItemAttributeBO>)sender).Count > 0)
         {
             obj = ((IndicoList <Indico.BusinessObjects.ItemAttributeBO>)sender)[((IndicoList <Indico.BusinessObjects.ItemAttributeBO>)sender).Count - 1].ObjDAL;
             this.ObjDAL.ItemAttributesWhereThisIsParent.Remove(obj);
         }
     }
     else
     {
         IndicoContext objContext = new IndicoContext();
         obj = ((IndicoList <Indico.BusinessObjects.ItemAttributeBO>)sender)[((IndicoList <Indico.BusinessObjects.ItemAttributeBO>)sender).Count - 1].SetDAL(objContext.Context);
         this.ObjDAL.ItemAttributesWhereThisIsParent.Remove(obj);
         objContext.SaveChanges();
         objContext.Dispose();
     }
 }
示例#6
0
        internal Indico.DAL.ItemAttribute SetDAL(IndicoEntities context)
        {
            this._doNotUpdateDALObject = true;

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

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

            obj.Description = this.Description;
            obj.Name        = this.Name;

            if (this.Item > 0)
            {
                obj.Item = context.Item.FirstOrDefault(o => o.ID == this.Item);
            }
            if (this.Parent != null && this.Parent > 0)
            {
                obj.Parent = context.ItemAttribute.FirstOrDefault(o => o.ID == this.Parent);
            }

            if (_itemAttributesWhereThisIsParentLoaded)
            {
                BusinessObject.SynchroniseEntityList(
                    Indico.BusinessObjects.ItemAttributeBO.ToEntityList(this.ItemAttributesWhereThisIsParent, context),
                    obj.ItemAttributesWhereThisIsParent);
            }
            if (_patternItemAttributeSubsWhereThisIsItemAttributeLoaded)
            {
                BusinessObject.SynchroniseEntityList(
                    Indico.BusinessObjects.PatternItemAttributeSubBO.ToEntityList(this.PatternItemAttributeSubsWhereThisIsItemAttribute, context),
                    obj.PatternItemAttributeSubsWhereThisIsItemAttribute);
            }

            this._doNotUpdateDALObject = false;

            return(obj);
        }