예제 #1
0
        public int Save(ShortModel shortUrl)
        {
            _context.ShortUrls.Add(shortUrl);
            _context.SaveChanges();

            return(shortUrl.Id);
        }
예제 #2
0
        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);
        }