Exemplo n.º 1
0
        public ActionResult AddLink(LinkModel link)
        {
            LinkEntity linkEntity      = (LinkEntity)link;
            LinkEntity addedLinkEntity = _linksRepository.Add(linkEntity);

            return(Json(addedLinkEntity));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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" }));
        }