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

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

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

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

            this.CompletedQty = obj.CompletedQty;
            this.StartedDate  = obj.StartedDate;

            this.OrderDetail = (obj.OrderDetailReference.EntityKey != null && obj.OrderDetailReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.OrderDetailReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.OrderDetailStatus = (obj.OrderDetailStatusReference.EntityKey != null && obj.OrderDetailStatusReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.OrderDetailStatusReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.Size = (obj.SizeReference.EntityKey != null && obj.SizeReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.SizeReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;

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

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

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

            obj.CompletedQty = this.CompletedQty;
            obj.StartedDate  = this.StartedDate;

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


            this._doNotUpdateDALObject = false;

            return(obj);
        }
 public void Add()
 {
     if (this.Context != null)
     {
         this.Context.Context.AddToFactoryOrderDetial(this.ObjDAL);
     }
     else
     {
         IndicoContext objContext          = new IndicoContext();
         Indico.DAL.FactoryOrderDetial obj = this.SetDAL(objContext.Context);
         objContext.Context.AddToFactoryOrderDetial(obj);
         objContext.SaveChanges();
         objContext.Dispose();
     }
 }
 void FactoryOrderDetialsWhereThisIsOrderDetailStatusList_OnBeforeRemove(object sender, EventArgs e)
 {
     Indico.DAL.FactoryOrderDetial obj = null;
     if (this.Context != null)
     {
         if (((IndicoList <Indico.BusinessObjects.FactoryOrderDetialBO>)sender).Count > 0)
         {
             obj = ((IndicoList <Indico.BusinessObjects.FactoryOrderDetialBO>)sender)[((IndicoList <Indico.BusinessObjects.FactoryOrderDetialBO>)sender).Count - 1].ObjDAL;
             this.ObjDAL.FactoryOrderDetialsWhereThisIsOrderDetailStatus.Remove(obj);
         }
     }
     else
     {
         IndicoContext objContext = new IndicoContext();
         obj = ((IndicoList <Indico.BusinessObjects.FactoryOrderDetialBO>)sender)[((IndicoList <Indico.BusinessObjects.FactoryOrderDetialBO>)sender).Count - 1].SetDAL(objContext.Context);
         this.ObjDAL.FactoryOrderDetialsWhereThisIsOrderDetailStatus.Remove(obj);
         objContext.SaveChanges();
         objContext.Dispose();
     }
 }
        /// <summary>
        /// Creates an instance of the FactoryOrderDetialBO class using the supplied Indico.DAL.FactoryOrderDetial.
        /// </summary>
        /// <param name="obj">a Indico.DAL.FactoryOrderDetial whose properties will be used to initialise the FactoryOrderDetialBO</param>
        internal FactoryOrderDetialBO(Indico.DAL.FactoryOrderDetial obj, ref IndicoContext context)
        {
            this._doNotUpdateDALObject = true;

            this.Context = context;

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

            this.CompletedQty = obj.CompletedQty;
            this.OrderDetail  = (obj.OrderDetailReference.EntityKey != null && obj.OrderDetailReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.OrderDetailReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.OrderDetailStatus = (obj.OrderDetailStatusReference.EntityKey != null && obj.OrderDetailStatusReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.OrderDetailStatusReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.Size = (obj.SizeReference.EntityKey != null && obj.SizeReference.EntityKey.EntityKeyValues.Count() > 0)
                ? (int)((System.Data.EntityKeyMember)obj.SizeReference.EntityKey.EntityKeyValues.GetValue(0)).Value
                : 0;
            this.StartedDate = obj.StartedDate;

            this._doNotUpdateDALObject = false;
        }