Ejemplo n.º 1
0
    protected void SubmitBtn_Click(object sender, EventArgs e)
    {
        if (Input.Text != "")
        {
            GaymerLINQDataContext db = new GaymerLINQDataContext();
            LoginLib login = new LoginLib();
            int UserID = login.GetUserID();

            Comment com = new Comment();
            com.AuthorID = UserID;
            com.UserWallID = Convert.ToInt32(Request.QueryString["UserId"]);
            com.CreateTime = DateTime.Now;
            com.Text = Input.Text;
            com.Hidden = false;

            db.Comments.InsertOnSubmit(com);

            try
            {
                db.SubmitChanges();
                BindWall();
                Input.Text = "";
            }
            catch
            {
            }
        }
    }
Ejemplo n.º 2
0
    protected void Wall_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
        LoginLib login = new LoginLib();
        int LoginID = login.GetUserID();
        GaymerLINQDataContext db = new GaymerLINQDataContext();
        var comment = db.Comments.Where(a => a.CommentId == (int)Wall.DataKeys[e.ItemIndex].Value).First();
        if (comment.AuthorID == LoginID)
        {
            ListViewItem item = Wall.Items[e.ItemIndex];
            string UpdateContent = ((TextBox)item.FindControl("EditBox")).Text.ToString();
            Wall.EditIndex = -1;

            var update = db.Comments.Where(a => a.CommentId == (int)Wall.DataKeys[e.ItemIndex].Value).First();
            update.Text = UpdateContent;
            update.UpdateTime = DateTime.Now;

            try { db.SubmitChanges(); }
            catch { }

            var WallContent = from a in db.Comments
                              where a.UserWallID != null ? a.UserWallID == GetActiveWall() : a.AuthorID == GetActiveWall() && !a.Hidden
                              orderby a.CommentId descending
                              select new
                              {
                                  CommentID = a.CommentId,
                                  Username = a.User.Username,
                                  CreatedTime = a.CommentId == (int)Wall.DataKeys[e.ItemIndex].Value ? CreatedTime(DateTime.Now, a.CreateTime) : CreatedTime(a.UpdateTime, a.CreateTime),
                                  Comment = a.CommentId == (int)Wall.DataKeys[e.ItemIndex].Value ? UpdateContent : a.Text,
                                  EditBtnVisible = a.AuthorID == LoginID ? "display:inline;" : "display:none;",
                                  DeleteBtnVisible = a.AuthorID == LoginID ? "display:inline;" : a.UserWallID == LoginID ? "display:inline;" : "display:none;"
                              };
            Wall.DataSource = WallContent;
            Wall.DataBind();
        }
    }
Ejemplo n.º 3
0
    protected void Wall_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        LoginLib login = new LoginLib();
        int LoginID = login.GetUserID();
        GaymerLINQDataContext db = new GaymerLINQDataContext();
        var comment = db.Comments.Where(a => a.CommentId == (int)Wall.DataKeys[e.ItemIndex].Value).First();
        int wallOwnerID = -1;
        if (comment.UserWallID.HasValue)
        {
            wallOwnerID = comment.UserWallID.Value;
        }
        if (wallOwnerID == LoginID || comment.AuthorID == LoginID)
        {
            comment.Hidden = true;
            try { db.SubmitChanges(); }
            catch { }

            var WallContent = from a in db.Comments
                              where a.UserWallID != null ? a.UserWallID == GetActiveWall() : a.AuthorID == GetActiveWall() && !a.Hidden && a.CommentId != (int)Wall.DataKeys[e.ItemIndex].Value
                              orderby a.CommentId descending
                              select new
                              {
                                  CommentID = a.CommentId,
                                  Username = a.User.Username,
                                  CreatedTime = CreatedTime(a.UpdateTime, a.CreateTime),
                                  Comment = a.Text,
                                  EditBtnVisible = a.AuthorID == LoginID ? "display:inline;" : "display:none;",
                                  DeleteBtnVisible = a.AuthorID == LoginID ? "display:inline;" : a.UserWallID == LoginID ? "display:inline;" : "display:none;"
                              };
            Wall.DataSource = WallContent;
            Wall.DataBind();
        }
    }
Ejemplo n.º 4
0
        protected void RegisterBtn_Click(object sender, EventArgs e)
    {
        string Username = RegUsernameBox.Text;
        string Email = RegEmailBox.Text;
        string REmail = RegREmailBox.Text;
        string Password = RegPasswordBox.Text;
        string RPassword = RegRPasswordBox.Text;
        
        if (Email != REmail)
        {
            RegError.Text = "Email don't match";
        }
        else if (Password != RPassword)
        {
            RegError.Text = "Password don't match";
        }
        else
        {
            GaymerLINQDataContext db = new GaymerLINQDataContext();
            //Sjekk om email eller username eksisterer
            var UsernameTest = (from a in db.Users
                                where a.Username == Username
                                select a).FirstOrDefault();
            var EmailTest = (from a in db.Users
                             where a.Mail == Email
                             select a).FirstOrDefault();            
            
            if (UsernameTest == null && EmailTest == null)
            {
                //klar for registrering
                User use = new User();
                use.Username = Username;
                use.Mail = Email;

                Random rand = new Random();
                string salt = rand.Next().ToString();
                byte[] bytee = System.Text.Encoding.Default.GetBytes(Password + salt);
                byte[] byteHash = new SHA1CryptoServiceProvider().ComputeHash(bytee);
                string hash = Convert.ToBase64String(byteHash);

                use.Salt = salt;
                use.Password = hash;

                UserInRole uir = new UserInRole();
                uir.inRoleID = 2;

                use.UserInRoles.Add(uir);

                db.Users.InsertOnSubmit(use);
                db.UserInRoles.InsertOnSubmit(uir);

                try
                {
                    db.SubmitChanges();
                    RegError.Text = "You are now registered";
                    Response.Redirect("/User/UserPage.aspx");
                }
                catch
                {
                    RegError.Text = "General database error";
                }
                finally
                {
                    db.Dispose();
                }
            }
            else if (UsernameTest != null && EmailTest != null)
            {

            }
            else if (UsernameTest != null)
            {

            }
            else if (EmailTest != null)
            {

            }
        }

       
    }
Ejemplo n.º 5
0
    private void ReadUserLINQ()
    {
        GaymerLINQDataContext db = new GaymerLINQDataContext();

        var result = (from a in db.Users
                      select a).FirstOrDefault();
        result.Username = "******";
        db.SubmitChanges();

    }
Ejemplo n.º 6
0
    public void SaveData()
    {
        string AboutMe = AboutMeTxt.Text;
        string fName = UserFirstName.Text;
        string lName = UserLastName.Text;
        DateTime? BirthDate = Birthdate(UserAgeTxtBox.Text);
        bool? sex = GenderConvert(GenderList.SelectedValue);
        string Livingplace = UserLivingPlaceTxtBox.Text;

        GaymerLINQDataContext db = new GaymerLINQDataContext();
        LoginLib login = new LoginLib();
        int userID = Convert.ToInt32(Request.QueryString["UserId"]);
        if (userID == 0)
        {
            userID = login.GetUserID();
        }

        var user = (from a in db.Users
                    where a.UID == userID
                   select a).FirstOrDefault();

        
        if (user.AbID == null)
        {
            UserAbout about = new UserAbout();
            
            about.Birthdate = BirthDate;
            about.FirstName = fName;
            about.LastName = lName;
            about.Gender = sex;
            about.Location = Livingplace;

            about.Users.Add(user);
            db.UserAbouts.InsertOnSubmit(about);
        }
        else
        {
            var about = (from a in db.UserAbouts
                         where a.AbID == user.AbID
                         select a).FirstOrDefault();

            about.Birthdate = BirthDate;
            about.FirstName = fName;
            about.LastName = lName;
            about.Gender = sex;
            about.Location = Livingplace;
        }

        try
        {
            db.SubmitChanges();
        }
        catch (Exception ab)
        {
            Response.Redirect("UserPage.aspx?db_feil");
        }
    }