/// <summary> /// /// </summary> /// <param name="id"></param> public static void DeleteRuleSet(int id) { using (var db = new DatabaseContext()) { RuleSet ruleSet = db.RuleSets.First(i => i.RuleSetId == id); db.RuleSets.Remove(ruleSet); // Remove references to this rule set (formula) from any rankings in which it appears. var rankings = from r in db.Rankings where r.RuleSetId == ruleSet.RuleSetId select r; foreach (Ranking ranking in rankings) { ranking.RuleSetId = -1; } db.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="ruleset"></param> public static void CreateRuleSet(string name, string formula, string username) { DateTime now = DateTime.Now; bool isValidFormula = ValidateFormula(formula); var ruleSet = new RuleSet { RuleSetName = name, Formula = formula, User = username, Created = now, Valid = isValidFormula }; using (var db = new DatabaseContext()) { db.RuleSets.Add(ruleSet); db.SaveChanges(); } }
public static void DeleteCity(int cityId) { using (var db = new DatabaseContext()) { CityInfo cityInfo = db.CityInfoes.First(i => i.CityInfoId == cityId); db.CityInfoes.Remove(cityInfo); // Remove the city from any rankings it was present in. var rankedRefs = from r in db.RankingMembers where r.CityInfoId == cityInfo.CityInfoId select r; foreach (RankingMember rankedReference in rankedRefs) { db.RankingMembers.Remove(rankedReference); } db.SaveChanges(); } // TODO: Also delete city files... or mark them as "orphan" somehow. // Maybe the city ref should just be marked as orphan in the db... that way we can save the ranked instances. }
public static void UpdateScoringIdentifiers(string serverHome) { using (DatabaseContext db = new DatabaseContext()) { // Clear all scoring ids. // ... inefficiently, but this only runs at application start so it will do. foreach (var scoringId in db.ScoringIdentifiers) { db.ScoringIdentifiers.Remove(scoringId); } // Add all scoring ids. foreach (var scoringId in getScoringIdentifiers(serverHome)) { db.ScoringIdentifiers.Add(scoringId); } db.SaveChanges(); } }
private static void storeCity(City parserCity, string username, string filepath, Stream cityFileStream) { // Fetch relevant data from parserCity. var city = new CityInfo(parserCity, username, filepath, DateTime.Now); // Save .sc2 file on the server. cityFileStream.Position = 0; using (Stream outputStream = File.OpenWrite(filepath)) { cityFileStream.CopyTo(outputStream); } // Save parsed city data to database. using (var db = new DatabaseContext()) { db.CityInfoes.Add(city); db.SaveChanges(); } }