Exemplo n.º 1
0
        // GET: /<controller>/
        public IActionResult Details(string id)
        {
            if (HttpContext.Session.GetString("loggedIn") != "yes")
            {
                return(Redirect("/"));
            }

            try
            {
                Song song = dataRepository.Songs.First(s => s.SongId == id);

                if (song != null)
                {
                    // create dl transaction & add
                    DownloadTransaction downloadTrans = new DownloadTransaction()
                    {
                        SongId     = song.SongId,
                        UserId     = HttpContext.Session.GetString("userId"),
                        Expiration = DateTime.Now.AddMinutes(5.0)
                    };
                    dataRepository.AddDownloadTransaction(downloadTrans);

                    // create view model to be passed to the view
                    DownloadSongViewModel viewModel = new DownloadSongViewModel()
                    {
                        Song  = song,
                        Token = downloadTrans.Token
                    };

                    return(View(viewModel));
                }
                else
                {
                    return(View("Error"));
                }
            }
            catch (Exception)
            {
                // show error page!
                return(View("Error"));
            }
        }