Esempio n. 1
0
        private async Task <bool> AddUrlToDb(URL url)
        {
            var urlInDb = await dataContext.Urls
                          .FirstOrDefaultAsync(oldUrl => oldUrl.FullUrl == url.FullUrl);

            if (urlInDb != null)
            {
                return(false);
            }

            var hashids = new Hashids($"{url.FullUrl}");
            var id      = hashids.Encode(1, 2, 3, 4, 5);

            url.ShortUrl = "https://voronintask.ru/go?id=" + id;
            dataContext.Add(url);
            await dataContext.SaveChangesAsync();

            return(true);
        }
Esempio n. 2
0
        private async Task <bool> UpdateNumberOfTransitions(URL url)
        {
            try
            {
                url.NumberOfTransitions++;
                await dataContext.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(!dataContext.Urls.Any(e => e.ID == url.ID));
            }

            return(true);
        }