public void CreateShortening(Shortening shortening) { if (String.IsNullOrEmpty(shortening.Slug) || String.IsNullOrEmpty(shortening.Link)) { throw new ArgumentException(nameof(shortening)); } _context.Add(shortening); _context.SaveChanges(); }
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); }
public bool SaveChanges(ShortenerDbContext context) { return(context.SaveChanges() >= 0); }