Пример #1
0
        public async Task <string> CreateShortUrlForUser(Guid userId, string url)
        {
            var isExistUser = await ShortenURlDbContext.UserUrl.FirstOrDefaultAsync(c => c.UserId == userId);

            var shortUrl    = createShortUrlService.MakeShortURL();
            var newShortUrl = new ShortUrl()
            {
                ShortUrlString = shortUrl,
                Url            = url
            };

            if (isExistUser != null)
            {
                isExistUser.ShortUrls.Add(newShortUrl);
                await ShortenURlDbContext.SaveChangesAsync();
            }
            else
            {
                var newUserUrl = new UserUrl()
                {
                    UserId = userId
                };
                newUserUrl.ShortUrls.Add(newShortUrl);
                ShortenURlDbContext.UserUrl.Add(newUserUrl);
                await ShortenURlDbContext.SaveChangesAsync();
            }
            return(shortUrl);
        }
Пример #2
0
        public async Task <string> CreateShortUrlForIp(string userIp, string url)
        {
            var isExistUserIp = await ShortenURlDbContext.UserIp.FirstOrDefaultAsync(c => c.Ip == userIp);

            var shortUrl    = createShortUrlService.MakeShortURL();
            var newShortUrl = new ShortUrl()
            {
                ShortUrlString = shortUrl,
                Url            = url
            };

            if (isExistUserIp != null)
            {
                isExistUserIp.ShortUrls.Add(newShortUrl);
                await ShortenURlDbContext.SaveChangesAsync();
            }
            else
            {
                var newUserIp = new UserIp()
                {
                    Ip = userIp,
                };
                newUserIp.ShortUrls.Add(newShortUrl);
                ShortenURlDbContext.UserIp.Add(newUserIp);
                await ShortenURlDbContext.SaveChangesAsync();
            }
            return(shortUrl);
        }
Пример #3
0
        public void Trace(string shortUrl, RequestHistory requestHistory)
        {
            shortUrl = shortUrl.Split('/')[2];
            var url = ShortenURlDbContext.ShortUrl.FirstOrDefault(c => c.ShortUrlString == shortUrl);

            if (url != null)
            {
                url.RequestHistorie.Add(requestHistory);
                ShortenURlDbContext.SaveChanges();
            }
        }
Пример #4
0
 public TraceService(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext)
 {
 }
Пример #5
0
 protected BaseService(ShortenURlDbContext shortenURlDbContext)
 {
     this.ShortenURlDbContext = shortenURlDbContext;
 }
Пример #6
0
 public ReportByCountry(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext)
 {
 }
Пример #7
0
 public ReportByBrowser(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext)
 {
 }
Пример #8
0
 public ReportByLast7Days(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext)
 {
 }
Пример #9
0
 public ReportByPlatforms(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext)
 {
 }
Пример #10
0
 public UrlService(ShortenURlDbContext shortenURlDbContext, ICreateShortURLService createShortUrlService) : base(shortenURlDbContext)
 {
     this.createShortUrlService = createShortUrlService;
 }