protected void Page_Load(object sender, EventArgs e) { LoginLib login = new LoginLib(); if (!IsPostBack) { //Full Callback if (!login.IsUserLoggedIn()) { Response.Redirect("/StartPage.aspx"); } else { Normal.FillData(); } } else { //Async Callback } int qUserId; string userIdString = Request.QueryString["UserId"]; Int32.TryParse(userIdString, out qUserId); ModifySelf.Visible = false; if (ManageDB.UserHasPermission("Gaymer_EditUser", login.GetUserID()) || login.GetUserID() != qUserId) { ModifySelf.Visible = true; } }
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"); } }
private int GetActiveWall() { LoginLib login = new LoginLib(); int UserID = Convert.ToInt32(Request.QueryString["UserId"]); if (UserID == 0) { UserID = login.GetUserID(); } return UserID; }
protected void avatarbtn_Click(object sender, EventArgs e) { if (this.Fileuploade.HasFile) { LoginLib Log = new LoginLib(); Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("@ImgBody", ConvertImageToByteArray(this.Fileuploade)); parameters.Add("@UID", Log.GetUserID()); int i = ManageDB.nonQuery("UPDATE [User] SET Avatar =@ImgBody WHERE UID= @UID", parameters); if (i != 0) { AvatarImg.ImageUrl = "/User/ViewAvatar.aspx?uid=" + Log.GetUserID(); } else errorlbl.Text += "Fil ikke lastet opp"; } }
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; }
public void VenstreFill() { //Finner brukere som har sendt "deg" meldinger LoginLib login = new LoginLib(); int useID = login.GetUserID(); Dictionary<String, object> parameter = new Dictionary<string, object>(); parameter.Add("@UserID", useID); DataTable dt = ManageDB.query(@" SELECT [User].Username,PrivateMessage.[Read] FROM PrivateMessage,[User] WHERE PrivateMessage.[To] = @UserID AND PrivateMessage.[From] = [User].UID ", parameter, debug: true); MeldBrukere.DataSource = dt; MeldBrukere.DataBind(); }
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 HoyreFill() { //Viser meldinger fra valgt bruker LoginLib login = new LoginLib(); int useID = login.GetUserID(); Dictionary<String, object> parameter = new Dictionary<string, object>(); parameter.Add("@UserID", useID); DataTable dt = ManageDB.query(@" SELECT Text,Time,Read FROM PrivateMessage WHERE [From]=@UserID AND [To]=@klikkID", parameter, debug: true); PrivateMessage pm = new PrivateMessage(); //if (pm.Text == "Friend request") //{ // MeldingerGV. //} }
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; } }
private void rendreAdminMenu(LoginLib login) { if (ManageDB.UserHasPermission(Permissions.Gaymer_View_Admin_Menu, login.GetUserID())) { MenuItem rootAdminMenu = new MenuItem(); rootAdminMenu.Text = "Admin"; rootAdminMenu.NavigateUrl = "~/Online/Student/FagListe.aspx"; rootAdminMenu.Selectable = false; Menu.Items.Add(rootAdminMenu); MenuItem m; if (ManageDB.UserHasPermission(Permissions.Gaymer_Manage_Roles, login.GetUserID())) { m = new MenuItem(); m.Text = "Roller"; m.NavigateUrl = "~/Admin/Roles.aspx"; rootAdminMenu.ChildItems.Add(m); } if (ManageDB.UserHasPermission(Permissions.Gaymer_Manage_Users, login.GetUserID())) { m = new MenuItem(); m.Text = "Users"; m.NavigateUrl = "~/Admin/Users.aspx"; rootAdminMenu.ChildItems.Add(m); } if (ManageDB.UserHasPermission(Permissions.Gaymer_Manage_Content_Type, login.GetUserID())) { m = new MenuItem(); m.Text = "Content types"; m.NavigateUrl = "~/Admin/ListContentTypes.aspx"; rootAdminMenu.ChildItems.Add(m); } } }