Example #1
0
        public async Task <Url> Add(string sourceUrl, string tail, string desc)
        {
            sourceUrl = sourceUrl.Trim();
            tail      = string.IsNullOrWhiteSpace(tail) ? await CreateTail() : tail.Trim();

            desc = string.IsNullOrWhiteSpace(desc) ? $"Entry added at {DateTime.UtcNow} UTC" : desc.Trim();

            var newUrl = new Url(sourceUrl, tail, desc);

            if (await _urlRepository.ExistAsync(newUrl))
            {
                throw new ConflictException("This Short URL already exist.");
            }

            return(await _urlRepository.Save(newUrl));
        }