Пример #1
0
        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);
            }
        }
Пример #2
0
 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");
         }
     }
 }
Пример #3
0
 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);
     }
 }
Пример #4
0
        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);
            }
        }