public async Task <ActionResult <Link> > CreateLink(LinkToCreateDto link) { if (link == null) { throw new ArgumentNullException(nameof(link)); } var linkEntity = _mapper.Map <Link>(link); _repo.AddLink(linkEntity); await _repo.SaveChangesAsync(); var linkToReturn = _mapper.Map <LinkDto>(linkEntity); return(CreatedAtAction( "GetLink", new { id = linkToReturn.Id }, linkToReturn)); }
public async Task <IActionResult> UpdateLink(Guid id, LinkToUpdateDto link) { var linkEntity = await _linksRepo.GetLinkAsync(id); if (linkEntity == null) { return(NotFound()); } _mapper.Map(link, linkEntity); _linksRepo.UpdateLink(linkEntity); // It might be more proper to handle this error in the repository try { await _linksRepo.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) when(!_linksRepo.LinkExists(id)) { return(NotFound()); } return(NoContent()); }