public ActionResult AddLink(LinkModel link) { LinkEntity linkEntity = (LinkEntity)link; LinkEntity addedLinkEntity = _linksRepository.Add(linkEntity); return(Json(addedLinkEntity)); }
public async Task <int> Handle(CreateLinkCommand request, CancellationToken cancellationToken) { if (!request.Url.StartsWith("http://") && !request.Url.StartsWith("https://")) { request.Url = $"http://{request.Url}"; } var link = new Link(request.Url, request.Description, request.User); await _linksRepository.Add(link); return(link.Id); }
public IActionResult Create([FromBody] CreateLink command) { if (!(command.Link.IsValidHttpLink() || command.Link.IsValidHttpsLink())) { return(BadRequest()); } Link linkInformation = new Link { OriginalLink = command.Link, Visitors = 0 }; _repository.Add(linkInformation); linkInformation.Hash = _hashAlgorithm.Hash(linkInformation.Id); _repository.Update(linkInformation); return(Ok(new { message = "Created" })); }