public int UpdatePlanet(Planet planet) { Planet planetFound = Planets.Find(p => p.Id == planet.Id); planetFound.Diameter = planet.Diameter; planetFound.DistanceFromSun = planet.DistanceFromSun; planetFound.Gravity = planet.Gravity; planetFound.ImagePath = planet.ImagePath; planetFound.LengthOfDay = planet.LengthOfDay; planetFound.Mass = planet.Mass; planetFound.MeanTemperature = planet.MeanTemperature; planetFound.Name = planet.Name; planetFound.NumberOfMoons = planet.NumberOfMoons; planetFound.OrbitalPeriod = planet.OrbitalPeriod; return 1; }
public int CreatePlanet(Planet planet) { Planet newPlanet = new Planet { Id = Planets.Max(p => p.Id) + 1, Diameter = planet.Diameter, DistanceFromSun = planet.DistanceFromSun, Gravity = planet.Gravity, ImagePath = planet.ImagePath, LengthOfDay = planet.LengthOfDay, Mass = planet.Mass, MeanTemperature = planet.MeanTemperature, Name = planet.Name, NumberOfMoons = planet.NumberOfMoons, OrbitalPeriod = planet.OrbitalPeriod }; Planets.Add(newPlanet); return newPlanet.Id; }
private List<Planet> MapViewModelsToPlanets(List<PlanetViewModel> vms) { List<Planet> planets = new List<Planet>(); Planet p; foreach (PlanetViewModel vm in vms) { p = new Planet(); p.Id = int.Parse(vm.Id); p.Name = vm.Name; p.ImagePath = vm.ImagePath; p.Mass = vm.Mass; p.Diameter = vm.Diameter; p.Gravity = vm.Gravity; p.LengthOfDay = vm.LengthOfDay; p.DistanceFromSun = vm.DistanceFromSun; p.OrbitalPeriod = vm.OrbitalPeriod; p.MeanTemperature = vm.MeanTemperature; p.NumberOfMoons = vm.NumberOfMoons; planets.Add(p); } return planets; }