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.HSCode obj = this.SetDAL(this.Context.Context); this.Context.Context.DeleteObject(obj); } } else { IndicoContext objContext = new IndicoContext(); Indico.DAL.HSCode 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.HSCode)) { throw new FormatException("Received wrong parameter type..."); } Indico.DAL.HSCode obj = (Indico.DAL.HSCode)eObj; // set the Indico.BusinessObjects.HSCodeBO properties this.ID = obj.ID; this.Code = obj.Code; this.Gender = (obj.GenderReference.EntityKey != null && obj.GenderReference.EntityKey.EntityKeyValues.Count() > 0) ? (int)((System.Data.EntityKeyMember)obj.GenderReference.EntityKey.EntityKeyValues.GetValue(0)).Value : 0; this.ItemSubCategory = (obj.ItemSubCategoryReference.EntityKey != null && obj.ItemSubCategoryReference.EntityKey.EntityKeyValues.Count() > 0) ? (int)((System.Data.EntityKeyMember)obj.ItemSubCategoryReference.EntityKey.EntityKeyValues.GetValue(0)).Value : 0; this._doNotUpdateDALObject = false; }
internal Indico.DAL.HSCode SetDAL(IndicoEntities context) { this._doNotUpdateDALObject = true; // set the Indico.DAL.HSCode properties Indico.DAL.HSCode obj = new Indico.DAL.HSCode(); if (this.ID > 0) { obj = context.HSCode.FirstOrDefault <HSCode>(o => o.ID == this.ID); } obj.Code = this.Code; if (this.Gender > 0) { obj.Gender = context.Gender.FirstOrDefault(o => o.ID == this.Gender); } if (this.ItemSubCategory > 0) { obj.ItemSubCategory = context.Item.FirstOrDefault(o => o.ID == this.ItemSubCategory); } this._doNotUpdateDALObject = false; return(obj); }
public void Add() { if (this.Context != null) { this.Context.Context.AddToHSCode(this.ObjDAL); } else { IndicoContext objContext = new IndicoContext(); Indico.DAL.HSCode obj = this.SetDAL(objContext.Context); objContext.Context.AddToHSCode(obj); objContext.SaveChanges(); objContext.Dispose(); } }
/// <summary> /// Creates an instance of the HSCodeBO class using the supplied Indico.DAL.HSCode. /// </summary> /// <param name="obj">a Indico.DAL.HSCode whose properties will be used to initialise the HSCodeBO</param> internal HSCodeBO(Indico.DAL.HSCode obj, ref IndicoContext context) { this._doNotUpdateDALObject = true; this.Context = context; // set the properties from the Indico.DAL.HSCode this.ID = obj.ID; this.Code = obj.Code; this.Gender = (obj.GenderReference.EntityKey != null && obj.GenderReference.EntityKey.EntityKeyValues.Count() > 0) ? (int)((System.Data.EntityKeyMember)obj.GenderReference.EntityKey.EntityKeyValues.GetValue(0)).Value : 0; this.ItemSubCategory = (obj.ItemSubCategoryReference.EntityKey != null && obj.ItemSubCategoryReference.EntityKey.EntityKeyValues.Count() > 0) ? (int)((System.Data.EntityKeyMember)obj.ItemSubCategoryReference.EntityKey.EntityKeyValues.GetValue(0)).Value : 0; this._doNotUpdateDALObject = false; }
void HSCodesWhereThisIsGenderList_OnBeforeRemove(object sender, EventArgs e) { Indico.DAL.HSCode obj = null; if (this.Context != null) { if (((IndicoList <Indico.BusinessObjects.HSCodeBO>)sender).Count > 0) { obj = ((IndicoList <Indico.BusinessObjects.HSCodeBO>)sender)[((IndicoList <Indico.BusinessObjects.HSCodeBO>)sender).Count - 1].ObjDAL; this.ObjDAL.HSCodesWhereThisIsGender.Remove(obj); } } else { IndicoContext objContext = new IndicoContext(); obj = ((IndicoList <Indico.BusinessObjects.HSCodeBO>)sender)[((IndicoList <Indico.BusinessObjects.HSCodeBO>)sender).Count - 1].SetDAL(objContext.Context); this.ObjDAL.HSCodesWhereThisIsGender.Remove(obj); objContext.SaveChanges(); objContext.Dispose(); } }