protected void AddComment(object sender, EventArgs e) { try { int id; Int32.TryParse(Request.QueryString["id"], out id); Assignment1Entities db = new Assignment1Entities(); Comment comment = new Comment(); comment.Posts_PostId = id; comment.Users_UserId = db.Users.FirstOrDefault(u => u.Email == (HttpContext.Current.User.Identity.Name)).UserId; comment.Text = txtComment.Text; comment.CreatedDate = DateTime.Now; db.Comments.Add(comment); db.SaveChanges(); Response.Redirect("/FullBlogPost.aspx?id=" + id); } catch { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('An Error as occurred, please try again later.');", true); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Assignment1Entities db = new Assignment1Entities(); posts.DataSource = db.Posts.ToList(); posts.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Assignment1Entities db = new Assignment1Entities(); User user = db.Users.FirstOrDefault(u => u.Email == (HttpContext.Current.User.Identity.Name)); txtFirst.Text = user.FirstName; txtLast.Text = user.LastName; txtPhone.Text = user.Phone; txtBirth.Text = user.Birth.ToString("yyyy-MM-dd"); txtCountry.Text = user.Country; } }
protected String BadWords(object sender) { String parsed = (String)sender; Assignment1Entities db = new Assignment1Entities(); foreach (var b in db.BadWords.ToList()) { parsed = parsed.Replace(b.Text, "*****"); } return(parsed); }
protected void Page_Load(object sender, EventArgs e) { if (this.Page.User.Identity.IsAuthenticated) { Assignment1Entities db = new Assignment1Entities(); var admin = db.Users.FirstOrDefault(u => u.Email == (HttpContext.Current.User.Identity.Name)).Admin; sessionFullNameLabel.Text = Session["FullName"].ToString(); LoginMenu.Visible = false; UserMenu.Visible = true; if ((bool)admin) { sessionFullNameLabel2.Text = Session["FullName"].ToString(); UserMenu.Visible = false; Admin.Visible = true; } } }
protected void ValidateUser(object sender, EventArgs e) { using (Assignment1Entities db = new Assignment1Entities()) { User user = db.Users.FirstOrDefault(u => u.Email == txtEmail.Text && u.Password == txtPassword.Text); if (user == null) { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Error: Wrong Email and Password.\\nOr Account does not exist.');", true); } else { user.LastLoginDate = DateTime.Now; db.SaveChanges(); Session["FullName"] = user.FirstName + ' ' + user.LastName; FormsAuthentication.SetAuthCookie(user.Email, false); Response.Redirect("~/Default.aspx"); } } }
protected void UpdateUser(object sender, EventArgs e) { try { Assignment1Entities db = new Assignment1Entities(); User user = db.Users.FirstOrDefault(u => u.Email == (HttpContext.Current.User.Identity.Name)); user.Email = txtEmail.Text; user.Password = txtPassword.Text; user.FirstName = txtFirst.Text; user.LastName = txtLast.Text; user.Phone = txtPhone.Text; user.Birth = DateTime.Parse(txtBirth.Text); user.Country = txtCountry.Text; db.SaveChanges(); FormsAuthentication.SetAuthCookie(user.Email, false); Response.Redirect("~/Default.aspx"); } catch { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('An Error as occurred, please try again later.');", true); } }
protected void RegisterUser(object sender, EventArgs e) { User user = new User { Email = txtEmail.Text, Password = txtPassword.Text, FirstName = txtFirst.Text, LastName = txtLast.Text, Phone = txtPhone.Text, Birth = DateTime.Parse(txtBirth.Text), Country = txtCountry.Text, CreatedDate = DateTime.Now, Admin = false }; try { using (Assignment1Entities db = new Assignment1Entities()) { if (!db.Users.Any(u => u.Email == user.Email)) { db.Users.Add(user); db.SaveChanges(); Session["FullName"] = user.FirstName + ' ' + user.LastName; FormsAuthentication.SetAuthCookie(user.Email, false); Response.Redirect("~/Default.aspx"); } else { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('An account with the email address: " + txtEmail + "already exists.\\nPlease enter a different email address');", true); } } } catch { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('An Error as occurred, please try again later.');", true); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id; Int32.TryParse(Request.QueryString["id"], out id); Assignment1Entities db = new Assignment1Entities(); Post post = db.Posts.FirstOrDefault(p => p.PostId == id); Page.Title = post.Title; Title.Text = post.Title; Author.Text = post.Author; Content.Text = post.HtmlText; CreatedDate.Text = post.CreatedDate.ToString(); comments.DataSource = db.Comments.Where(c => c.Posts_PostId == id).ToList(); comments.DataBind(); } if (this.Page.User.Identity.IsAuthenticated) { AddCommentPanel.Visible = true; } }