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 { } } }
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"); } }
public void FillData() { LoginLib login = new LoginLib(); int userID = Convert.ToInt32(Request.QueryString["UserId"]); if (userID == 0) { userID = login.GetUserID(); } GaymerLINQDataContext db = new GaymerLINQDataContext(); var user = (from a in db.Users where a.UID == userID select new { Uname = a.Username, Firstname = a.UserAbout.FirstName, Lastname = a.UserAbout.LastName, Avatar = a.Avatar, AboutMe = "", Birthdate = a.UserAbout.Birthdate, Sex = a.UserAbout.Gender, Living = "" }).FirstOrDefault(); Username.Text = user.Uname; MyAvatar.ImageUrl = "~/user/ViewAvatar.aspx?uid=" + userID; MyAvatar.AlternateText = user.Uname + " Avatar"; AboutMeTxt.Text = user.AboutMe; UserFirstName.Text = user.Firstname; UserLastName.Text = user.Lastname; if (user.Birthdate.HasValue) { UserAgeTxtBox.Text = user.Birthdate.Value.Year + "-" + user.Birthdate.Value.Month + "-" + user.Birthdate.Value.Day; } if (user.Sex == null) { GenderList.SelectedValue = "null"; } else if (user.Sex == true) { GenderList.SelectedValue = "true"; } else { GenderList.SelectedValue = "false"; } UserLivingPlaceTxtBox.Text = user.Living; }
private void BindWall() { LoginLib login = new LoginLib(); int LoginID = login.GetUserID(); GaymerLINQDataContext db = new GaymerLINQDataContext(); 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 = 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(); }
public void FillData() { LoginLib login = new LoginLib(); int userID = getVisitedUserId(); if (userID < 0) { userID = login.GetUserID(); } GaymerLINQDataContext db = new GaymerLINQDataContext(); var user = (from a in db.Users where a.UID == userID select new { Uid = a.UID, Uname = a.Username, Firstname = a.UserAbout.FirstName, Lastname = a.UserAbout.LastName, Avatar = a.Avatar, AboutMe = "", Birthdate = a.UserAbout.Birthdate, Sex = a.UserAbout.Gender, Living = "" }).FirstOrDefault(); // Henter ut brukerens rolle fra databasen. var userRole = (from UserInRoles in db.UserInRoles from Roles in db.Roles where UserInRoles.inUserID == user.Uid && UserInRoles.inRoleID == Roles.RoleID //Finner "rett" bruker i UserInRole. select new { URole = UserInRoles.inRoleID }).FirstOrDefault(); var rolle = (from Roles in db.Roles where Roles.RoleID == userRole.URole select new { BrukerRolle = Roles.Role1 }).FirstOrDefault(); lblRolle.Text = rolle.BrukerRolle; Username.Text = user.Uname; MyAvatar.ImageUrl = "~/user/ViewAvatar.aspx?uid=" + userID; MyAvatar.AlternateText = user.Uname + " Avatar"; AboutMeTxt.Text = user.AboutMe; UsersNameTxt.Text = user.Firstname + " " + user.Lastname; UserAgeTxt.Text = AgeYr(user.Birthdate).ToString(); UserSexTxt.Text = user.Sex == null ? "Undefined" : user.Sex == true ? "Woman" : "Man"; UserLivingPlaceTxt.Text = user.Living; //Finne alle venner/relasjoner Dictionary<String, object> parameter = new Dictionary<string, object>(); parameter.Add("@UserID", userID); DataTable dt = ManageDB.query(@" SELECT [User].Username, [User].UID FROM [User],UserRelation WHERE UserRelation.UserId = @UserID AND [User].UID = UserRelation.RelatedUserId ", parameter, debug: true); FriendView.DataSource = dt; FriendView.DataBind(); if (userID == login.GetUserID() || isFriend(login.GetUserID(), userID)) FriendRequestbtn.Visible = false; }
public void SendRequest(int userID) { if (userID < 0) { // FEIL } LoginLib login = new LoginLib(); int visitedUserId = -1; if (userID != login.GetUserID()) { visitedUserId = userID; } GaymerLINQDataContext db = new GaymerLINQDataContext(); //var meldinger = (from pm in db.PrivateMessages // where pm.From == login.GetUserID() // select pm).FirstOrDefault(); PrivateMessage pmeld = new PrivateMessage(); int userId= login.GetUserID(); pmeld.To = visitedUserId; pmeld.Text = "Friend request"; DateTime Time = System.DateTime.Now; pmeld.Read = false; var p = new Dictionary<string, object>(); p.Add("@UserId", userId); p.Add("@VisitUserId", visitedUserId); p.Add("@Time",Time); int nyrequest = ManageDB.nonQuery(@" INSERT INTO PrivateMessage([From],[To],[Text],Time,[Read]) VALUES (@UserId,@VisitUserId,'Friend request',@Time,'False')",p,debug:true); //db.PrivateMessages.InsertOnSubmit(meldinger); //try //{ // db.SubmitChanges(); //} //catch (Exception ab) //{ // Response.Redirect("UserPage.aspx?db_feil"); //} }
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(); } }
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(); } }
protected void Wall_ItemEditing(object sender, ListViewEditEventArgs 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.NewEditIndex].Value).First(); if (comment.AuthorID == LoginID) { Wall.EditIndex = e.NewEditIndex; 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 = 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(); ListViewItem item = Wall.Items[e.NewEditIndex]; TextBox EditBox = (TextBox)item.FindControl("EditBox"); EditBox.Text = WallContent.FirstOrDefault(p => p.CommentID == (int)Wall.DataKeys[e.NewEditIndex].Value).Comment; } }
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) { } } }
private void ReadUserLINQ() { GaymerLINQDataContext db = new GaymerLINQDataContext(); var result = (from a in db.Users select a).FirstOrDefault(); result.Username = "******"; db.SubmitChanges(); }