/// <summary>
        /// Save all comments to database (direct)
        /// </summary>
        /// <param name="originalWorkId">originalWorkId</param>
        /// <param name="companyId">companyId</param>        
        public void Save(int originalWorkId, int companyId)
        {
            RehabAssessmentTDS rehabAssessmentCommentDetailsChanges = (RehabAssessmentTDS)Data.GetChanges();

            if (rehabAssessmentCommentDetailsChanges.CommentDetails.Rows.Count > 0)
            {
                RehabAssessmentCommentDetailsGateway rehabAssessmentCommentDetailsGateway = new RehabAssessmentCommentDetailsGateway(rehabAssessmentCommentDetailsChanges);

                foreach (RehabAssessmentTDS.CommentDetailsRow row in (RehabAssessmentTDS.CommentDetailsDataTable)rehabAssessmentCommentDetailsChanges.CommentDetails)
                {
                    // Insert new comment
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        WorkComments workComments = new WorkComments(null);
                        int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID;

                        workComments.InsertDirect(row.WorkID, row.RefID, row.Type, row.Subject, row.UserID, row.DateTime_, row.Comment, libraryFilesId, row.Deleted, row.COMPANY_ID, row.WorkType);
                    }

                    // Update comment
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        int refId = row.RefID;
                        bool originalDeleted = false;
                        int originalCompanyId = companyId;

                        // original values
                        string originalType = rehabAssessmentCommentDetailsGateway.GetTypeOriginal(workId, refId);
                        string originalSubject = rehabAssessmentCommentDetailsGateway.GetSubjectOriginal(workId, refId);
                        int originalUserId = rehabAssessmentCommentDetailsGateway.GetUserIdOriginal(workId, refId);
                        DateTime? originalDateTime = null; if (rehabAssessmentCommentDetailsGateway.GetDateTime_Original(workId, refId) != null) originalDateTime = rehabAssessmentCommentDetailsGateway.GetDateTime_Original(workId, refId);
                        string originalComment = rehabAssessmentCommentDetailsGateway.GetCommentOriginal(workId, refId);
                        int? originalLibraryFilesId = null; if (rehabAssessmentCommentDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = rehabAssessmentCommentDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId);
                        string originalWorkType = rehabAssessmentCommentDetailsGateway.GetWorkTypeOriginal(workId, refId);

                        // new values
                        string newType = rehabAssessmentCommentDetailsGateway.GetType(workId, refId);
                        string newSubject = rehabAssessmentCommentDetailsGateway.GetSubject(workId, refId);
                        string newComment = rehabAssessmentCommentDetailsGateway.GetComment(workId, refId);
                        int? newLibraryFilesId = null; if (rehabAssessmentCommentDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = rehabAssessmentCommentDetailsGateway.GetLIBRARY_FILES_ID(workId, refId);

                        WorkComments workComments = new WorkComments(null);
                        workComments.UpdateDirect(workId, refId, originalType, originalSubject, originalUserId, originalDateTime, originalComment, originalLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType, workId, refId, newType, newSubject, originalUserId, originalDateTime, newComment, newLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType);
                    }

                    // Deleted comment
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        WorkComments workComments = new WorkComments(null);
                        workComments.DeleteDirect(row.WorkID, row.RefID, row.COMPANY_ID);
                    }

                }
            }
        }
        /// <summary>
        /// Save Previous Comments
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="workType">workType</param>
        /// <param name="companyId">companyId</param>
        /// <param name="newSectionWorkId">newSectionWorkId</param>
        private void SavePreviousComments(int parentWorkId, string workType, int companyId, int childWorkId)
        {
            WorkCommentsGateway parentWorkCommentsGateway = new WorkCommentsGateway();
            parentWorkCommentsGateway.LoadAllByWorkIdWorkType(parentWorkId, companyId, workType);

            WorkCommentsGateway childWorkCommentsGateway = new WorkCommentsGateway();
            childWorkCommentsGateway.LoadAllByWorkIdWorkType(childWorkId, companyId, workType);
            WorkComments childWorkComments = new WorkComments(childWorkCommentsGateway.Data);

            int lastRefId = childWorkComments.GetNewRefId();

            foreach (WorkTDS.LFS_WORK_COMMENTRow commentRow in (WorkTDS.LFS_WORK_COMMENTDataTable)parentWorkCommentsGateway.Table)
            {
                WorkComments workComments = new WorkComments();

                int refId = lastRefId;
                string type = ""; if (!commentRow.IsTypeNull()) type = commentRow.Type;
                string subject = commentRow.Subject;
                int userId = commentRow.UserID;
                DateTime? dateTime_ = null; if (!commentRow.IsDateTime_Null()) dateTime_ = commentRow.DateTime_;
                string comment = ""; if (!commentRow.IsCommentNull()) comment = commentRow.Comment;
                int? libraryFilesId = null; if (!commentRow.IsLIBRARY_FILES_IDNull()) libraryFilesId = commentRow.LIBRARY_FILES_ID;

                workComments.InsertDirect(childWorkId, refId, type, subject, userId, dateTime_, comment, libraryFilesId, false, companyId, workType);

                lastRefId++;
            }
        }
        /// <summary>
        /// Save Previous Comments
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="workType">workType</param>
        /// <param name="companyId">companyId</param>
        /// <param name="newSectionWorkId">newSectionWorkId</param>
        private void SavePreviousComments(int workId, string workType, int companyId, int newSectionWorkId)
        {
            WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
            workCommentsGateway.LoadAllByWorkIdWorkType(workId, companyId, workType);

            foreach (WorkTDS.LFS_WORK_COMMENTRow commentRow in (WorkTDS.LFS_WORK_COMMENTDataTable)workCommentsGateway.Table)
            {
                int refId = commentRow.RefID;
                string type = ""; if (!commentRow.IsTypeNull()) type = commentRow.Type;
                string subject = commentRow.Subject;
                int userId = commentRow.UserID;
                DateTime? dateTime_ = null; if (!commentRow.IsDateTime_Null()) dateTime_ = commentRow.DateTime_;
                string comment = ""; if (!commentRow.IsCommentNull()) comment = commentRow.Comment;
                int? libraryFilesId = null; if (!commentRow.IsLIBRARY_FILES_IDNull()) libraryFilesId = commentRow.LIBRARY_FILES_ID;

                WorkComments workComments = new WorkComments();
                workComments.InsertDirect(newSectionWorkId, refId, type, subject, userId, dateTime_, comment, libraryFilesId, false, companyId, workType);
            }
        }
        /// <summary>
        /// Save all comments to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            PointRepairsTDS pointRepairsChanges = (PointRepairsTDS)Data.GetChanges();

            if (pointRepairsChanges.CommentDetails.Rows.Count > 0)
            {
                PointRepairsCommentDetailsGateway pointRepairsCommentDetailsGateway = new PointRepairsCommentDetailsGateway(pointRepairsChanges);

                foreach (PointRepairsTDS.CommentDetailsRow row in (PointRepairsTDS.CommentDetailsDataTable)pointRepairsChanges.CommentDetails)
                {
                    // Insert new comment
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        int workId = row.WorkID;
                        int refId = row.RefID;
                        int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID;

                        WorkComments workComments = new WorkComments(null);
                        workComments.InsertDirect(workId, refId, row.Type, row.Subject, row.UserID, row.DateTime_, row.Comment, libraryFilesId, row.Deleted, row.COMPANY_ID, row.WorkType);
                    }

                    // Update comment
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        int refId = row.RefID;
                        int originalCompanyId = companyId;
                        string type = row.Type;
                        int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID;
                        string workType = row.WorkType;

                        // Original values
                        string originalSubject = pointRepairsCommentDetailsGateway.GetSubjectOriginal(workId, refId);
                        int originalUserId = pointRepairsCommentDetailsGateway.GetUserIdOriginal(workId, refId);
                        DateTime originalDateTime_ = pointRepairsCommentDetailsGateway.GetDateTime_Original(workId, refId);
                        string originalComment = pointRepairsCommentDetailsGateway.GetCommentOriginal(workId, refId);
                        bool originalDeleted = pointRepairsCommentDetailsGateway.GetDeletedOriginal(workId, refId);

                        // New values
                        string newSubject = pointRepairsCommentDetailsGateway.GetSubject(workId, refId);
                        string newComment = pointRepairsCommentDetailsGateway.GetComment(workId, refId);

                        WorkComments workComments = new WorkComments(null);
                        workComments.UpdateDirect(workId, refId, type, originalSubject, originalUserId, originalDateTime_, originalComment, libraryFilesId, originalDeleted, originalCompanyId, workType,  workId, refId, type, newSubject, originalUserId, originalDateTime_, newComment, libraryFilesId, originalDeleted, companyId, workType);
                    }

                    // Delete comment
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        int workId = row.WorkID;
                        int refId = row.RefID;

                        WorkComments workComments = new WorkComments(null);
                        workComments.DeleteDirect(workId, refId, row.COMPANY_ID);
                    }
                }
            }
        }