Пример #1
0
        public static int CreateGameWithGameConfigurationEntry(string connectionString)
        {
            var idSelect = new SqlSelectStatement(connectionString);

            idSelect.Top(1)
                    .Select("G.Id")
                    .From("dbo.BZ_Game", "G")
                    .Join("dbo.BZ_Game_Configuration", "GC", "GC.GameId = G.Id");

            var id = idSelect.ExecuteScalar<int?>();

            if (!id.HasValue)
            {
                var name = Utilities.GetRandomString(16);

                var gameInsert = new SqlInsertStatement(connectionString);

                gameInsert.InsertInto("dbo.BZ_Game")
                          .Column("CreatedBy", 1)
                          .Column("CreatedDate", DateTime.Now)
                          .Column("Name")
                          .Column("IndustryId", 1)
                          .Values()
                            .Value("Name", name);

                gameInsert.Execute();

                idSelect = new SqlSelectStatement(connectionString);

                idSelect.Top(1)
                    .Select("Id")
                    .From("dbo.BZ_Game")
                    .WhereEquals("Name", name);

                id = idSelect.ExecuteScalar<int?>();

                var entryInsert = new SqlInsertStatement(connectionString);

                entryInsert.InsertInto("dbo.BZ_Game_Configuration")
                           .Column("GameId", id.Value)
                           .Column("ConfigurationKeyId", 1)
                           .Column("Value")
                           .Values()
                            .Value("Value", "Test Value");

                entryInsert.Execute();
            }

            return id.Value;
        }
Пример #2
0
        public static int GetGameId(string connectionString, string name)
        {
            var sql = new SqlInsertStatement(connectionString);

            sql.InsertInto("dbo.BZ_Game")
               .Column("CreatedBy", 1)
               .Column("CreatedDate", DateTime.Now)
               .Column("Name")
               .Column("IndustryId", 1)
               .Values()
                .Value("Name", name);

            sql.Execute();

            var select = new SqlSelectStatement(connectionString);

            select.Top(1)
                  .From("dbo.BZ_Game")
                  .Select("Id")
                  .WhereEquals("Name", name);

            return select.ExecuteScalar<int>();
        }