public ShortLinkModel SaveShortLink(ShortLink shortLink, string url) { ShortLinkModel shortLinkModel = ShortLinkModel.FromEntity(shortLink, url); _shortLinks.Add(shortLinkModel); return(shortLinkModel); }
public ShortLinkModel UpdateShortLink(ShortLink shortLink, string url) { bool success = DeleteShortLink(shortLink.Id); if (!success) { return(null); } SaveShortLink(shortLink, url); return(ShortLinkModel.FromEntity(shortLink, url)); }
public ShortLinkModel SaveShortLink(ShortLink shortLink, string url) { shortLink.Id = 0; shortLink.InsertionDate = DateTimeOffset.Now; if (string.IsNullOrWhiteSpace(shortLink.UrlKey)) { shortLink.UrlKey = StringUtils.GenRandomString(6); } var result = _context.ShortLinks.Add(shortLink); _context.SaveChanges(); return(ShortLinkModel.FromEntity(result.Entity, url)); }
public ShortLinkModel UpdateShortLink(ShortLink shortLink, string url) { ShortLink result = _context.ShortLinks.FirstOrDefault(x => x.Id == shortLink.Id); if (result == null) { return(null); } result.LongUrl = shortLink.LongUrl; result.UrlKey = shortLink.UrlKey; result.RedirectsCount = shortLink.RedirectsCount; _context.SaveChanges(); return(ShortLinkModel.FromEntity(result, url)); }
public ShortLinkModel GetShortLinkById(long linkId, string url) { ShortLink shortLink = _context.ShortLinks.FirstOrDefault(link => link.Id == linkId); return(ShortLinkModel.FromEntity(shortLink, url)); }
public IEnumerable <ShortLinkModel> GetAllShortLinks(string url) { return(_context.ShortLinks.Select(m => ShortLinkModel.FromEntity(m, url))); }
public ShortLinkModel GetShortLinkByUrlKey(string urlKey, string url) { ShortLink shortLink = _context.ShortLinks.FirstOrDefault(l => l.UrlKey == urlKey); return(shortLink == null ? null : ShortLinkModel.FromEntity(shortLink, url)); }