public async Task <Response <Note> > Create(Note note) { try { var createdNote = await _context.Notes.AddAsync(note); await _context.SaveChangesAsync(); return(ResponseFactory.Success(createdNote.Entity)); } catch (Exception exception) { _logger.LogError("Failed to create note", exception); return(ResponseFactory.Fail <Note>("Failed to create note")); } }
public async Task <Response <bool> > Delete(int noteId) { try { var noteToRemove = await _context.Notes.FindAsync(noteId); _context.Notes.Remove(noteToRemove); await _context.SaveChangesAsync(); return(ResponseFactory.Success(true)); } catch (Exception exception) { _logger.LogError($"Failed to delete note with id: {noteId}", exception); return(ResponseFactory.Fail <bool>($"Failed to delete note with id: {noteId}")); } }
public async Task <Response <Note> > Update(int noteId, Note note) { try { var noteToUpdate = await _context.Notes.FindAsync(noteId); noteToUpdate.Text = note.Text; _context.Notes.Update(noteToUpdate); await _context.SaveChangesAsync(); return(ResponseFactory.Success(noteToUpdate)); } catch (Exception exception) { _logger.LogError($"Failed to update note with id: {noteId}", exception); return(ResponseFactory.Fail <Note>($"Failed to update note with id: {noteId}")); } }