public ActionResult SavePlayerToExistingList(string PlayerId, string watchListName)
        {
            string           name = watchListName;
            FFLToolEntities2 ORM  = new FFLToolEntities2();

            tblWatchlist watchlist = new tblWatchlist();

            watchlist.PlayerId      = Convert.ToInt32(PlayerId);
            watchlist.WatchlistName = watchListName.Trim();

            //need to error handle gracefully
            watchlist.WatchlistId = (from W in ORM.tblWatchlists
                                     where W.WatchlistName == watchListName.Trim()
                                     select W.WatchlistId).Distinct().Single();

            try
            {
                ORM.tblWatchlists.Add(watchlist);
                ORM.SaveChanges();
            }
            catch
            {
                return(RedirectToAction("ShowAllPlayers", new { watchListName = name }));
            }


            return(RedirectToAction("ShowAllPlayers", new { watchListName = name }));
        }
        public ActionResult SavePlayerToNewList(string PlayerId, string watchListName)
        {
            FFLToolEntities2 ORM = new FFLToolEntities2();

            string name          = watchListName;
            string userId        = User.Identity.GetUserId();
            string currWatchList = (from UW in ORM.tblUserWatchlists
                                    where UW.UserId == userId
                                    select UW.WatchlistId).Max().ToString();

            tblWatchlist watchList = new tblWatchlist();

            watchList.WatchlistId   = Convert.ToInt64(currWatchList);
            watchList.PlayerId      = Convert.ToInt32(PlayerId);
            watchList.WatchlistName = watchListName;

            try
            {
                ORM.tblWatchlists.Add(watchList);
                ORM.SaveChanges();
            }
            catch
            {
                return(RedirectToAction("ShowAllPlayers", new { watchListName = name }));
            }

            return(RedirectToAction("ShowAllPlayers", new { watchListName = name }));
        }
        public ActionResult DeleteWatchList(string watchlistId, string watchListName)
        {
            long             ID  = Int64.Parse(watchlistId);
            FFLToolEntities2 ORM = new FFLToolEntities2();

            ORM.tblUserWatchlists.Remove(ORM.tblUserWatchlists.Find(ID, User.Identity.GetUserId()));

            ORM.SaveChanges();

            string name = watchListName;

            return(RedirectToAction("WatchListManagement", new { watchListName = name }));
        }
        public ActionResult DropPlayer(string watchlistId, string playerId)
        {
            FFLToolEntities2 ORM = new FFLToolEntities2();

            tblWatchlist watchlist = ORM.tblWatchlists.Find(Convert.ToInt64(watchlistId), Convert.ToInt32(playerId));

            ORM.tblWatchlists.Remove(watchlist);
            ORM.SaveChanges();

            JObject delPlayerJSON = ApiRequestHistorical("current", "?player=" + playerId);
            string  delPlayer     = (string)delPlayerJSON["cumulativeplayerstats"]["playerstatsentry"][0]["player"]["FirstName"] + " " + (string)delPlayerJSON["cumulativeplayerstats"]["playerstatsentry"][0]["player"]["LastName"];

            return(RedirectToAction("WatchList", new
            {
                WatchlistId = watchlist.WatchlistId.ToString(),
                WatchlistName = watchlist.WatchlistName,
                DeletedPlayer = delPlayer
            }));
        }
        public ActionResult NewWatchlist()
        {
            string userId = User.Identity.GetUserId();

            if (userId == null)
            {
                return(View("../Account/Login"));
            }

            FFLToolEntities2 ORM = new FFLToolEntities2();

            tblUserWatchlist watchList = new tblUserWatchlist();

            userId = User.Identity.GetUserId();

            watchList.UserId = userId;
            ORM.tblUserWatchlists.Add(watchList);
            ORM.SaveChanges();

            return(RedirectToAction("ShowAllPlayers"));
        }