Guest User

Untitled

a guest
Jan 27th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. routes.MapRoute(
  2. name: "Fantasy League Matchups",
  3. url: "Fantasy/{leagueID}/{leagueSlug}/Matchups/{round}",
  4. defaults: new { controller = "Fantasy", action = "Matchups", leagueSlug = UrlParameter.Optional, round = UrlParameter.Optional },
  5. constraints: new { leagueID = @"d+" }
  6. );
  7.  
  8. routes.MapRoute(
  9. name: "Fantasy League Settings",
  10. url: "Fantasy/{leagueID}/{leagueSlug}/Settings",
  11. defaults: new { controller = "Fantasy", action = "Settings", leagueSlug = UrlParameter.Optional },
  12. constraints: new { leagueID = @"d+" }
  13. );
  14.  
  15. // GET: /Fantasy/{leagueID}/{leagueSlug}/Matchups/{round}
  16. public ActionResult Matchups(int leagueID, string leagueSlug = null, int round = -1) {
  17. var fantasyLeague = DataContext.FantasyLeagues.Where(l => l.ID == leagueID).FirstOrDefault();
  18. if (fantasyLeague != null) {
  19. if (string.IsNullOrEmpty(leagueSlug) || round == -1) {
  20. return RedirectToActionPermanent("Matchups", "Fantasy", new { leagueID = leagueID, leagueSlug = fantasyLeague.Slug, round = fantasyLeague.CurrentRound });
  21. }
  22.  
  23. var userInLeague = User != null && User.Identity != null && fantasyLeague.FantasyTeams.Any(t => t.Owner.UserName == User.Identity.Name);
  24. var fantasyMatches = fantasyLeague.FantasyMatches.Where(fm => fm.Round == round).ToList();
  25.  
  26. return View("Matchups", new FantasyMatchupsViewModel {
  27. FantasyLeague = fantasyLeague,
  28. FantasyMatches = fantasyMatches,
  29. Round = round,
  30. UserInLeague = userInLeague
  31. });
  32. }
  33. return RedirectToAction("Index");
  34. }
  35.  
  36. // GET: /Fantasy/{leagueID}/{leagueSlug}/Settings
  37. public ActionResult Settings(int leagueID, string leagueSlug = null) {
  38. var fantasyLeague = DataContext.FantasyLeagues.Where(l => l.ID == leagueID).FirstOrDefault();
  39. if (fantasyLeague != null) {
  40. if (string.IsNullOrEmpty(leagueSlug)) {
  41. return RedirectToActionPermanent("Settings", "Fantasy", new { leagueID = leagueID, leagueSlug = fantasyLeague.Slug });
  42. }
  43.  
  44. var userOwnsLeague = User != null && User.Identity != null && fantasyLeague.Commissioner.UserName == User.Identity.Name;
  45.  
  46. return View("Settings", new FantasySettingsViewModel {
  47. FantasyLeague = fantasyLeague,
  48. UserOwnsLeague = userOwnsLeague,
  49. Name = fantasyLeague.Name,
  50. MaxPlayers = fantasyLeague.MaxPlayers,
  51. LockoutPeriod = fantasyLeague.LockoutPeriod,
  52. PasswordProtected = fantasyLeague.PasswordProtected,
  53. Password = fantasyLeague.Password
  54. });
  55. }
  56. return RedirectToAction("Index");
  57. }
Add Comment
Please, Sign In to add comment