public int Save(ShortModel shortUrl) { _context.ShortUrls.Add(shortUrl); _context.SaveChanges(); return(shortUrl.Id); }
public string GetShort(string url) { var code = this._encodeService.Encode(url); var existUrl = this.GetUrl(code); if (string.IsNullOrEmpty(existUrl)) { using (var context = new UrlDBContext()) { var newUrl = new Url() { UrlCode = code, UrlUrl = url }; context.Url.Add(newUrl); context.SaveChanges(); } } return(code); }