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; }
public static IEnumerable<Company> GenerateCompanies(string connectionString, int gameId, int numCompanies = -1) { var insert = new SqlInsertStatement(connectionString); insert.InsertInto("dbo.BZ_Company") .Column("GameId", gameId) .Column("Name") .Column("Money") .Column("InitialAccuracy"); if(numCompanies < 0) { numCompanies = Utilities.GetRandomInt(1, 5); } for (var index = 0; index < numCompanies; index++) { insert.Values() .Value("Name", Utilities.GetRandomString(16).Replace("'", "''")) .Value("Money", Utilities.GetRandomDecimal()) .Value("InitialAccuracy", Utilities.GetRandomDecimal()); } insert.Execute(); var sql = new SqlSelectStatement(connectionString); sql.Select("Id") .Select("Name") .Select("Money") .Select("InitialAccuracy") .Select("UserId") .From("dbo.BZ_Company") .WhereEquals("GameId", gameId); return sql.ExecuteComplex<Company>(); }
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>(); }
public static IEnumerable<Project> GenerateProjects(string connectionString, int gameId, int count = 1) { var definitions = GetDBProjectDefinitions(connectionString); var insert = new SqlInsertStatement(connectionString); insert.InsertInto("dbo.BZ_Project") .Column("GameId", gameId) .Column("ProjectDefinitionId") .Column("Value") .Column("Deadline") .Column("ReputationRequired"); while (count-- > 0) { var deadline = Utilities.GetRandomDate(DateTime.Today, DateTime.Today.AddYears(1)); var requiredReputation = (int)Utilities.GetValues<StarCategory>().Random(); var value = Utilities.GetRandomDecimal(10, 1000); insert.Values() .Value("ProjectDefinitionId", definitions.Random().Id) .Value("Value", value) .Value("Deadline", deadline) .Value("ReputationRequired", requiredReputation); } insert.Execute(); var projectSelect = new SqlSelectStatement(connectionString); projectSelect.Select("Id") .Select("GameId") .Select("ProjectDefinitionId") .Select("Value") .Select("Deadline") .Select("ReputationRequired") .From("dbo.BZ_Project") .WhereEquals("GameId", gameId); var pData = projectSelect.ExecuteData(); var skillIds = new SqlSelectStatement(connectionString) .Select("Id") .From("dbo.BZ_Skill_Definition") .Execute<int>(); var requirementInsert = new SqlInsertStatement(connectionString); requirementInsert.InsertInto("dbo.BZ_Project_Requirement") .Column("ProjectId") .Column("SkillDefinitionId") .Column("TargetValue") .Column("CurrentValue", 0.0m); var output = new List<Project>(); var anyHasRequirements = false; foreach (var item in pData) { var id = (int)item["Id"]; var definitionId = (short)item["ProjectDefinitionId"]; var definition = definitions.FirstOrDefault(d => d.Id == definitionId); var requirements = new List<ProjectRequirement>(); foreach (var skill in definition.Skills) { anyHasRequirements = true; var targetValue = Utilities.GetRanged(skill.Value, 2); requirements.Add(new ProjectRequirement { SkillDefinition = skill.SkillDefinition, CurrentValue = 0, TargetValue = targetValue }); requirementInsert.Values() .Value("ProjectId", id) .Value("SkillDefinitionId", skill.SkillDefinition.Id) .Value("TargetValue", targetValue); } output.Add(new Project(requirements) { Id = id, Value = (decimal)item["Value"], Deadline = (DateTime)item["Deadline"], ReputationRequired = (StarCategory)(int)item["ReputationRequired"], Definition = definition }); } if (anyHasRequirements) { requirementInsert.Execute(); } return output; }