public RawGame UpdateOrCreate(RawGame entity) { SetupUpdateOrCreate(entity); RawGame existing; using (var db = new Db()) { existing = FindByAPIKey(entity.APIID); } if (existing == null) { //-- Insert -- entity = Create(entity); entity.dateAdded = DateTime.UtcNow; } else { existing.TheBlob = entity.TheBlob; existing.isAlsoExpansion = entity.isAlsoExpansion; existing.lastUpdatedBy = "console-Update"; existing.dateLastUpdated = DateTime.UtcNow; using (var db = new Db()) { db.Entry(existing).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } } return(entity); }
public int pullXMLbyIDSaveToDBAndTweetAboutIt(string apiKey) { try { var API = new APIAccessor_boardgamegeek_BoardGame(); var BC = new RawGamesAccessor(); var twit = new TwitterApiAccessor("iNbJLSc1T9fvufuWbFV3V6Xni", "JFjvyyhz56ZvZR1IkGjNSXNBThUT31OUrn43LXMQkCdNyy2CpK", "749359779592613888-wWPrZIls1xVFprjqRunSpKEr5GgaXDp", "rRHz1DhGR9kJ8DwwMjGuMj3uWn9z0t1IIp3YAYDlL4FKm"); var xml = API.getBoardGame(apiKey.ToString()); var newGame = new RawGame(); newGame.APIID = apiKey; newGame.TheBlob = xml; BC.UpdateOrCreate(newGame); twit.SendTweet("Someone posted information about Game ID: " + newGame.APIID + " from BGG - " + DateTime.Now.ToString("yyyyMMdd-hhmmss")); return(100); } catch (Exception e) { return(499); } }
public string searchAndSaveAllReferences(string searchCriteria) { try { var API = new APIAccessor_boardgamegeek_BoardGame(); var BC = new RawGamesAccessor(); var xml = API.search(searchCriteria); if (xml.Contains("<body>")) { return("TimeOut"); } //todo - log the search var obj = xml.ParseXML <BoardChitless.Shared.DataContracts.BoardGameGeekSearch.items>(); foreach (BoardChitless.Shared.DataContracts.BoardGameGeekSearch.itemsItem i in obj.item) { var g = new RawGame(); g.APIID = i.id.ToString(); g.Name = i.name.value.ToString(); try { g.YearPublished = i.yearpublished.value; if (i.typeField == "boardgameexpansion") { g.isAlsoExpansion = 1; } } catch { //let it be null } g.RecordType = i.typeField; g.addedBy = "console-search-" + searchCriteria; g.dateAdded = DateTime.UtcNow; //newGame.TheBlob = xml; if (i.name.type == "primary") { BC.UpdateOrCreate(g); } } return("Done"); } catch { return("Error"); } }
public void TestInitialize() { _testTransactionScope = new TransactionScope(); Target = new RawGamesAccessor(); CreatedDataContractInstance = new RawGame(); _record = new RawGame() { APIID = "822", Name = "Test", YearPublished = 2016, TheBlob = "<xml>test</xml>" }; }
public RawGame Create(RawGame entity) { entity.dateAdded = DateTime.UtcNow; entity.dateLastUpdated = DateTime.UtcNow; using (var db = new Db()) { db.Set <RawGame>().Add(entity); db.SaveChanges(); } return(entity); }
public string pullXMLbyIDAndSaveToDatabase(string apiKey) { try { var API = new APIAccessor_boardgamegeek_BoardGame(); var BC = new RawGamesAccessor(); var xml = API.getBoardGame(apiKey.ToString()); var newGame = new RawGame(); newGame.APIID = apiKey; newGame.TheBlob = xml; BC.UpdateOrCreate(newGame); return("Done!"); } catch { return("Error"); } }
public void SetupUpdateOrCreate(RawGame entity) { //Logger.Log(string.Format(Properties.Resources.Accessors_Updating, typeof(ReportRecord).Name, entity.Id), TraceEventType.Verbose); }