protected async Task RetriveData() { try { users = JsonConvert.DeserializeObject <List <User> >(await HttpRequestsManager.ExecuteRequestAsync(HOST)); Debug.WriteLine("Success"); } catch (WebException ex) { //When server is down (only for our test) string debug = File.ReadAllText("F:\\Projects\\OBL\\WebSite\\App_LocalResources\\json.json"); users = JsonConvert.DeserializeObject <List <User> >(debug); Debug.WriteLine("ERROR: " + ex.Message + "\nDo you forget to update HOST name or run the server?"); } finally { posts = users.SelectMany( //select all posts, but- u => u.Posts.Select(p => p.SetUser(u)) //add user to ach post ).ToList(); RepeaterPosts.DataSource = posts; RepeaterJS.DataSource = users; RepeaterPosts.DataBind(); RepeaterJS.DataBind(); UpdatePanelRepeater.Update(); } }
private void PopulatePosts() { var posts = from post in dbContext.Posts select post; RepeaterPosts.DataSource = posts; RepeaterPosts.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } // id in querystring? int topicId; if (!int.TryParse(Request.QueryString["id"], out topicId)) { throw new HttpException(400, "Bad Request"); } Topic topic; // bestaand topic? if ((topic = GetTopic(topicId)) == null) { throw new HttpException(404, "Not Found"); } // ja! (Master as Layout).GenerateBreadCrumb(topic.Forum); (Master.FindControl("BulletedListBreadCrumb") as BulletedList).Items.Add(new ListItem(topic.Title, "#")); Page.Title = LiteralTopicTitle.Text = topic.Title; HiddenFieldTopicId.Value = topic.Id.ToString(); RepeaterPosts.DataSource = topic.Posts.OrderBy(post => post.CreatedDate); RepeaterPosts.DataBind(); Member member = Session["member"] as Member; if (topic.IsLocked) { ButtonReply.CssClass = "btn btn-danger"; ButtonReply.Enabled = false; ButtonReply.Text = "Locked"; ButtonReply.ToolTip = "This topic is locked. You cannot reply."; } else { if (member == null) // gast { ButtonReply.Enabled = false; ButtonReply.Text = "Login to reply"; ButtonReply.ToolTip = "Only registered users can reply to topics."; } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["Username"] == null && Session["Guest"] == null) { Response.Redirect("Login.aspx"); } if (Session["Guest"] != null) { Response.Redirect("Home.aspx"); } if (Session["Username"] != null) { string username = Session["Username"].ToString(); UserService.UserService proxy = new UserService.UserService(); bool verified = proxy.IsUserVerified(username); if (!verified) { Response.Redirect("Verification.aspx?mail=false"); } } if (!IsPostBack) { string username = Session["Username"].ToString(); UserService.UserService proxy = new UserService.UserService(); UserService.User proxyUser = proxy.GetUser(username); User user = new User(proxyUser.Username, proxyUser.FirstName, proxyUser.LastName, proxyUser.Password, proxyUser.ProfileImage, proxyUser.HomeAddress, proxyUser.BillingAddress, proxyUser.EmailAddress, proxyUser.Phone, proxyUser.SecretQuestions, proxyUser.SecretAnswers, proxyUser.Verified); imgProfileImage.ImageUrl = user.ProfileImage; lblUsername.InnerText = user.Username; lblFirstName.InnerText = user.FirstName; lblLastName.InnerText = user.LastName; lblEmail.InnerText = user.EmailAddress; lblPhone.InnerText = user.Phone; lblHomeAddress.InnerText = user.HomeAddress; lblBillingAddress.InnerText = user.BillingAddress; string[] questions = user.SecretQuestions.Split(','); lblSecurityQuestion1.InnerText = securityQuestions[Int32.Parse(questions[0])]; lblSecurityQuestion2.InnerText = securityQuestions[Int32.Parse(questions[1])]; lblSecurityQuestion3.InnerText = securityQuestions[Int32.Parse(questions[2])]; // Getting Posts string url = "https://localhost:44312/api/User/GetUserPosts/" + username; WebRequest request = WebRequest.Create(url); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); String data = reader.ReadToEnd(); JavaScriptSerializer js = new JavaScriptSerializer(); List <Post> posts = js.Deserialize <List <Post> >(data); RepeaterPosts.DataSource = posts; RepeaterPosts.DataBind(); if (posts.Count == 0) { h5NoPosts.Visible = true; } stream.Close(); reader.Close(); // Getting Follow count string url2 = "https://localhost:44312/api/Follow/GetFollowCount/" + username; WebRequest request2 = WebRequest.Create(url2); WebResponse response2 = request2.GetResponse(); Stream stream2 = response2.GetResponseStream(); StreamReader reader2 = new StreamReader(stream2); String data2 = reader2.ReadToEnd(); btnFollowing.Text = "Following " + data2; stream2.Close(); reader2.Close(); // Getting Follower count string url3 = "https://localhost:44312/api/Follow/GetFollowerCount/" + username; WebRequest request3 = WebRequest.Create(url3); WebResponse response3 = request3.GetResponse(); Stream stream3 = response3.GetResponseStream(); StreamReader reader3 = new StreamReader(stream3); String data3 = reader3.ReadToEnd(); btnFollowers.Text = data3 + " Followers"; stream3.Close(); reader3.Close(); } SetupPostCardEvents(); }