public async Task <ActionResult> GetHanSolo(CancellationToken cancellationToken) { ResidentSummary vm = null; try { vm = await _starWarsService.GetHanSoloAsync(cancellationToken); } catch (NullReferenceException ex) { if (ex.Message.Contains("not found")) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } //potentially log error here and return 500 return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } catch (Exception ex) { //potentially log error and rethrow error, or, in this case, just return 500 return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(View(vm)); }
public ResidentSummary ToResidentSummary() { var model = new ResidentSummary(); model.Name = Name; model.Height = Height; model.Weight = Weight; model.Gender = Gender; model.HairColor = HairColor; model.EyeColor = EyeColor; model.SkinColor = SkinColor; return(model); }
public async Task <ActionResult> GetResidentsOfPlanetNaboo(string planetname) { var model = new PlanetResidentsViewModel(); List <ResidentModel> residents = await starWarsApi.GetResidentsByPlanetNameAsync("Naboo"); residents = residents.OrderBy(x => x.ResidentName).ToList(); foreach (ResidentModel r in residents) { ResidentSummary rs = new ResidentSummary(); rs.EyeColor = r.ResidentEyeColor; rs.Gender = r.ResidentGender; rs.HairColor = r.ResidentHairColor; rs.Height = r.ResidentHeight; rs.Name = r.ResidentName; rs.SkinColor = r.ResidentSkinColor; rs.Weight = r.ResidentWeight; model.Residents.Add(rs); } return(View(model)); }