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); }
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); }
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(); } }
public TraceService(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext) { }
protected BaseService(ShortenURlDbContext shortenURlDbContext) { this.ShortenURlDbContext = shortenURlDbContext; }
public ReportByCountry(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext) { }
public ReportByBrowser(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext) { }
public ReportByLast7Days(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext) { }
public ReportByPlatforms(ShortenURlDbContext shortenURlDbContext) : base(shortenURlDbContext) { }
public UrlService(ShortenURlDbContext shortenURlDbContext, ICreateShortURLService createShortUrlService) : base(shortenURlDbContext) { this.createShortUrlService = createShortUrlService; }