Ejemplo n.º 1
0
        public static Star ToStar(DataRow dr)
        {
            Star s = new Star();

            s.id = Convert.ToInt32(dr["id"]);
            s.public_id = Guid.Parse(dr["public_id"].ToString());
            s.name = Convert.ToString(dr["name"]);
            s.mass = Convert.ToDecimal(dr["mass"]);
            s.radius = Convert.ToDecimal(dr["radius"]);
            s.galactic_radius = Convert.ToDecimal(dr["galactic_radius"]);
            s.type = (StarType)Enum.Parse(typeof(StarType), dr["type"].ToString(), true);
            s.speed = Convert.ToDecimal(dr["speed"]);
            //s.size = Convert.ToInt32(dr["size"]);

            return s;
        }
Ejemplo n.º 2
0
        public Star Star_Create(Int32 Galaxy_Id, String name, Decimal radius, Decimal galactic_radius, Decimal speed, StarType type,
            Decimal diameter, Int32 size, Decimal mass)
        {
            Star s = new Star();

            using (var cmd = GetCommand())
            {
                cmd.CommandText = "[dbo].[Star_Create]";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Galaxy_Id", Galaxy_Id);
                cmd.Parameters.AddWithValue("@name", name);
                cmd.Parameters.AddWithValue("@radius", radius);
                cmd.Parameters.AddWithValue("@galactic_radius", galactic_radius);
                cmd.Parameters.AddWithValue("@speed", speed);
                cmd.Parameters.AddWithValue("@type", type.ToString());
                cmd.Parameters.AddWithValue("@diameter", diameter);
                cmd.Parameters.AddWithValue("@size", size);
                cmd.Parameters.AddWithValue("@mass", mass);

                Int32 id = 0;
                SqlParameter param = new SqlParameter("@id", id);
                param.Direction = ParameterDirection.Output;

                cmd.Parameters.Add(param);

                cmd.ExecuteNonQuery();

                id = Convert.ToInt32(param.Value);

                return Star_SelectById(id);

            }

            return s;
        }