public IHttpActionResult GetTryScorersbyTeam(string team)
        {
            var players = from p in db.Players
                          select p;

            InternationalTeam teamValue = (InternationalTeam)Enum.Parse(typeof(InternationalTeam), team);

            if (Enum.IsDefined(typeof(InternationalTeam), teamValue) | teamValue.ToString().Contains(","))
            {
                players = db.Players.Where(x => x.InternationalTeam.ToString().ToUpper() == teamValue.ToString().ToUpper()).Where(x => x.TriesScored >= 1);
            }
            return(Ok(players));
        }
Exemple #2
0
        // GET: Players

        public ActionResult Index(string searchString, string option)
        {
            var players = from p in db.Players
                          select p;

            if (!String.IsNullOrEmpty(searchString) & option == "Name")
            {
                players = players.Where(x => x.Name.Contains(searchString));
                return(View(players));
            }

            else if (!String.IsNullOrEmpty(searchString) & option == "Team")
            {
                try
                {
                    InternationalTeam teamValue = (InternationalTeam)Enum.Parse(typeof(InternationalTeam), searchString);
                    if (Enum.IsDefined(typeof(InternationalTeam), teamValue) | teamValue.ToString().Contains(","))
                    {
                        players = players.Where(x => x.InternationalTeam.ToString().ToUpper() == teamValue.ToString().ToUpper());
                    }
                    return(View(players.OrderBy(x => x.Name)));
                }
                catch (ArgumentException)
                {
                    return(new HttpStatusCodeResult(404));
                }
            }
            else if (!String.IsNullOrEmpty(searchString) & option == "Position")
            {
                try
                {
                    Position positionValue = (Position)Enum.Parse(typeof(Position), searchString);
                    if (Enum.IsDefined(typeof(Position), positionValue) | positionValue.ToString().Contains(","))
                    {
                        players = players.Where(x => x.Position.ToString().ToUpper() == positionValue.ToString().ToUpper());
                    }
                    return(View(players.OrderBy(x => x.Name)));
                }
                catch (ArgumentException)
                {
                    return(new HttpStatusCodeResult(404));
                }
            }


            else
            {
                return(View(db.Players.OrderBy(x => x.TriesScored).ToList()));
            }
        }