Beispiel #1
0
        public async Task <ActionResult <ShortLinkDto> > CreateAsync(ShortLinkDto shortLinkDto)
        {
            if (await _skimRepository.SlugExistsAsync(shortLinkDto.Slug))
            {
                return(Conflict());
            }

            // If user provided no slug, generate a random one
            if (string.IsNullOrWhiteSpace(shortLinkDto.Slug))
            {
                for (int length = 2;; length++)
                {
                    shortLinkDto.Slug = SlugGenerator.Generate(length);
                    if (!await _skimRepository.SlugExistsAsync(shortLinkDto.Slug))
                    {
                        break;
                    }
                }
            }

            await _skimRepository.CreateShortLinkAsync(_mapper.Map <ShortLink>(shortLinkDto));

            return(CreatedAtAction(actionName: nameof(GetBySlugAsync),
                                   routeValues: new { slug = shortLinkDto.Slug },
                                   value: shortLinkDto));
        }
Beispiel #2
0
        public LinkDto GetLinks(ShortLinkDto shortLinkDto)
        {
            ShortLinkEntity entity = _repository.GetLinks(shortLinkDto.shortlink);

            return(new LinkDto()
            {
                deeplink = entity.Deeplink, webUrl = entity.WebUrl
            });
        }
Beispiel #3
0
 public LinkDto Get([FromBody] ShortLinkDto shortlink)
 {
     return(_converter.GetLinks(shortlink));
 }