static public bool DeleteTaskChargeCode(DdTaskChargeCodeExt item, RevisionInfo revisionInfo) { DaTaskChargeCode da = new DaTaskChargeCode(DataStore.DbConnection); bool ok = da.DeleteById(item.Id); if (ok) AddChangeLog(da.TableName, item.Id, item.Timestamp, revisionInfo); //delete return ok; }
static public void UpdateTaskChargeCode(BindingSource binding, int taskHeadingRoleREF, RevisionInfo revInfo) { BindingList<DdTaskChargeCodeExt> list = (BindingList<DdTaskChargeCodeExt>)binding.DataSource; try { using (TransactionScope scope = new TransactionScope()) { DaTaskChargeCode da = new DaTaskChargeCode(DataStore.CloneDbConnection()); foreach (DdTaskChargeCodeExt item in list) {// do deletes first bool existing = da.GetById(item.Id); if (existing && item.DeleteFlag) {// delete here - avoid validation da.DeleteById(item.Id); AddChangeLog(da.TableName, item.Id, da.Timestamp, revInfo); } } foreach (DdTaskChargeCodeExt item in list) { if (item.DeleteFlag) continue; // already done above //if (item.Id == string.Empty) continue; // already done above bool existing = da.GetById(item.Id); if (!existing) { da.Clear(); } da.Description = item.Description; da.TaskChargeCodeID = item.TaskChargeCodeID; da.TaskHeadingRoleREF = item.TaskHeadingRoleREF; da.Title = item.Title; if (!existing) { da.TaskHeadingRoleREF = taskHeadingRoleREF; da.Insert(); AddChangeLog(da.TableName, da.Id, da.Timestamp, revInfo); } else { if (!da._IsModified) continue; da.Modified = DateTime.Now; da.ModifiedBy = Environment.UserName; da.Save(); AddChangeLog(da.TableName, da.Id, da.Timestamp, revInfo); } } scope.Complete(); } binding.DataSource = GetTaskChargeCodeList(taskHeadingRoleREF); } catch (AppEx) { throw; } catch (Exception exc) { throw new AppEx(exc, "Error updating TaskChargeCode"); } }