public static SessionNoteDTO ToSessionNoteDTO(SessionNote note) { return(new SessionNoteDTO { Id = note.Id, Title = note.Title, UserId = note.UserId, SessionId = note.SessionId, UserName = note.User.Name, UserNameEn = note.User.NameEn }); }
public async Task <ActionResult <SessionNote> > PostSessionNote([FromBody] SessionNote sessionNote) { sessionNote.UserId = User.FindFirstValue(ClaimTypes.NameIdentifier); if (sessionNote.SessionNoteTitle == "") { sessionNote.SessionNoteTitle = "New Note"; } try { Campaign selectedCampaign = await _context.Campaigns.FindAsync(sessionNote.CampaignID); if (selectedCampaign.UserId == sessionNote.UserId) { bool selectedNoteCheck = _context.SessionNotes.Where(x => x.SelectedSessionNote == true).Any(); if (selectedNoteCheck) { List <SessionNote> selectedNotes = _context.SessionNotes.Where(x => x.UserId == sessionNote.UserId && x.SelectedSessionNote == true).ToList(); foreach (SessionNote selectedNote in selectedNotes) { selectedNote.SelectedSessionNote = false; } sessionNote.SelectedSessionNote = true; } else { sessionNote.SelectedSessionNote = true; } await _context.SessionNotes.AddAsync(sessionNote); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSessionNote", new { id = sessionNote.SessionNoteID }, sessionNote)); } else { return(BadRequest()); } } catch (Exception exc) { Console.WriteLine(exc); return(BadRequest()); } }
public async Task <ActionResult <SessionNote> > DeleteSessionNote(int id) { SessionNote sessionNote = await _context.SessionNotes.FindAsync(id); if (sessionNote == null || sessionNote.UserId != User.FindFirstValue(ClaimTypes.NameIdentifier)) { return(NotFound()); } _context.SessionNotes.Remove(sessionNote); await _context.SaveChangesAsync(); return(sessionNote); }
public async Task <IActionResult> SetSelectedSessionNote(int id) { string currentUser = User.FindFirstValue(ClaimTypes.NameIdentifier); SessionNote sessionNoteToSelect = await _context.SessionNotes.FindAsync(id); if (sessionNoteToSelect.UserId == currentUser) { bool selectedNoteCheck = _context.SessionNotes.Where(x => x.SelectedSessionNote == true).Any(); //TODO: This needs to be done per campaign, not on all of the user's notes if (selectedNoteCheck) { List <SessionNote> selectedNotes = _context.SessionNotes.Where(x => x.UserId == currentUser && x.SelectedSessionNote == true && x.CampaignID == sessionNoteToSelect.CampaignID).ToList(); foreach (SessionNote selectedNote in selectedNotes) { selectedNote.SelectedSessionNote = false; } sessionNoteToSelect.SelectedSessionNote = true; } else { sessionNoteToSelect.SelectedSessionNote = true; } _context.Entry(sessionNoteToSelect).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SessionNoteExists(id)) { //_logger.AddSystemLog($"WARNING: User {requestingUser} has caused a DbUpdateConcurrencyException"); return(NotFound()); } else { throw; } } } return(NoContent()); }
private async Task <Map> LinkNewMapToNote(StringValues noteValues, Map map) { string currentUser = User.FindFirstValue(ClaimTypes.NameIdentifier); string noteIdString = noteValues.AsEnumerable().First(); bool parseNoteId = int.TryParse(noteIdString, out int noteId); if (parseNoteId) { SessionNote noteToLink = await _context.SessionNotes.FindAsync(noteId); if (noteToLink.UserId == currentUser) { map.SessionNoteID = noteToLink.SessionNoteID; } } return(map); }
public async Task <ActionResult <SessionNote> > EditSessionNote([FromBody] SessionNote sentSessionNote) { string requestingUser = User.FindFirstValue(ClaimTypes.NameIdentifier); SessionNote sessionNote = await _context.SessionNotes.FindAsync(sentSessionNote.SessionNoteID); if (requestingUser != sessionNote.UserId) { return(BadRequest()); } sessionNote.SessionNoteBody = sentSessionNote.SessionNoteBody; if (sentSessionNote.SessionNoteTitle != null) { sessionNote.SessionNoteTitle = sentSessionNote.SessionNoteTitle; } else { sessionNote.SessionNoteTitle = "New Note"; } _context.Entry(sessionNote).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SessionNoteExists(sessionNote.SessionNoteID)) { //_logController.AddSystemLog($"WARNING: User {requestingUser} has caused a DbUpdateConcurrencyException"); return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> LinkExistingMapToNote(int id) { string currentUser = User.FindFirstValue(ClaimTypes.NameIdentifier); Map mapToLink = await _context.Maps.FindAsync(id); if (currentUser != mapToLink.UserId) { return(BadRequest()); } Campaign selectedCampaign = _context.Campaigns.First(x => x.UserId == currentUser); SessionNote relatedSessionNote = _context.SessionNotes.Where(x => x.SelectedSessionNote == true).First(); mapToLink.SessionNoteID = relatedSessionNote.SessionNoteID; _context.Entry(mapToLink).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult <SessionNote> > GetSessionNoteAsync(int id) { SessionNote sessionNote = await _context.SessionNotes.FindAsync(id); return(sessionNote); }