Ejemplo n.º 1
0
    protected void btnInclude_Click(object sender, EventArgs e)
    {
        List <ThreadPrivateUser> tpuList = new List <ThreadPrivateUser>();

        foreach (ListItem itm in cblEmployeeList.Items)
        {
            if (itm.Selected)
            {
                ThreadPrivateUser tpu = new ThreadPrivateUser()
                {
                    ThreadID = hdnThreadID.Value.ToInt(),
                    Username = itm.Value
                };
                tpuList.Add(tpu);
            }
        }

        if (tpuList.Count > 0)
        {
            using (ThreadDataContext tdc = new ThreadDataContext())
            {
                tdc.ThreadPrivateUsers.InsertAllOnSubmit(tpuList);
                tdc.SubmitChanges();
            }
        }

        this.LoadPrivateUsers(hdnThreadID.Value.ToInt());
    }
Ejemplo n.º 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");
    }