public void UpdateURLClicks(URLClick URLClicks) { var URLClicksToBeUpdated = _context.URLClicks.FirstOrDefault(u => u.Id == URLClicks.Id); URLClicksToBeUpdated.NumberOfClicks += 1; _context.SaveChanges(); }
public ActionResult Index() { string queryParameter; var URLClickObject = new URLClick(); var requestedUrl = Request.Url.AbsoluteUri.Split('?'); if (requestedUrl.Length > 1) { queryParameter = requestedUrl[1]; URLClickObject = _homeService.GetURL(queryParameter); _homeService.UpdateURLClicks(URLClickObject); return(Redirect(URLClickObject.URL.OriginalURL)); } return(View()); }
public URL LoadUrlToDatabase(URL urlToBeSaved) { _context.URLs.Add(urlToBeSaved); _context.SaveChanges(); var URLClickObject = new URLClick { ShortURLNumber = urlToBeSaved.ShortURL.Split('?')[1], URLId = urlToBeSaved.Id, NumberOfClicks = 0 }; _context.URLClicks.Add(URLClickObject); _context.SaveChanges(); return(urlToBeSaved); }