// 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")); } }
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")); } }
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)); }
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)); }
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)); }