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

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

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into Sponsor data transfer object
                SponsorDto SelectedSponsor = response.Content.ReadAsAsync <SponsorDto>().Result;
                ViewModel.sponsor = SelectedSponsor;

                //find teams that are sponsored by this sponsor
                url      = "sponsordata/getteamsforsponsor/" + id;
                response = client.GetAsync(url).Result;

                //Put data into Sponsor data transfer object
                IEnumerable <TeamDto> SelectedTeams = response.Content.ReadAsAsync <IEnumerable <TeamDto> >().Result;
                ViewModel.sponsoredteams = SelectedTeams;

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

            //Can catch the status code (200 OK, 301 REDIRECT), etc.
            //Debug.WriteLine(response.StatusCode);
            if (response.IsSuccessStatusCode)
            {
                //Put data into Sponsor data transfer object
                SponsorDto SelectedSponsor = response.Content.ReadAsAsync <SponsorDto>().Result;
                return(View(SelectedSponsor));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
コード例 #3
0
        public IHttpActionResult GetSponsors()
        {
            List <Sponsor>    Sponsors    = db.Sponsors.ToList();
            List <SponsorDto> SponsorDtos = new List <SponsorDto> {
            };

            //Here you can choose which information is exposed to the API
            foreach (var Sponsor in Sponsors)
            {
                SponsorDto NewSponsor = new SponsorDto
                {
                    SponsorID   = Sponsor.SponsorID,
                    SponsorName = Sponsor.SponsorName,
                    SponsorURL  = Sponsor.SponsorURL
                };
                SponsorDtos.Add(NewSponsor);
            }

            return(Ok(SponsorDtos));
        }
コード例 #4
0
        public IHttpActionResult FindSponsor(int id)
        {
            //Find the data
            Sponsor Sponsor = db.Sponsors.Find(id);

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

            //put into a 'friendly object format'
            SponsorDto SponsorDto = new SponsorDto
            {
                SponsorID   = Sponsor.SponsorID,
                SponsorName = Sponsor.SponsorName,
                SponsorURL  = Sponsor.SponsorURL
            };


            //pass along data as 200 status code OK response
            return(Ok(SponsorDto));
        }
コード例 #5
0
        public IHttpActionResult GetSponsorsForTeam(int id)
        {
            List <Sponsor> Sponsors = db
                                      .Sponsors
                                      //s.Teams.Any(t => t.TeamID == id) returns TRUE OR FALSE
                                      .Where(s => s.Teams.Any(t => t.TeamID == id))
                                      .ToList();
            List <SponsorDto> SponsorDtos = new List <SponsorDto> {
            };

            //Here you can choose which information is exposed to the API
            foreach (var Sponsor in Sponsors)
            {
                SponsorDto NewSponsor = new SponsorDto
                {
                    SponsorID   = Sponsor.SponsorID,
                    SponsorName = Sponsor.SponsorName,
                    SponsorURL  = Sponsor.SponsorURL
                };
                SponsorDtos.Add(NewSponsor);
            }

            return(Ok(SponsorDtos));
        }