public async Task <Note> UpdateNote(NoteToUpdateDTO noteToUpdate) { Note note = await _noteRepo.GetFromIdAsync(noteToUpdate.noteId); note.Message = noteToUpdate.message; return(await _genericRepo.UpdateAsync(note)); }
private Note ConvertNoteToUpdateDTO(NoteToUpdateDTO noteToUpdate) { if (noteToUpdate == null) { return(null); } Note note = new Note { NoteId = noteToUpdate.noteId, Message = noteToUpdate.message }; return(note); }
public async Task <IActionResult> Post(NoteToUpdateDTO noteToUpdate) { try { noteToUpdate.message = _htmlEncoder.Encode(_javaScriptEncoder.Encode(noteToUpdate.message)); int userId = Int32.Parse(this.User.FindFirstValue(ClaimTypes.NameIdentifier)); var note = await _noteServices.GetNoteById(noteToUpdate.noteId); if (note == null) { return(StatusCode(400, "Note with id " + noteToUpdate.noteId + " was not found.")); } var portfolio = await _portfolioServices.GetPortfolioByIdAsync(note.PortfolioId); if (portfolio == null) { return(StatusCode(500, "Portfolio was not found")); } if (note.PortfolioId != portfolio.PortfolioId) { return(StatusCode(400, "Note with id " + note.NoteId + " does not belong in portfolio with id " + portfolio.PortfolioId)); } if (portfolio.UserId == userId) { await _noteServices.UpdateNote(noteToUpdate); return(StatusCode(200)); } return(StatusCode(401)); } catch { return(StatusCode(500, "Somthing went wrong while attempting to update note")); } }