public async Task <IActionResult> UpdateNote([FromBody] NoteManipulationDto noteManipulation, Guid id) { if (!await _noteService.UpdateNoteAsync(HttpContext.User.Identity?.Name, id, noteManipulation, ModelState)) { return(BadRequest(ModelState)); } return(NoContent()); }
public async Task <NoteDto> CreateNoteAsync(string userId, NoteManipulationDto noteManipulation) { var note = _mapper.Map <Note>(noteManipulation); note.UserId = userId; _repositoryManager.Note.CreateNote(note); await _repositoryManager.SaveAsync(); return(_mapper.Map <NoteDto>(note)); }
public async Task <bool> UpdateNoteAsync(string userId, Guid noteId, NoteManipulationDto noteManipulation, ModelStateDictionary modelState) { var note = await _repositoryManager.Note.GetNoteByIdAsync(userId, noteId, true); if (note == null) { _logger.Log(LogLevel.Error, "Note with such id doesn't exists!"); modelState.TryAddModelError("invalid-note-id", "Note with such id doesn't exists!"); return(false); } _mapper.Map(noteManipulation, note); await _repositoryManager.SaveAsync(); return(true); }
public async Task <IActionResult> Create([FromHeader] string apiKey, [FromBody] NoteManipulationDto noteManipulationDto) { var apiKeyRef = await _db.Collection("users").Document(apiKey).GetSnapshotAsync(); if (!apiKeyRef.Exists) { return(NotFound()); } await GetNotesReference(apiKey) .Document() .SetAsync(new { NoteTitle = noteManipulationDto.NoteTitle, NoteContent = noteManipulationDto.NoteContent, CreateDateTime = DateTimeOffset.Now.ToString(), LatestEditDateTime = (string)null }); return(StatusCode(201)); }
public async Task <IActionResult> Update([FromHeader] string apiKey, string noteid, [FromBody] NoteManipulationDto noteManipulationDto) { var apiKeyRef = await _db.Collection("users").Document(apiKey).GetSnapshotAsync(); if (!apiKeyRef.Exists) { return(NotFound()); } if (!(await GetNotesReference(apiKey).Document(apiKey).GetSnapshotAsync()).Exists) { return(NotFound()); } await GetNotesReference(apiKey) .Document(noteid) .SetAsync(new { NoteTitle = noteManipulationDto.NoteTitle, NoteContent = noteManipulationDto.NoteContent, LatestEditDateTime = DateTimeOffset.Now.ToString(), }, SetOptions.MergeAll); return(NoContent()); }
public async Task <IActionResult> CreateNote([FromBody] NoteManipulationDto noteManipulation) { var note = await _noteService.CreateNoteAsync(HttpContext.User.Identity?.Name, noteManipulation); return(CreatedAtRoute("NoteById", new { note.Id }, note)); }