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 })); }
public async Task <ActionResult <RegistrationResult> > SetFileNoteHiddenStatus(string fileId, string noteId, bool isHidden) { var existing_note = (await messagingClient.Send(new EvacuationFileNotesQuery { FileId = fileId, NoteId = noteId })).Notes.SingleOrDefault(); if (existing_note == null) { return(NotFound()); } if (!UserCanHideNote()) { return(BadRequest(new ProblemDetails { Detail = "You do not have sufficient permissions to edit a note's hidden status." })); } existing_note.IsHidden = isHidden; 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 })); }
public async Task <string> Handle(SaveEvacuationFileNoteCommand cmd) { if (string.IsNullOrEmpty(cmd.FileId)) { throw new ArgumentNullException("FileId is required"); } var note = mapper.Map <Resources.Cases.Note>(cmd.Note); var id = (await caseRepository.ManageCase(new SaveEvacuationFileNote { FileId = cmd.FileId, Note = note })).Id; return(id); }
public async Task <ActionResult <RegistrationResult> > CreateFileNote(string fileId, Note note) { var cmd = new SaveEvacuationFileNoteCommand { Note = mapper.Map <EMBC.ESS.Shared.Contracts.Events.Note>(note), FileId = fileId }; cmd.Note.CreatedBy = new EMBC.ESS.Shared.Contracts.Events.TeamMember { Id = currentUserId }; var id = await messagingClient.Send(cmd); return(Ok(new EvacuationFileNotesResult { Id = id })); }
public async Task <string> Handle(SaveEvacuationFileNoteCommand cmd) { if (string.IsNullOrEmpty(cmd.FileId)) { throw new ArgumentNullException("FileId is required"); } if (!string.IsNullOrEmpty(cmd.Note.Id)) { var file = (await caseRepository.QueryCase(new Resources.Cases.EvacuationFilesQuery { FileId = cmd.FileId, })).Items.Cast <Resources.Cases.Evacuations.EvacuationFile>().SingleOrDefault(); if (file == null) { throw new NotFoundException($"Evacuation File {cmd.FileId} not found", cmd.FileId); } var noteToUpdate = file.Notes.Where(n => n.Id == cmd.Note.Id).SingleOrDefault(); if (noteToUpdate == null) { throw new NotFoundException($"Evacuation File Note {cmd.Note.Id} not found", cmd.Note.Id); } if (!noteToUpdate.CreatingTeamMemberId.Equals(cmd.Note.CreatedBy.Id, StringComparison.Ordinal) || noteToUpdate.AddedOn < DateTime.UtcNow.AddHours(-24)) { throw new BusinessLogicException($"The note may be edited only by the user who created it withing a 24 hour period."); } } var note = mapper.Map <Resources.Cases.Evacuations.Note>(cmd.Note); var id = (await caseRepository.ManageCase(new SaveEvacuationFileNote { FileId = cmd.FileId, Note = note })).Id; return(id); }