static public bool SaveChangeRequest(ref DdChangeRequestExt item, RevisionInfo revisionInfo) { DaChangeRequest da = new DaChangeRequest(DataStore.DbConnection); if (!da.GetById(item.Id)) return false; da.ApplicationREF = item.ApplicationREF; da.Comment = item.Comment; da.RequestID = item.RequestID; da.Title = item.Title; bool ok = true; if (da._IsModified) { da.Modified = DateTime.Now; da.ModifiedBy = Environment.UserName; ok = da.Save(); if (ok) AddChangeLog(da.TableName, da.Id, da.Timestamp, revisionInfo); if (ok) item = new DdChangeRequestExt(da.GetBuffer()); } return ok; }
static public void UpdateChangeRequest(BindingSource binding, int applicationREF, RevisionInfo revInfo) { BindingList<DdChangeRequestExt> list = (BindingList<DdChangeRequestExt>)binding.DataSource; try { using (TransactionScope scope = new TransactionScope()) { DaChangeRequest da = new DaChangeRequest(DataStore.CloneDbConnection()); foreach (DdChangeRequestExt 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 (DdChangeRequestExt item in list) { if (item.DeleteFlag) continue; // already done above //if (item.ChangeRequestID == string.Empty) continue; // already done above bool existing = da.GetById(item.Id); if (!existing) { da.Clear(); } da.ApplicationREF = item.ApplicationREF; da.Comment = item.Comment; da.RequestID = item.RequestID; da.Title = item.Title; if (!existing) { da.ApplicationREF = applicationREF; 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 = GetChangeRequestList(applicationREF); } catch (AppEx) { throw; } catch (Exception exc) { throw new AppEx(exc, "Error updating ChangeRequest"); } }