public void Add(Master mObj) { mObj.CanDelete = true;//double-make-sure that new record is not marked as undeletable object updateObj = GetTableObj(mObj); #region Insert On Submit switch (masterType) { //case Table.Role:dbc.MasterRoles.InsertOnSubmit((MasterRole)updateObj); break; //new MasterRole(){ID=mObj.ID, Title=mObj.Title, SortOrder=mObj.SortOrder, //LastModifiedBy=mObj.LastModifiedBy, LastModifiedDate=mObj.LastModifiedDate}); case Table.Claim_Status: dbc.MasterClaimStatus.InsertOnSubmit((MasterClaimStatus)updateObj); break; case Table.Defect: dbc.MasterDefects.InsertOnSubmit((MasterDefect)updateObj); break; case Table.File_Type_Detail: dbc.MasterFileTypeDetails.InsertOnSubmit((MasterFileTypeDetail)updateObj); break; case Table.File_Type_Header: dbc.MasterFileTypeHeaders.InsertOnSubmit((MasterFileTypeHeader)updateObj); break; //case Table.Activity: dbc.MasterActivities.InsertOnSubmit((MasterActivity)updateObj); break; } #endregion //dbc.SubmitChanges(); }
/// <summary> /// Returns specific Master object wrapped as object as per - masterType /// </summary> /// <param name="mObj">Master object</param> /// <returns>Specific Master object wrapped as object</returns> public object GetTableObj(Master mObj) { switch (masterType) { case Table.Claim_Status: return new MasterClaimStatus() { ID = mObj.ID, Title = mObj.Title, SortOrder = mObj.SortOrder, LastModifiedBy = mObj.LastModifiedBy, LastModifiedDate = mObj.LastModifiedDate, CanDelete = mObj.CanDelete }; case Table.Defect: return new MasterDefect() { ID = mObj.ID, Title = mObj.Title, //HT:Special field //Category = mObj.Category, SortOrder = mObj.SortOrder, LastModifiedBy = mObj.LastModifiedBy, LastModifiedDate = mObj.LastModifiedDate, CanDelete = mObj.CanDelete }; case Table.File_Type_Detail: return new MasterFileTypeDetail() { ID = mObj.ID, Title = mObj.Title, SortOrder = mObj.SortOrder, LastModifiedBy = mObj.LastModifiedBy, LastModifiedDate = mObj.LastModifiedDate, CanDelete = mObj.CanDelete }; case Table.File_Type_Header: return new MasterFileTypeHeader() { ID = mObj.ID, Title = mObj.Title, SortOrder = mObj.SortOrder, LastModifiedBy = mObj.LastModifiedBy, LastModifiedDate = mObj.LastModifiedDate, CanDelete = mObj.CanDelete }; #region Role & Activity - kept for future /* case Table.Role: return new MasterRole() { ID = mObj.ID, Title = mObj.Title, SortOrder = mObj.SortOrder, LastModifiedBy = mObj.LastModifiedBy, LastModifiedDate = mObj.LastModifiedDate, CanDelete = mObj.CanDelete }; case Table.Activity: return new MasterActivity() { ID = mObj.ID, Title = mObj.Title, SortOrder = mObj.SortOrder, LastModifiedBy = mObj.LastModifiedBy, LastModifiedDate = mObj.LastModifiedDate, CanDelete = mObj.CanDelete };*/ #endregion default: return null; } }
public void Update(Master mObj) { //Set lastmodified fields mObj.LastModifiedBy = _SessionUsr.ID; mObj.LastModifiedDate = DateTime.Now; if (mObj.ID <= Defaults.Integer) // Insert return;//HT:SPECIAL CASE: W've handled Add separately so we skip //AddMasterEntry(mObj); else // Update { object updateObj = GetTableObj(mObj); #region Attach the object as modified switch (masterType) { //case Table.Role: dbc.MasterRoles.Attach((MasterRole)updateObj); break; case Table.Claim_Status: dbc.MasterClaimStatus.Attach((MasterClaimStatus)updateObj); break; case Table.Defect: dbc.MasterDefects.Attach((MasterDefect)updateObj); break; case Table.File_Type_Detail: dbc.MasterFileTypeDetails.Attach((MasterFileTypeDetail)updateObj); break; case Table.File_Type_Header: dbc.MasterFileTypeHeaders.Attach((MasterFileTypeHeader)updateObj); break; //case Table.Activity: dbc.MasterActivities.Attach((MasterActivity)updateObj); break; //dbc.MasterActivities.Attach(new MasterActivity(){ID=mObj.ID, Title=mObj.Title, SortOrder=mObj.SortOrder, //LastModifiedBy=mObj.LastModifiedBy, LastModifiedDate=mObj.LastModifiedDate}); } #endregion dbc.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, updateObj);//Optimistic-concurrency (simplest solution) //dbc.SubmitChanges(); } }
public void Delete(Master mObj) { //HT: CAUTION: Make sure references are checked #region Attach the object as modified switch (masterType) { case Table.Claim_Status: dbc.MasterClaimStatus.DeleteOnSubmit(dbc.MasterClaimStatus.Single (c =>c.CanDelete && c.ID == mObj.ID)); break; case Table.Defect: dbc.MasterDefects.DeleteOnSubmit(dbc.MasterDefects.Single (c => c.CanDelete && c.ID == mObj.ID)); break; case Table.File_Type_Detail: dbc.MasterFileTypeDetails.DeleteOnSubmit(dbc.MasterFileTypeDetails.Single (c => c.CanDelete && c.ID == mObj.ID)); break; case Table.File_Type_Header: dbc.MasterFileTypeHeaders.DeleteOnSubmit(dbc.MasterFileTypeHeaders.Single (c => c.CanDelete && c.ID == mObj.ID)); break; //case Table.Activity: dbc.MasterActivities.DeleteOnSubmit(dbc.MasterActivities.Single // (c =>c.CanDelete && c.ID == mObj.ID)); break; } #endregion //dbc.SubmitChanges(); }