Skip to content

MoreReadableNoteService

Implements IMoreReadableNoteService, a structurally near-identical alternative to SAIF.Services.Agencies.Notes.NoteService for agency notepad entries, but signaling authorization/validation/lookup failures by throwing the internal NoteServiceException rather than populating an IMessageContainer. It depends on IUnitOfWork for repository access and transactions, IValidationService for validation, IUserProfileService for current-user identity and role checks, and IWorkCalendarService to compute the "two work days ago" cutoff. Its static constructor registers the same AutoMapper maps as NoteService for AgencyNote/Notepad→Note and reuses AgenciesMappingHelper.CreateAgencyMap().

Purpose

  • Retrieves a single note or all notes for an agency, filtering out confidential notes unless the current user is authorized to see them.
  • Adds, appends to, edits, and deletes agency notes, throwing NoteServiceException on authorization failure, validation failure, concurrent-update conflicts, or edit-window violations instead of returning a boolean/message result.
  • Reports whether the current user can add notes or see confidential notes, and returns the available note categories.

Context

  • Namespace: SAIF.Services.Agencies.Notes
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package)

Public members

Member Signature Purpose
MoreReadableNoteService(...) public MoreReadableNoteService(IUnitOfWork unitOfWork, IValidationService validationService, IUserProfileService userProfileService, IWorkCalendarService workCalendarService) Validates all four collaborators are non-null and stores them for use by every other member.
CanUserAddNote public bool CanUserAddNote { get; } Returns whether the current user is authorized to add notes.
CanUserSeeConfidentialNotes public bool CanUserSeeConfidentialNotes { get; } Returns whether the current user holds the confidential-notes role.
GetNotes(agencyId, criteria) public IEnumerable<Note> GetNotes(long agencyId, NoteFilterCriteria criteria) Returns the agency's notes narrowed by criteria.
GetNotes(agencyId) public IEnumerable<Note> GetNotes(long agencyId) Returns all visible notes for the agency, mapped to Note contracts.
GetNote public Note GetNote(long noteId) Returns the mapped Note for noteId; throws NoteServiceException ("Error: Note could not be found.") if not found or not visible to the current user.
GetCategories public IEnumerable<Category> GetCategories() Returns the note categories scoped to the agency-note context.
AddNote public long AddNote(NoteEdit noteEdit) Verifies edit authorization and validates the edit (throwing NoteServiceException on failure), then adds the note attributed to the current user within a transaction and returns the new note ID.
DeleteExpiredNotes public void DeleteExpiredNotes() Always throws NotImplementedException; this capability is not implemented for agency notes.
DeleteNote public void DeleteNote(long noteId) Deletes the note without considering concurrency if the caller is a super-delete user or the note was created within the last two work days; throws NoteServiceException ("Error: Deleting this note is not allowed.") otherwise.
EditNote public void EditNote(long noteId, NoteEdit noteEdit) Verifies edit authorization, checks for intervening updates, enforces the edit-window rule when text changed, validates the edit, and applies the change within a transaction, throwing NoteServiceException on any failure.
AppendNote public void AppendNote(long noteId, NoteEdit noteEdit) Verifies edit authorization, checks for intervening updates, enforces the append-window rule (must be older than two work days), validates the appended text, and applies the append within a transaction, throwing NoteServiceException on any failure.
AppendPrefixTextLength public int AppendPrefixTextLength { get; } Returns the character length of the "Added by " prefix that will be inserted when appending.
EditSuffixTextLength public int EditSuffixTextLength { get; } Returns the character length of the "Updated by " suffix appended when a note's text is edited.

Behavioral notes

  • Every failure path (authorization, validation, not-found, concurrency, edit/append-window violations) throws the internal NoteServiceException rather than returning a status or populating a message container, making this type's error-handling contract distinct from NoteService in the same namespace*.
  • AddNote, EditNote, AppendNote, and DeleteNote each wrap their write in unitOfWork.Begin()/Commit(); failures raised before Commit() leave the transaction uncommitted rather than explicitly rolled back*.
  • Edit authorization (IsEditUser) is cached per-instance in the isUserAuthorizedToEditNotes nullable field after the first check*.
  • Uses a longer maximum note length (MaxNoteLength = 4000) than the sibling NoteService in this namespace, which uses 3985*.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • Services/SAIF.Services/Agencies/Notes/NoteService.cs