Ejemplo n.º 1
0
 public void CreateShortening(Shortening shortening)
 {
     if (String.IsNullOrEmpty(shortening.Slug) ||
         String.IsNullOrEmpty(shortening.Link))
     {
         throw new ArgumentException(nameof(shortening));
     }
     _context.Add(shortening);
     _context.SaveChanges();
 }
Ejemplo n.º 2
0
        public UrlModel Create(UrlModel model)
        {
            if (!Uri.TryCreate(model.LongUrl, UriKind.Absolute, out Uri result))
            {
                return(null);
            }

            var item = new UrlEntity
            {
                LongUrl          = model.LongUrl,
                validationString = new Random().Next().ToString(),
                CreationDate     = DateTime.Now
            };

            _dbContext.Links.Add(item);
            _dbContext.SaveChanges();

            // Add to returned model "token" for delete link
            model.deleteToken = CreateDeleteToken(item);
            model.ShortPath   = WebEncoders.Base64UrlEncode(BitConverter.GetBytes(item.Id));

            return(model);
        }
Ejemplo n.º 3
0
 public bool SaveChanges(ShortenerDbContext context)
 {
     return(context.SaveChanges() >= 0);
 }