// 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")); } }
public IActionResult Download(string id) { if (HttpContext.Session.GetString("loggedIn") != "yes") { return(Redirect("/")); } try { DownloadTransaction downloadTrans = dataRepository.DownloadTransaction.First(d => d.Token == id); if (downloadTrans == null) { return(View("Error")); } Song song = dataRepository.Songs.First(s => s.SongId == downloadTrans.SongId); // check expiration if (DateTime.Now > downloadTrans.Expiration) { ViewBag.Expired = true; } else { ViewBag.Expired = false; } // create view model to be passed to the view DownloadSongViewModel viewModel = new DownloadSongViewModel() { Song = song, Token = downloadTrans.Token }; return(View(viewModel)); } catch (Exception) { return(View("Error")); } }