public async Task <ActionResult <RegistrationResult> > UpdateFileNoteContent(string fileId, string noteId, Note note) { var existing_note = (await messagingClient.Send(new EvacuationFileNotesQuery { FileId = fileId, NoteId = noteId })).Notes.SingleOrDefault(); if (existing_note == null) { return(NotFound()); } if (!UserCanEditNote(mapper.Map <Note>(existing_note))) { return(BadRequest(new ProblemDetails { Detail = "The note may be edited only by the user who created it withing a 24 hour period." })); } existing_note.Content = note.Content; var cmd = new SaveEvacuationFileNoteCommand { Note = mapper.Map <ESS.Shared.Contracts.Submissions.Note>(existing_note), FileId = fileId }; var id = await messagingClient.Send(cmd); return(Ok(new EvacuationFileNotesResult { Id = id })); }
private bool UserCanEditNote(Note note) => !string.IsNullOrEmpty(note.CreatingTeamMemberId) && note.CreatingTeamMemberId.Equals(currentUserId) && note.AddedOn >= DateTime.UtcNow.AddHours(-24);
public async Task <ActionResult <RegistrationResult> > CreateFileNote(string fileId, Note note) { var cmd = new SaveEvacuationFileNoteCommand { Note = mapper.Map <ESS.Shared.Contracts.Submissions.Note>(note), FileId = fileId }; cmd.Note.CreatedBy = new ESS.Shared.Contracts.Submissions.TeamMember { Id = currentUserId }; var id = await messagingClient.Send(cmd); return(Ok(new EvacuationFileNotesResult { Id = id })); }