protected void addCredits(object sender, EventArgs e) { Button b = sender as Button; int credits = Int32.Parse(b.CommandArgument.ToString()); UserBE user = new UserBE(); user.Nickname = Session["UserNickname"].ToString(); user = user.getUserByNick(); user.Credit += credits; user.update(); Session["UserCredit"] = user.Credit; user = user.getUserByNick(); labelCredits.Text = credits.ToString() + " Credits Added! Now you have " + user.Credit.ToString() + " credits!"; }
protected void send_Message(object sender, EventArgs e) { bool correct = true; if (textuserdest.Text.Length == 0) { userFeedback.Visible = true; correct = false; } else { UserBE user1 = new UserBE("", 0, "", "", textuserdest.Text, ""); UserBE dest = new UserBE(user1.getUserByNick()); if (dest.Email == "") { correct = false; existsFeedback.Visible = true; } } if (textsubject.Text.Length == 0) { subjectFeedback.Visible = true; correct = false; } if (textmessage.Text.Length == 0) { messageFeedback.Visible = true; correct = false; } else if (textmessage.Text.Length > 1000) { lengthFeedback.Visible = true; lengthFeedback.Text = "The message is too long! Delete " + (textmessage.Text.Length - 1000).ToString() + " characters."; correct = false; } if (correct) { String subject = textsubject.Text; String message = textmessage.Text; DateTime date = DateTime.Now; UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE sender1 = new UserBE(user1.getUserByNick()); user1 = new UserBE("", 0, "", "", textuserdest.Text, ""); UserBE addressee = new UserBE(user1.getUserByNick()); MessageBE sndMessage = new MessageBE(sender1, addressee, date, subject, message); sndMessage.sendMessage(); Response.Redirect("ProfileMessages.aspx?Box=Out"); } }
protected void gridResults_RowCommand(Object sender, GridViewCommandEventArgs e) { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Get the last name of the selected author from the appropriate // cell in the GridView control. GridViewRow selectedRow = gridResults.Rows[index]; TableCell codeCell = selectedRow.Cells[6]; int code = int.Parse(codeCell.Text); MessageBE message = MessageDAC.getMessage(code); if (e.CommandName == "View") { Cabecera.Visible = true; Cabecera.Text = "Selected Message Preview:"; Emisor.Visible = true; if (Request.QueryString["Box"] == "Out") Emisor.Text = "To: " + message.Addressee.Nickname; else Emisor.Text = "From: " + message.Sender.Nickname; Fecha.Visible = true; Fecha.Text = "Date: " + message.Date.ToString(); Asunto.Visible = true; Asunto.Text = message.Subject; Texto.Visible = true; Texto.Text = message.Message; if (!message.Read && Request.QueryString["Box"] == "In") { message.openMessage(); Load_Grid(); } } if (e.CommandName == "Delete") { UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE currentUser = new UserBE(user1.getUserByNick()); message.removeMessage(currentUser); if (Request.QueryString["Box"] == "Out") { Response.Redirect("ProfileMessages.aspx?Box=Out"); } else { Response.Redirect("ProfileMessages.aspx?Box=In"); } } }
public static void loadCookie(HttpCookie userCookie) { UserBE user1 = new UserBE("", 0, "", "", userCookie.Value, ""); UserBE user = new UserBE(user1.getUserByNick()); HttpContext.Current.Session["UserNickname"] = user.Nickname; HttpContext.Current.Session["UserName"] = user.Name; HttpContext.Current.Session["UserLastname"] = user.LastName; HttpContext.Current.Session["UserEmail"] = user.Email; HttpContext.Current.Session["UserCredit"] = user.Credit; HttpContext.Current.Session["UserProfpict"] = user.ProfilePicture; }
protected void create_News(object sender, EventArgs e) { NewsBE news = new NewsBE(); news.Title = TitleTB.Text; if (Request.QueryString["code"]!=null) news.Code = Int32.Parse(Request.QueryString["code"]); news.Content = ContentTB.Text; news.PublicationDate = DateTime.Now; UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE author = new UserBE(user1.getUserByNick()); news.Author = author; news.create(); Response.Redirect("NewsAdmin.aspx"); }
protected void create_Project(object sender, EventArgs e) { bool correct = true; if (creditsTextboxProject.Text.Length == 0 || Int32.Parse(creditsTextboxProject.Text) > Int32.Parse(Session["UserCredit"].ToString())) { creditsFeedback.Visible = true; correct = false; } else creditsFeedback.Text = ""; if (correct) { //Project information. String tittle = tittleProjectTextbox.Text; String description = descriptionTextbox.Text; UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE creator = new UserBE(user1.getUserByNick()); int code = -1; DateTime creation = DateTime.Now; DateTime expires = DateTime.MinValue; int credit = Int32.Parse(creditsTextboxProject.Text); DateTime version = DateTime.Now; String gitDir = "There"; //Update the UserBE credits and also the Sessión value. String currentCredits = Session["UserCredit"].ToString(); Session["UserCredit"] = Int32.Parse(currentCredits) - credit; creator.Credit = Int32.Parse(currentCredits) - credit; creator.update(); //Project creation. ProjectBE crProject = new ProjectBE(tittle, description, creator, code, creation, expires, credit, credit, version, gitDir); crProject.create(); crProject.Code = crProject.getLastCode(); //When you create a project, you are contributing to it. ContributionBE contribution = new ContributionBE(creator, crProject, credit, DateTime.Now); contribution.create(); creationFeedback.Text = "Project created successfully!"; creationFeedback.ForeColor = System.Drawing.Color.Green; } }
protected void grid_RowCommand(int code) { MessageBE message = MessageDAC.getMessage(code); UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE currentUser = new UserBE(user1.getUserByNick()); message.removeMessage(currentUser); if (Request.QueryString["Box"] == "Out") { Response.Redirect("ProfileMessages.aspx?Box=Out"); } else { Response.Redirect("ProfileMessages.aspx?Box=In"); } }
protected void Load_Grid() { String order = "code DESC"; if (Request.QueryString["Order"] == "sender" && Request.QueryString["Box"] == "In") order = "sender ASC, code DESC"; else if (Request.QueryString["Order"] == "addressee" && Request.QueryString["Box"] == "Out") order = "addressee ASC, code DESC"; else if (Request.QueryString["Order"] == "isread") order = "isread ASC, code DESC"; else if (Request.QueryString["Order"] == "code_ASC") order = "code ASC"; UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE currentUser = new UserBE(user1.getUserByNick()); DataSet d; if (Request.QueryString["Box"] == "Out") { d = MessageDAC.getSentMessages(currentUser, order); } else { d = MessageDAC.getReceivedMessages(currentUser, order); } gridResults.DataSource = d; gridResults.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { try { lengthFeedback.Visible = false; messageFeedback.Visible = false; HttpCookie userCookie = Request.Cookies["UserNickname"]; if (userCookie != null) SiteMaster.loadCookie(userCookie); if (Session["UserNickname"] == null) { Response.Redirect("Login.aspx"); } else if (!Page.IsPostBack) { if (Request.QueryString["ID"] != null) { new MessageDAC(); MessageBE message = MessageDAC.getMessage(int.Parse(Request.QueryString["ID"])); UserBE user1 = new UserBE("", 0, "", "", Session["UserNickname"].ToString(), ""); UserBE currentUser = new UserBE(user1.getUserByNick()); if (currentUser.Email != "" && currentUser.Email != null && message.Sender != null && message.Addressee != null) { if (message.Sender.Email == currentUser.Email || message.Addressee.Email == currentUser.Email) { gridBefore.DataSource = message.showConversation("Before"); gridBefore.DataBind(); gridAfter.DataSource = message.showConversation("After"); gridAfter.DataBind(); EmisorM.Text = "From: " + message.Sender.Nickname; ReceptorM.Text = "To: " + message.Addressee.Nickname; FechaM.Text = "Date: " + message.Date.ToString(); AsuntoM.Text = message.Subject; TextoM.Text = message.Message; if (message.Addressee.Email != currentUser.Email) replyButton.Visible = false; else message.openMessage(); } else { ErrorM.Visible = true; ErrorM.Text = "This one is not one of your messages. You shouldn't be here."; hideElements(); } } else { ErrorM.Visible = true; ErrorM.Text = "This message doesn't exist. You shouldn't be here."; hideElements(); } } else { Response.Redirect("ProfileMessages.aspx"); } } } catch (Exception) { Response.Redirect("Error.aspx"); } }