protected void Page_Load(object sender, EventArgs e) { Response.Expires = -1; if (Request.Form["episode"] != null) { // Reading the episode sent by the page, as a JSON string string episode_JsonFormat = Request.Form["episode"]; // Converting from JSON to object Episode episode = JsonConvert.DeserializeObject<Episode>(episode_JsonFormat); // Saving the episode to the repository EpisodeRepository epsRepository = new EpisodeRepository(); epsRepository.Save(episode); Response.Write("Episodio Salvo!"); Response.End(); } else { // Generate response, when no episode has been sent Response.Write("Page is loaded. Please, execute using the comics Page."); Response.End(); } }
// Function that will return the JSON-format of all episode list protected void Page_Load(object sender, EventArgs e) { Response.Expires = -1; // Loading the episode from repository EpisodeRepository epsRepository = new EpisodeRepository(); var episodeList = epsRepository.AllEpisodeList(); Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; Response.Write(JsonConvert.SerializeObject(episodeList)); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { Response.Expires = -1; if (Request["episodeNumber"] != null) { // Setting and configuring the parameters var episodeNumber = Int16.Parse(Request["episodeNumber"]); var idiom = Request["idiom"]; try { // Loading the episode from repository EpisodeRepository epsRepository = new EpisodeRepository(); var episode = epsRepository.Load(episodeNumber, idiom); // Sending the episode as a JSon format Response.Clear(); Response.ContentType = "application/json; charset=utf-8"; // Sending an error object if (episode == null) { SendErrorMap(); } else { Response.Write(JsonConvert.SerializeObject(episode)); } } catch (Exception exp) { SendErrorMap(); } finally { Response.End(); } } else { Response.Write("Page is loaded. Please, execute using the comics Page."); Response.End(); } }