private void UpdateDatabase() { // Get ids int toDoId = Int32.Parse(hdfToDoListId.Value); string toDolistType = hdfFmType.Value; int companyId = Int32.Parse(hdfCompanyId.Value); // Delete DB.Open(); DB.BeginTransaction(); try { ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(toDolistInformationTDS); toDoListToDoListActivity.DeleteAllDirect(toDoId, companyId); ToDoListToDoList toDoList = new ToDoListToDoList(null); toDoList.DeleteDirect(toDoId, companyId); DB.CommitTransaction(); } catch (Exception ex) { DB.RollbackTransaction(); string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' ')); Response.Redirect(url); } }
/// <summary> /// Save /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ToDoListInformationTDS toDoListInformationChanges = (ToDoListInformationTDS)Data.GetChanges(); if (toDoListInformationChanges != null) { if (toDoListInformationChanges.BasicInformation.Rows.Count > 0) { ToDoListInformationBasicInformationGateway toDoListInformationBasicInformationGateway = new ToDoListInformationBasicInformationGateway(toDoListInformationChanges); // Update to do foreach (ToDoListInformationTDS.BasicInformationRow row in (ToDoListInformationTDS.BasicInformationDataTable)toDoListInformationChanges.BasicInformation) { // Unchanged values int toDoId = row.ToDoID; string subject = toDoListInformationBasicInformationGateway.GetSubject(toDoId); DateTime creationDate = toDoListInformationBasicInformationGateway.GetCreationDate(toDoId); int createdById = toDoListInformationBasicInformationGateway.GetCreatedByID(toDoId); // Original values DateTime? originalDueDate = null; if (toDoListInformationBasicInformationGateway.GetDueDateOriginal(toDoId).HasValue) originalDueDate = (DateTime)toDoListInformationBasicInformationGateway.GetDueDateOriginal(toDoId); int? originalUnitId = null; if (toDoListInformationBasicInformationGateway.GetUnitIDOriginal(toDoId).HasValue) originalUnitId = (int)toDoListInformationBasicInformationGateway.GetUnitIDOriginal(toDoId); string originalState = toDoListInformationBasicInformationGateway.GetStateOriginal(toDoId); // New variables DateTime? newDueDate = null; if (toDoListInformationBasicInformationGateway.GetDueDate(toDoId).HasValue) newDueDate = (DateTime)toDoListInformationBasicInformationGateway.GetDueDate(toDoId); int? newUnitId = null; if (toDoListInformationBasicInformationGateway.GetUnitID(toDoId).HasValue) newUnitId = (int)toDoListInformationBasicInformationGateway.GetUnitID(toDoId); string newState = toDoListInformationBasicInformationGateway.GetState(toDoId); ToDoListToDoList toDoListToDoList = new ToDoListToDoList(null); toDoListToDoList.UpdateDirect(toDoId, subject, creationDate, createdById, originalState, originalDueDate, originalUnitId, row.Deleted, row.COMPANY_ID, toDoId, subject, creationDate, createdById, newState, newDueDate, newUnitId, row.Deleted, row.COMPANY_ID); } } } }
/// <summary> /// Save to do lists /// </summary> /// <param name="creationDate">creationDate</param> /// <param name="companyId">companyId</param> public int? Save(DateTime creationDate, int companyId) { int newToDoListId = 0; ToDoListAddTDS ToDoListAddChanges = (ToDoListAddTDS)Data.GetChanges(); if (ToDoListAddChanges.BasicInformation.Rows.Count > 0) { ToDoListToDoListGateway toDoListToDoListGateway = new ToDoListToDoListGateway(ToDoListAddChanges); foreach (ToDoListAddTDS.BasicInformationRow row in (ToDoListAddTDS.BasicInformationDataTable)ToDoListAddChanges.BasicInformation) { string subject = ""; if (!row.IsSubjectNull()) subject = row.Subject; string comment = ""; if (!row.IsCommentNull()) comment = row.Comment; DateTime? dueDate = null; if (!row.IsDueDateNull()) dueDate = row.DueDate; int? unitId = null; if (!row.IsUnitIdNull()) unitId = row.UnitId; int employeeId = 0; if (!row.IsTeamMemberIDNull()) employeeId = row.TeamMemberID; bool deleted = row.Deleted; string state = row.State; int createdById = row.CreatedByID; int refId = 1; string type_ = row.Type_; // ... Insert the to do list ToDoListToDoList toDoListToDoList = new ToDoListToDoList(null); newToDoListId = toDoListToDoList.InsertDirect(subject, creationDate, createdById, state, dueDate, unitId, deleted, companyId); // ... Insert first Activity (Default Assignation - first Activity) ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null); toDoListToDoListActivity.InsertDirect(newToDoListId, refId, employeeId, type_, creationDate, row.Deleted, companyId, comment); } } return newToDoListId; }