public async Task <IEnumerable <Boardgame> > LoadHotness() { try { Uri teamDataURI = new Uri(BASE_URL + "/hot?thing=boardgame"); XDocument xDoc = await ReadData(teamDataURI); // LINQ to XML. IEnumerable <Boardgame> gameCollection = from Boardgame in xDoc.Descendants("item") select new Boardgame { Name = Boardgame.Element("name").Attribute("value").Value, YearPublished = Boardgame.Element("yearpublished") != null?int.Parse(Boardgame.Element("yearpublished").Attribute("value").Value) : 0, Thumbnail = Boardgame.Element("thumbnail").Attribute("value").Value, GameId = int.Parse(Boardgame.Attribute("id").Value) }; return(gameCollection); } catch (Exception ex) { //ExceptionHandler(ex); return(new List <Boardgame>()); } }
public async Task <IEnumerable <Play> > LoadLastPlays(string Username) { try { Uri teamDataURI = new Uri(string.Format(BASE_URL + "/plays?username={0}", Username)); XDocument xDoc = await ReadData(teamDataURI); IEnumerable <Play> gameCollection = from Boardgame in xDoc.Descendants("play") select new Play { PlayId = int.Parse(Boardgame.Attribute("id").Value), BoardGameName = Boardgame.Element("item").Attribute("name").Value, BoardGameId = int.Parse(Boardgame.Element("item").Attribute("objectid").Value), PlayDate = safeParseDateTime(Boardgame.Attribute("date").Value), NumberOfPlays = int.Parse(Boardgame.Attribute("quantity").Value), Length = int.Parse(Boardgame.Attribute("length").Value), UserComment = GetStringValue(Boardgame.Element("comments")), Players = LoadPlayersStatsList(Boardgame.Element("players")) }; return(gameCollection); } catch (Exception) { return(new List <Play>()); } }
public async Task <User> LoadUserDetails(string username) { try { Uri teamDataURI = new Uri(string.Format(BASE_URL + "/user?name={0}", username)); XDocument xDoc = await ReadData(teamDataURI); IEnumerable <User> users = from Boardgame in xDoc.Descendants("user") select new User { BggUserId = int.Parse(Boardgame.Attribute("id").Value), Username = Boardgame.Attribute("name").Value, Avatar = GetStringValue(Boardgame.Element("avatarlink"), "value"), FirstName = GetStringValue(Boardgame.Element("firstname"), "value"), LastName = GetStringValue(Boardgame.Element("lastname"), "value"), YearRegistered = GetStringValue(Boardgame.Element("yearregistered"), "value"), }; return(users.FirstOrDefault()); } catch (Exception) { return(new User()); } }
public async Task <IEnumerable <PlayItem> > LoadLastPlays(string Username) { try { Uri teamDataURI = new Uri(string.Format(BASE_URL + "/plays?username={0}&subtype=boardgame&excludesubtype=videogame", Username)); XDocument xDoc = await ReadData(teamDataURI); // LINQ to XML. IEnumerable <PlayItem> gameCollection = from Boardgame in xDoc.Descendants("play") select new PlayItem { Name = Boardgame.Element("item").Attribute("name").Value, NumPlays = int.Parse(Boardgame.Attribute("quantity").Value), GameId = int.Parse(Boardgame.Element("item").Attribute("objectid").Value), PlayDate = safeParseDateTime(Boardgame.Attribute("date").Value) }; return(gameCollection); } catch (Exception ex) { return(new List <PlayItem>()); } }
public async Task <IEnumerable <HotItem> > LoadHotItems() { try { Uri teamDataURI = new Uri(BASE_URL + "/hot?type=boardgame"); XDocument xDoc = await ReadData(teamDataURI); IEnumerable <HotItem> hotBoardGamesCollection = from Boardgame in xDoc.Descendants("item") select new HotItem { Name = Boardgame.Element("name").Attribute("value").Value, YearPublished = Boardgame.Element("yearpublished") != null?int.Parse(Boardgame.Element("yearpublished").Attribute("value").Value) : 0, ThumbnailWeb = "http:" + Boardgame.Element("thumbnail").Attribute("value").Value, BoardGameId = int.Parse(Boardgame.Attribute("id").Value), Rank = int.Parse(Boardgame.Attribute("rank").Value) }; return(hotBoardGamesCollection); } catch (Exception) { return(new List <HotItem>()); } }
public async Task <Plays> LoadPlays(string username, int page = 1, DateTime?minDate = null, DateTime?maxDate = null) { try { string url = string.Format(BASE_URL2 + "/plays?username={0}&subtype=boardgame&excludesubtype=videogame&page={1}", username, page); if (minDate != null) { url += "&mindate=" + minDate.Value.ToString("yyyy-MM-dd"); } if (maxDate != null) { url += "&maxdate=" + maxDate.Value.ToString("yyyy-MM-dd"); } Uri teamDataURI = new Uri(url); XDocument xDoc = await ReadData(teamDataURI); // LINQ to XML. IEnumerable <PlayItem> gameCollection = from Boardgame in xDoc.Descendants("play") select new PlayItem { Name = Boardgame.Element("item").Attribute("name").Value, NumPlays = int.Parse(Boardgame.Attribute("quantity").Value), GameId = int.Parse(Boardgame.Element("item").Attribute("objectid").Value), PlayDate = safeParseDateTime(Boardgame.Attribute("date").Value), Comments = Boardgame.Element("comments") != null?TrimmedStringOrNull(Boardgame.Element("comments").Value) : null }; var plays = new Plays(); plays.Total = int.Parse(xDoc.Root.Attribute("total").Value); plays.Items = gameCollection; return(plays); } catch (Exception ex) { throw; //return new Plays(); } }