public async Task <IActionResult> UpdateTag(Guid id, TagToUpdateDto tag) { var tagEntity = await _tagsRepo.GetTagAsync(id); if (tagEntity == null) { return(NotFound()); } _mapper.Map(tag, tagEntity); _tagsRepo.UpdateTag(tagEntity); // It might be more proper to handle this error in the repository try { await _tagsRepo.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!_tagsRepo.TagExists(id)) { return(NotFound()); } return(NoContent()); }
public async Task <ActionResult <Tag> > CreateLink(TagToCreateDto tag) { if (tag == null) { throw new ArgumentNullException(nameof(tag)); } var tagEntity = _mapper.Map <Tag>(tag); _repo.AddTag(tagEntity); await _repo.SaveChangesAsync(); var linkToReturn = _mapper.Map <LinkDto>(tagEntity); return(CreatedAtAction( "GetLink", new { id = linkToReturn.Id }, linkToReturn)); }