protected void btnPostMessage_Click(object sender, EventArgs e) { string newMessageContent = txtNewMessageContent.Text.Trim(); int expireHours = Parsers.ParseInt(drpMessageExpiry.SelectedValue); DateTime messageExpires = DateTime.Now.AddHours(expireHours); bool isImportant = chkIsHighPriority.Checked; string icon = drpIcon.SelectedValue; if (icon.Length <= 0) { icon = "default.png"; } if (newMessageContent.Length > 0) { // Get the current logged in user LoginSessionRepository loginRepository = new LoginSessionRepository(); string foundUserSessionID = loginRepository.GetSessionIDFromCookies(Request); LoginSession currentUser = loginRepository.LoadIfValid(foundUserSessionID, Request.ServerVariables["REMOTE_ADDR"], Request.ServerVariables["HTTP_USER_AGENT"]); if (currentUser != null) { ShopMessageRepository messageRepo = new ShopMessageRepository(); ShopMessage msg = messageRepo.Add(currentUser.Username, newMessageContent, DateTime.Now, messageExpires, isImportant, icon); tblActiveMessages.Rows.Add(addMessageTableRow(msg)); } } }
protected void Page_Load(object sender, EventArgs e) { // Check to see if we need to delete any messages // Remember to delete them from the ones displayed in the table too, or the user will still see them // load active messages in the table and provide button links to delete them ShopMessageRepository messageRepo = new ShopMessageRepository(); if (Request.QueryString["remove"] != null) { int removeID = Parsers.ParseInt(Request.QueryString["remove"].ToString().Trim()); if (removeID > 0) { messageRepo.Delete(removeID); } } List <ShopMessage> activeMessages = messageRepo.GetActive(); tblActiveMessages.Rows.Clear(); tblActiveMessages.Rows.Add(addMessageTableHeaderRow()); foreach (ShopMessage msg in activeMessages) { tblActiveMessages.Rows.Add(addMessageTableRow(msg)); } if (!IsPostBack) { chkIsHighPriority.Checked = true; IconRepository iconRepo = new IconRepository(); drpIcon.Items.Clear(); drpIcon.Items.Add(new ListItem() { Text = "default.png", Value = "default.png" }); foreach (string icon in iconRepo.GetAll()) { drpIcon.Items.Add(new ListItem() { Text = icon, Value = icon }); } } }
protected void Page_Load(object sender, EventArgs e) { ShopMessageRepository msgRepo = new ShopMessageRepository(); List <ShopMessage> activeMessages = msgRepo.GetActive(); List <ShopMessage> NormalPriority = activeMessages.Where(x => x.IsImportant == false).ToList(); List <ShopMessage> HighPriority = activeMessages.Where(x => x.IsImportant == true).ToList(); Response.Clear(); Response.ContentEncoding = Encoding.UTF8; Response.ContentType = "application/json; charset=utf-8"; Response.Write("{"); Response.Write(" \"Normal\": "); Response.Write("[\n"); int counter = 0; foreach (ShopMessage msg in NormalPriority) { Response.Write("{"); Response.Write("\"ID\":\"" + msg.ID + "\",\n"); Response.Write("\"Sender\":\"" + Helpers.SanitizeForJSON(msg.Sender) + "\",\n"); Response.Write("\"Icon\":\"" + msg.Icon + "\",\n"); Response.Write("\"Content\":\"" + Helpers.SanitizeForJSON(msg.Content) + "\",\n"); Response.Write("\"Created\":\"" + msg.Created + "\",\n"); Response.Write("\"CreatedFriendly\":\"" + Helpers.TimeSince(msg.Created) + "\",\n"); Response.Write("\"StartTime\":\"" + msg.Start + "\",\n"); Response.Write("\"EndTime\":\"" + msg.End + "\",\n"); Response.Write("\"IsImportant\":" + msg.IsImportant.ToString().ToLower() + "\n"); Response.Write("}"); counter++; if (counter < NormalPriority.Count) { Response.Write(","); } } Response.Write("],\n"); Response.Write(" \"High\": "); Response.Write("[\n"); counter = 0; foreach (ShopMessage msg in HighPriority) { Response.Write("{"); Response.Write("\"ID\":\"" + msg.ID + "\",\n"); Response.Write("\"Sender\":\"" + Helpers.SanitizeForJSON(msg.Sender) + "\",\n"); Response.Write("\"Icon\":\"" + msg.Icon + "\",\n"); Response.Write("\"Content\":\"" + Helpers.SanitizeForJSON(msg.Content) + "\",\n"); Response.Write("\"Created\":\"" + msg.Created + "\",\n"); Response.Write("\"CreatedFriendly\":\"" + Helpers.TimeSince(msg.Created) + "\",\n"); Response.Write("\"StartTime\":\"" + msg.Start + "\",\n"); Response.Write("\"EndTime\":\"" + msg.End + "\",\n"); Response.Write("\"IsImportant\":" + msg.IsImportant.ToString().ToLower() + "\n"); Response.Write("}"); counter++; if (counter < HighPriority.Count) { Response.Write(","); } } Response.Write("]\n"); Response.Write("}"); Response.End(); }