@@ -166,6 +166,53 @@ public async Task<ActionResult<ContactResult>> GetContactById(string contactId)
166166 return result ;
167167 }
168168
169+ /// <summary>
170+ /// Gets all the Notes for a Contact by the contact id
171+ /// </summary>
172+ /// <returns></returns>
173+ [ HttpGet ( "GetContactNotesByContactId" ) ]
174+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
175+ [ Authorize ( Policy = ResgridResources . Contacts_View ) ]
176+ public async Task < ActionResult < ContactNotesResult > > GetContactNotesByContactId ( string contactId )
177+ {
178+ var result = new ContactNotesResult ( ) ;
179+
180+ var contact = await _contactsService . GetContactByIdAsync ( contactId ) ;
181+ var department = await _departmentsService . GetDepartmentByIdAsync ( DepartmentId ) ;
182+
183+ if ( contact != null && contact . DepartmentId == DepartmentId )
184+ {
185+ var contactNotes = await _contactsService . GetContactNotesByContactIdAsync ( contactId , Int32 . MaxValue , false ) ;
186+
187+ foreach ( var contactNote in contactNotes )
188+ {
189+ var addedOnPerson = await _userProfileService . GetProfileByUserIdAsync ( contactNote . AddedByUserId ) ;
190+ UserProfile editedPerson = null ;
191+
192+ if ( ! String . IsNullOrWhiteSpace ( contactNote . EditedByUserId ) )
193+ editedPerson = await _userProfileService . GetProfileByUserIdAsync ( contactNote . EditedByUserId ) ;
194+
195+ ContactNoteType noteType = null ;
196+ if ( ! String . IsNullOrWhiteSpace ( contactNote . ContactNoteTypeId ) )
197+ noteType = await _contactsService . GetContactNoteTypeByIdAsync ( contactNote . ContactNoteTypeId ) ;
198+
199+ result . Data . Add ( ConvertContactNoteData ( contactNote , noteType , department , addedOnPerson , editedPerson ) ) ;
200+ }
201+
202+ result . PageSize = contactNotes . Count ;
203+ result . Status = ResponseHelper . Success ;
204+ }
205+ else
206+ {
207+ result . PageSize = 0 ;
208+ result . Status = ResponseHelper . NotFound ;
209+ }
210+
211+ ResponseHelper . PopulateV4ResponseData ( result ) ;
212+
213+ return result ;
214+ }
215+
169216 public static ContactCategoryResultData ConvertCategoryData ( ContactCategory category , Department department , UserProfile addedProfile , UserProfile editedProfile )
170217 {
171218 var cat = new ContactCategoryResultData ( ) ;
@@ -246,5 +293,44 @@ public static ContactResultData ConvertContactData(Contact contact, Department d
246293
247294 return con ;
248295 }
296+
297+ public static ContactNoteResultData ConvertContactNoteData ( ContactNote contactNote , ContactNoteType contactNoteType , Department department , UserProfile addedProfile , UserProfile editedProfile )
298+ {
299+ var conNote = new ContactNoteResultData ( ) ;
300+ conNote . ContactId = contactNote . ContactId ;
301+ conNote . ContactNoteId = contactNote . ContactNoteId ;
302+ conNote . ContactNoteTypeId = contactNote . ContactNoteTypeId ;
303+ conNote . Note = contactNote . Note ;
304+ conNote . ShouldAlert = contactNote . ShouldAlert ;
305+ conNote . Visibility = contactNote . Visibility ;
306+
307+ if ( contactNoteType != null )
308+ {
309+ conNote . ContactNoteTypeId = contactNoteType . ContactNoteTypeId ;
310+ conNote . NoteType = contactNoteType . Name ;
311+ }
312+
313+ if ( contactNote . ExpiresOn . HasValue )
314+ {
315+ conNote . ExpiresOnUtc = contactNote . ExpiresOn ;
316+ conNote . ExpiresOn = contactNote . ExpiresOn . Value . FormatForDepartment ( department ) ;
317+ }
318+
319+ conNote . IsDeleted = contactNote . IsDeleted ;
320+ conNote . AddedOnUtc = contactNote . AddedOn ;
321+ conNote . AddedOn = contactNote . AddedOn . FormatForDepartment ( department ) ;
322+ conNote . AddedByUserId = contactNote . AddedByUserId ;
323+ conNote . AddedByName = addedProfile . FullName . AsFirstNameLastName ;
324+
325+ if ( contactNote . EditedOn . HasValue )
326+ {
327+ conNote . EditedOnUtc = contactNote . EditedOn ;
328+ conNote . EditedOn = contactNote . EditedOn . Value . FormatForDepartment ( department ) ;
329+ conNote . EditedByUserId = contactNote . EditedByUserId ;
330+ conNote . EditedByName = editedProfile . FullName . AsFirstNameLastName ;
331+ }
332+
333+ return conNote ;
334+ }
249335 }
250336}
0 commit comments