public string UpdatePlanetsColor(IDbConnection connection)
        {
            //var planets = _gGeometryPlanetService.GetAll(i => i);
            var planets = _gGeometryPlanetService.GetAll(connection, i => i);
            var systems = (List <GGeometrySystemDataModel>)_systemService.GetGeometrySystems(connection);

            if (systems == null)
            {
                throw new ArgumentNullException(Error.NoData, nameof(systems));
            }

            foreach (var planet in planets)
            {
                var planetId = planet.Id;
                var sysIdx   = systems.FindIndex(i => i.Id == planet.SystemId);

                planet.Color = PlanetColor3Generator.CreateColorByType(planet.TypeId);
                systems[sysIdx].Planetoids.Planets[planetId].Color = planet.Color;
            }
            _gGeometryPlanetService.AddOrUpdateGeometryPlanets(planets, connection);
            _systemService.AddOrUpdateGeometrySystems(connection, systems);
            return("Sucsess");
        }
        private bool CreatePlanets(IDbConnection connection)
        {
            var stars = _getStarCollection(connection);
            var pl    = new PlanetGeometry();


            //            const double FactorAngle = Math.PI/16;

            //==================================================
            var planetTypeName = MapTypes.Planet.ToString();

            var gasGameTypes = new List <byte> {
                (byte)PlanetoidSubTypes.Gas, (byte)PlanetoidSubTypes.IceGas
            };
            var usedGasGameTypes = new List <byte>();


            var planetTextureTypes = _gameTypeService.GetTextures(connection, planetTypeName);

            var earthTextureTypes =
                planetTextureTypes.Where(i => i.GameTypeId == (byte)PlanetoidSubTypes.Earth).Select(i => i.Id)
                .ToList();

            var gasTextureTypes =
                planetTextureTypes.Where(i => i.GameTypeId == (byte)PlanetoidSubTypes.Gas).Select(i => i.Id).ToList();
            var iceGasTypes = planetTextureTypes.Where(i => i.GameTypeId == (byte)PlanetoidSubTypes.IceGas)
                              .Select(i => i.Id)
                              .ToList();


            var earthTextureUsed  = new List <short>();
            var gasTextureUsed    = new List <short>();
            var iceGasTextureUsed = new List <short>();

            //==================================================


            var planets = new List <GGeometryPlanetDataModel>();

            foreach (var star in stars)
            {
                var planetCount      = Rand.Next(6, 10);
                var starRadius       = star.Radius;
                var basicPlanetOrbit = 1.2 * starRadius;

                var secondRingCoef = 1;

                for (var i = 0; i < planetCount; i++)
                {
                    pl.Atmosphere = true;
                    pl.Rings      = null;

                    var currOrbit = basicPlanetOrbit * Math.Pow(Factor, i) / 4;
                    var q         = currOrbit / 2;
                    currOrbit *= Scale;
                    currOrbit  = Math.Round(currOrbit, 4);
                    var planetCurrRadius = Math.Round(q - (q * 0.1 * i), 4);


                    byte  typeId;
                    short textureType;
                    if (i <= 4)
                    {
                        typeId      = (byte)PlanetoidSubTypes.Earth;
                        textureType = GameTypeHalper.GetRandomTypeFromUsedTyps(earthTextureTypes, ref earthTextureUsed);
                    }
                    else
                    {
                        typeId      = GameTypeHalper.GetRandomTypeFromUsedTyps(gasGameTypes, ref usedGasGameTypes);
                        textureType = (typeId == (byte)PlanetoidSubTypes.Gas)
                            ? GameTypeHalper.GetRandomTypeFromUsedTyps(gasTextureTypes, ref gasTextureUsed)
                            : GameTypeHalper.GetRandomTypeFromUsedTyps(iceGasTypes, ref iceGasTextureUsed);

                        var hasRing = HasRings(i, ref secondRingCoef);
                        if (hasRing)
                        {
                            pl.Rings = _createRings(connection);
                        }
                    }


                    var orbitPosition = (byte)Rand.Next(0, Tes);
                    var orbitAngle    = _getRandomAngle(FactorAngle);


                    planets.Add(new GGeometryPlanetDataModel
                    {
                        GalaxyId   = star.GalaxyId,
                        SectorId   = star.SectorId,
                        SystemId   = star.Id,
                        TypeId     = typeId,
                        Orbit      = currOrbit,
                        AxisAngle  = _getRandomAngle(FactorAngle),
                        OrbitAngle = orbitAngle,

                        RingTypeId     = pl.Rings,
                        SystemPosition = (byte)(i + 1),
                        Radius         = planetCurrRadius,
                        Color          = PlanetColor3Generator.CreateColorByType(typeId),
                        TextureTypeId  = textureType,

                        OrbitPosition = orbitPosition
                    });
                }
            }
            var suc = _gGeometryPlanetService.AddOrUpdateGeometryPlanets(planets, connection).Any();


            return(suc);
        }