/// <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 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);
                    }
                }
            }
        }