public async Task <IActionResult> Update([FromBody] NoteAddUpdateDto note, string id) { if (note == null) { return(BadRequest()); } if (!await _noteService.Update(note, id)) { return(NotFound()); } return(Ok(new ApiResponse { Success = true, Message = "Updated note" })); }
public async Task <bool> Update(NoteAddUpdateDto n, string id) { try { var currentNote = await GetNoteById(id); currentNote.Update(n.ToNote(id)); await this._noteRepository.UpdateAsync(id, currentNote); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
public async Task <IActionResult> Add([FromBody] NoteAddUpdateDto note) { if (note == null) { return(BadRequest("Note is null")); } var apiResponse = new ApiResponse(); try { var id = await _noteService.Add(note); apiResponse.Success = true; apiResponse.Message = "Added note successfully"; return(Created($"/notes/{id}", apiResponse)); } catch { apiResponse.Message = "Some error occurred while adding the note"; apiResponse.Success = false; return(StatusCode(500, apiResponse)); } }
public async Task <string> Add(NoteAddUpdateDto n) { var note = await _noteRepository.AddAsync(n.NewNote()); return(note.Id); }