コード例 #1
0
        // GET: Injury/Details/5
        public ActionResult Details(int id)
        {
            UpdateInjury ViewModel = new UpdateInjury();

            string url = "injurydata/findinjury/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                //Put data into Injury data transfer object
                InjuryDto SelectedInjury = response.Content.ReadAsAsync <InjuryDto>().Result;
                ViewModel.injury = SelectedInjury;

                //find players that are injuried by this injury
                url      = "injurydata/getplayersforinjury/" + id;
                response = client.GetAsync(url).Result;

                //Put data into Injury data transfer object
                IEnumerable <PlayerDto> SelectedPlayers = response.Content.ReadAsAsync <IEnumerable <PlayerDto> >().Result;
                ViewModel.injuriedplayers = SelectedPlayers;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
コード例 #2
0
        public ActionResult DeleteConfirm(int id)
        {
            string url = "injurydata/findinjury/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                //Put data into Injury data transfer object
                InjuryDto SelectedInjury = response.Content.ReadAsAsync <InjuryDto>().Result;
                return(View(SelectedInjury));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
コード例 #3
0
        public IHttpActionResult GetInjuries()
        {
            List <Injury>    Injuries   = db.Injuries.ToList();
            List <InjuryDto> InjuryDtos = new List <InjuryDto> {
            };

            //Here you can choose which information is exposed to the API
            foreach (var Injury in Injuries)
            {
                InjuryDto NewInjury = new InjuryDto
                {
                    InjuryID   = Injury.InjuryID,
                    InjuryName = Injury.InjuryName
                };
                InjuryDtos.Add(NewInjury);
            }

            return(Ok(InjuryDtos));
        }
コード例 #4
0
        public IHttpActionResult GetInjuriesForPlayer(int id)
        {
            List <Injury> Injuries = db.Injuries
                                     .Where(i => i.Players.Any(p => p.PlayerID == id))
                                     .ToList();
            List <InjuryDto> SponsorDtos = new List <InjuryDto> {
            };

            //Here you can choose which information is exposed to the API
            foreach (var Injury in Injuries)
            {
                InjuryDto NewSponsor = new InjuryDto
                {
                    InjuryID   = Injury.InjuryID,
                    InjuryName = Injury.InjuryName,
                };
                SponsorDtos.Add(NewSponsor);
            }

            return(Ok(SponsorDtos));
        }
コード例 #5
0
        public IHttpActionResult FindInjury(int id)
        {
            //Find the data
            Injury Injury = db.Injuries.Find(id);

            //if not found, return 404 status code.
            if (Injury == null)
            {
                return(NotFound());
            }

            //put into a 'friendly object format'
            InjuryDto InjuryDto = new InjuryDto
            {
                InjuryID   = Injury.InjuryID,
                InjuryName = Injury.InjuryName
            };


            //pass along data as 200 status code OK response
            return(Ok(InjuryDto));
        }