public async Task <IActionResult> Post([FromBody] NoteInsertDTO data, [FromHeader] Guid apiKey) { if (apiKey == Guid.Empty) { return(Unauthorized()); } if (!await _repository.APIKeyExists(apiKey)) { return(NotFound()); } var entity = _mapper.Map <Note>(data); entity.CreateDateTime = DateTimeOffset.Now; entity.APIKeyID = apiKey; await _repository.AddNote(entity); if (!await _repository.Save()) { return(StatusCode(500, "Creating note failed on save")); } var result = _mapper.Map <NoteDTO>(entity); return(CreatedAtAction( nameof(Get), new { noteid = entity.NoteID }, result)); }
public async Task <IActionResult> Post([FromBody] NoteInsertDTO data, [FromHeader] string apiKey) { if (string.IsNullOrWhiteSpace(apiKey)) { return(Unauthorized()); } if (!await _repository.APIKeyExists(apiKey)) { return(NotFound()); } var entity = _mapper.Map <Note>(data); entity.NoteID = Guid.NewGuid().ToString(); entity.CreateDateTime = DateTimeOffset.Now; entity.APIKeyID = apiKey; await _repository.AddNote(entity); var result = _mapper.Map <NoteDTO>(entity); return(StatusCode(201, result)); }