public ActionResult Create(string Redirect, string Src, DateTime?Expires) { try { // TODO: Add insert logic here if (User != null) { user = _usersRepo.GetById(User.Identity.GetUserId()); } Url newUrl = new Url { Redirect = Redirect, Src = Src, CreatedOn = DateTime.Now, Expires = Expires, UserId = user.Id, Username = _usersRepo.GetUsername(user.Id) }; if (_repo.needLastId) { newUrl.Id = _repo.LastId + 1; } _repo.Add(newUrl); TempData["Success"] = "Short Url has been created"; return(RedirectToAction("List")); } catch { TempData["Error"] = "There was an error saving your new Url"; return(View("List")); } }
public ProfissionalXUrl Save(ProfissionalXUrl entity) { try { switch (entity.ID) { case 0: entity.DataCriacao = DateTime.UtcNow; entity.DataEdicao = DateTime.UtcNow; entity.Ativo = true; entity.ID = _repository.Add(entity); break; default: entity = Update(entity); break; } return(entity); } catch (Exception e) { throw new Exception("Não foi possível completar a operação.", e); } }
public ActionResult ShortenUrl(string originalUrl) { var repo = new UrlRepository(Properties.Settings.Default.ConStr); var url = repo.GetUrl(User.Identity.Name, originalUrl); if (url == null) { var userRepo = new UserRepository(Properties.Settings.Default.ConStr); var user = userRepo.GetByEmail(User.Identity.Name); var shortId = ShortId.Generate(true, false); url = new Url { OriginalUrl = originalUrl, ShortenedHash = shortId, UserId = user.Id }; repo.Add(url); } return(Json(new { shortUrl = GetFullUrl(url.ShortenedHash) })); }