예제 #1
0
    private void SaveReply()
    {
        bool              isSuccess = false;
        string            username  = Request.Cookies["Speedo"]["UserName"];
        int               threadID  = Request.QueryString["threadid"].ToInt();
        ThreadDataContext sdc       = new ThreadDataContext();

        try
        {
            ThreadReply tr = new ThreadReply
            {
                ThreadID      = threadID,
                Username      = username,
                ReplyContents = ckeReply.Text,
                DateReply     = DateTime.Now
            };

            sdc.ThreadReplies.InsertOnSubmit(tr);
            sdc.SubmitChanges();
            isSuccess = true;
        }
        catch (Exception ex)
        {
            DALPortal.LogError(username, MethodBase.GetCurrentMethod().ReflectedType.ToString(), MethodBase.GetCurrentMethod().Name, ex.Message);
        }
        finally
        {
            sdc.Dispose();
        }

        if (isSuccess)
        {
            Response.Redirect("Thread.aspx?threadid=" + threadID.ToString() + "&page=1");
        }
    }
예제 #2
0
    private void InsertRecord()
    {
        string username = Request.Cookies["Speedo"]["UserName"];

        ThreadDataContext sdc = new ThreadDataContext();

        try
        {
            Thread thread = new Thread
            {
                ThreadCategoryID = ddlCategory.SelectedValue.ToInt(),
                ThreadTypeID     = ddlType.SelectedValue.ToInt(),
                Title            = txtTitle.Text,
                Description      = txtDescription.Text,
                Contents         = ckeContents.Text,
                IsAllowedReply   = chkIsAllowReply.Checked,
                IsPosted         = chkPostAnnouncement.Checked,
                IsPrivate        = chkIsPrivate.Checked,
                IsActive         = true,
                IsSticky         = false,
                PostedBy         = username,
                PostedDate       = DateTime.Now,
                LastPostBy       = username,
                LastPostDate     = DateTime.Now,
                TotalReply       = 0
            };

            if (fuAttachment.HasFile)
            {
                string fileName = System.Guid.NewGuid().ToString() + "." + Path.GetExtension(fuAttachment.FileName);
                fuAttachment.SaveAs(Server.MapPath(@"~\App_Attachments\" + fileName));
                thread.AttachedFileName        = fileName;
                thread.AttachedFileDescription = (txtAttachment.Text.Length == 0 ? "Attached File" : txtAttachment.Text);
            }

            sdc.Threads.InsertOnSubmit(thread);
            sdc.SubmitChanges();

            if (chkIsPrivate.Checked)
            {
                foreach (ListItem itm in cblThreadMembers.Items)
                {
                    ThreadPrivateUser tpu = new ThreadPrivateUser()
                    {
                        ThreadID = thread.ThreadID,
                        Username = itm.Value
                    };

                    sdc.ThreadPrivateUsers.InsertOnSubmit(tpu);
                }
            }

            sdc.SubmitChanges();
        }
        catch (Exception ex)
        {
            DALPortal.LogError(username, MethodBase.GetCurrentMethod().ReflectedType.ToString(), MethodBase.GetCurrentMethod().Name, ex.Message);
        }
        finally
        {
            sdc.Dispose();
        }

        Response.Redirect("ThreadList.aspx?categoryid=" + Request.QueryString["categoryid"] + "&page=1");
    }