public IActionResult Generation(GenerationViewModel model) { var context = HttpContext; if (ModelState.IsValid) { string shortUrl = GetRandomUrl(); while (_db.UrlTable.Any(ur => ur.ShortUrl == shortUrl)) { shortUrl = GetRandomUrl(); } var url = new Urls(); url.Url = model.Url; url.NumOfClick = 0; url.ShortUrl = shortUrl; if (User.Identity.IsAuthenticated) { url.Username = User.Identity.Name; _db.UrlTable.Add(url); _db.SaveChanges(); } else { url.Username = null; _urlService.AddUrl(url, context); } return(View("UrlReturn", "https://" + HttpContext.Request.Host + "/" + shortUrl)); } return(View()); }
public IActionResult Save(string url, string content) { try { _service.AddUrl(new UrlDTO() { Url = url, Content = content }); return(PartialView("UrlList", ConvertDTO(_service.GetUrls()))); } catch (ValidationException exc) { return(View("Error", exc.Message)); } }