//Get starship detailsl public static SwStarship GetSwStarshipById(int id) { IRepository <Starship> starshipRepo = new Repository <Starship>(); Starship starship = starshipRepo.GetById(id); SwStarship swStarship = SwApiMapping.MapStarship(starship); if (swStarship.CostInCredits > 2147483647) { swStarship.CostInCredits = 2147483647.0M; } Dictionary <int, string> starshipImageURLs = new Dictionary <int, string>(); starshipImageURLs.Add(100, "https://www.vhv.rs/file/max/27/271590_millennium-falcon-png.png"); if (starshipImageURLs.ContainsKey(id)) { swStarship.ImageURL = starshipImageURLs[id]; } else { swStarship.ImageURL = "https://upload.wikimedia.org/wikipedia/commons/thumb/7/75/Emblem_of_the_First_Galactic_Empire.svg/600px-Emblem_of_the_First_Galactic_Empire.svg.png"; } return(swStarship); }
//Get all starships public static List <SwStarship> GetSwStarships() { //Hit API, get collection of starships in ambigous collection (var) IRepository <Starship> starshipRepo = new Repository <Starship>(); var starships = starshipRepo.GetEntities(1, 40); List <SwStarship> swStarships = new List <SwStarship>(); foreach (Starship starship in starships) { SwStarship swStarship = SwApiMapping.MapStarship(starship); // if (swStarship.CostInCredits > 2147483647) swStarship.CostInCredits = 2147483647.0M; if (swStarship.CostInCredits > 20000) { swStarships.Add(swStarship); } } return(swStarships); }
public static SwStarship MapStarship(Starship starship) { //Create SwStarship SwStarship swStarship = new SwStarship(); decimal CostinCreditsOutParameter; if (starship == null) { swStarship.Name = "error"; return(swStarship); } ; //Map properties swStarship.Name = starship.Name; swStarship.Model = starship.Model; swStarship.Manufacturer = starship.Manufacturer; swStarship.Length = starship.Length; bool parseCost = decimal.TryParse(starship.CostInCredits, out CostinCreditsOutParameter); if (parseCost) { swStarship.CostInCredits = CostinCreditsOutParameter; } else { swStarship.CostInCredits = 0; } swStarship.MaxAtmospheringSpeed = starship.MaxAtmospheringSpeed; swStarship.CargoCapacity = starship.CargoCapacity; swStarship.Id = GetFilmId(starship.Url, false); //swStarship.ImageURL = GetImageURL(); return(swStarship); }