protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); StreamReader reader = new StreamReader(this.Request.InputStream); String xmlData = reader.ReadToEnd(); XmlDocument docXRef = new XmlDocument(); docXRef.LoadXml(xmlData); string uname = Utils.TryGetProperty("DeleteCrossRef_AniDB_TraktRequest", docXRef, "Username"); string aid = Utils.TryGetProperty("DeleteCrossRef_AniDB_TraktRequest", docXRef, "AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); if (string.IsNullOrEmpty(uname) || animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } List <CrossRef_AniDB_Trakt> recs = repCrossRef.GetByAnimeIDUser(animeid, uname); foreach (CrossRef_AniDB_Trakt xref in recs) { repCrossRef.Delete(xref.CrossRef_AniDB_TraktID); } // now send to mirror string uri = string.Format("http://{0}/DeleteCrossRef_AniDB_Trakt.aspx", Constants.MirrorWAIX); XMLService.SendData(uri, xmlData); } catch (Exception ex) { Response.Write(Constants.ERROR_XML); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); StreamReader reader = new StreamReader(this.Request.InputStream); String xmlData = reader.ReadToEnd(); XmlDocument docXRef = new XmlDocument(); docXRef.LoadXml(xmlData); string uname = Utils.TryGetProperty("AddCrossRef_AniDB_Trakt_Request", docXRef, "Username"); string sname = Utils.TryGetProperty("AddCrossRef_AniDB_Trakt_Request", docXRef, "ShowName"); string aid = Utils.TryGetProperty("AddCrossRef_AniDB_Trakt_Request", docXRef, "AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); string traktid = Utils.TryGetProperty("AddCrossRef_AniDB_Trakt_Request", docXRef, "TraktID"); string traktseason = Utils.TryGetProperty("AddCrossRef_AniDB_Trakt_Request", docXRef, "Season"); int traktSeason = 0; if (!int.TryParse(traktseason, out traktSeason)) { Response.Write(Constants.ERROR_XML); return; } if (string.IsNullOrEmpty(uname) || animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } CrossRef_AniDB_Trakt xref = null; List <CrossRef_AniDB_Trakt> recs = repCrossRef.GetByAnimeIDUser(animeid, uname); if (recs.Count == 1) { xref = recs[0]; } if (recs.Count == 0) { xref = new CrossRef_AniDB_Trakt(); } else { xref = recs[0]; } xref.AnimeID = animeid; xref.AdminApproved = 0; xref.TraktID = traktid; xref.TraktSeasonNumber = traktSeason; xref.Username = uname; xref.ShowName = sname; repCrossRef.Save(xref); // now send to mirror string uri = string.Format("http://{0}/AddCrossRef_AniDB_Trakt.aspx", Constants.MirrorWAIX); XMLService.SendData(uri, xmlData); } catch (Exception ex) { Response.Write(Constants.ERROR_XML); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "text/xml"; try { string aid = Utils.GetParam("AnimeID"); int animeid = 0; int.TryParse(aid, out animeid); if (animeid <= 0) { Response.Write(Constants.ERROR_XML); return; } string uname = Utils.GetParam("uname"); if (uname.Trim().Length == 0) { Response.Write(Constants.ERROR_XML); return; } CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository(); CrossRef_AniDB_Trakt xref = null; // check for admin approved List <CrossRef_AniDB_Trakt> recs = repCrossRef.GetByAnimeIDApproved(animeid); if (recs.Count > 0) { xref = recs[0]; // should only be one } // check for user specific if (xref == null) { recs = repCrossRef.GetByAnimeIDUser(animeid, uname); if (recs.Count > 0) { xref = recs[0]; // should only be one } } // check for other users (anonymous) if (xref == null) { // check for other users (anonymous) recs = repCrossRef.GetByAnimeID(animeid); if (recs.Count == 0) { Response.Write(Constants.ERROR_XML); return; } // find the most popular result List <CrossRefTraktStat> results = new List <CrossRefTraktStat>(); foreach (CrossRef_AniDB_Trakt xrefloc in recs) { bool found = false; foreach (CrossRefTraktStat stat in results) { if (stat.TraktID.Equals(xrefloc.TraktID, StringComparison.InvariantCultureIgnoreCase) && stat.TraktSeason == xrefloc.TraktSeasonNumber) { found = true; stat.ResultCount++; } } if (!found) { CrossRefTraktStat stat = new CrossRefTraktStat(); stat.ResultCount = 1; stat.TraktID = xrefloc.TraktID; stat.TraktSeason = xrefloc.TraktSeasonNumber; stat.CrossRef = xrefloc; results.Add(stat); } } CrossRefTraktStat mostPopular = null; foreach (CrossRefTraktStat stat in results) { if (mostPopular == null) { mostPopular = stat; } else { if (stat.ResultCount > mostPopular.ResultCount) { mostPopular = stat; } } } xref = mostPopular.CrossRef; } CrossRef_AniDB_TraktResult result = new CrossRef_AniDB_TraktResult(xref); string ret = Utils.ConvertToXML(result, typeof(CrossRef_AniDB_TraktResult)); Response.Write(ret); } catch (Exception ex) { Response.Write(ex.ToString()); return; } }