Exemple #1
0
        public async Task <IActionResult> Rating(string query)
        {
            int linkId = _urlGenerator.Decode(query);
            var link   = await _dbContext.Widgets.FindAsync(linkId);

            if (link == null)
            {
                return(NotFound(new { query }));
            }

            return(View(new WidgetViewModel()
            {
                Id = link.Id, Yandex = link.Yandex, Google = link.Google, TwoGIS = link.TwoGIS
            }));
        }
Exemple #2
0
        //[Route("{shortLink}")]
        public async Task <IActionResult> Link(string shortLink)
        {
            int linkId = _urlGenerator.Decode(shortLink);
            var link   = await _dbContext.Widgets.FindAsync(linkId);

            if (link == null)
            {
                return(NotFound(new { shortLink }));
            }

            try
            {
                link.CountConversion += 1;
                _dbContext.Widgets.Update(link);
                await _dbContext.SaveChangesAsync();

                return(RedirectToAction("Rating", "Widgets", new { link.Link }));
            }
            catch
            {
                return(RedirectToAction(nameof(HomeController.Index), this.UrlName <HomeController>()));
            }
        }