partial void InsertTicket(Ticket instance)
 {
     instance.LastUpdateBy = HttpContext.Current.User.Identity.GetFormattedUserName();
     instance.LastUpdateDate = DateTime.Now;
     ExecuteDynamicInsert(instance);
     
     
 }
예제 #2
0
        public Ticket GetNewTicket()
        {
            string details = Page.Request.Form["details"];

            Ticket ticket = null;
            if (Page.IsValid)
            {
                if (!string.IsNullOrEmpty(details))
                {
                    DateTime now = DateTime.Now;
                    string user = Page.User.Identity.GetFormattedUserName();
                    ticket = new Ticket();
                    ticket.Type = TypeDropDownList.SelectedValue;
                    ticket.Category = CategoryDropDownList.SelectedValue;
                    ticket.Title = TitleTextBox.Text;
                    ticket.IsHtml = false;
                    ticket.Details = details;
                    if (!string.IsNullOrEmpty(PriorityDropDownList.SelectedValue))
                    {
                        ticket.Priority = PriorityDropDownList.SelectedValue;
                    }
                    string[] tags = TagManager.GetTagsFromString(TagPickerControl.TagList);
                    ticket.TagList = string.Join(",", tags);
                    ticket.AffectsCustomer = AffectsCustomerCheckBox.Checked;
                    ticket.PublishedToKb = false;
                    ticket.CreatedBy = user;
                    ticket.CreatedDate = now;
                    if (CreateOnBehalfTextBox.Checked)
                    {
                        ticket.Owner = OwnerDropDownList.SelectedValue;
                    }
                    else
                    {
                        ticket.Owner = user;
                    }
                    ticket.CurrentStatus = "Active";
                    ticket.CurrentStatusSetBy = user;
                    ticket.CurrentStatusDate = now;


                    TicketComment openingComment = new TicketComment();
                    if (CreateOnBehalfTextBox.Checked)
                    {
                        openingComment.CommentEvent = string.Format("created the ticket on behalf of {0}", SecurityManager.GetUserDisplayName(ticket.Owner));
                    }
                    else
                    {
                        openingComment.CommentEvent = string.Format("created the ticket");
                    }
                    openingComment.CommentedBy = user;
                    openingComment.CommentedDate = now;


                    HttpFileCollection uploadedFiles = Request.Files;

                    for (int i = 0; i < uploadedFiles.Count; i++)
                    {
                        
                        HttpPostedFile userPostedFile = uploadedFiles[i];
                        if (userPostedFile.ContentLength > 0)
                        {
                            TicketAttachment attachment = new TicketAttachment();
                            string fName = Path.GetFileName(userPostedFile.FileName);//FileUploader.FileName;

                            attachment.FileName = fName;
                            var description = Page.Request.Form[fName];
                            if (!string.IsNullOrEmpty(description))
                            {
                                if (description.Length > 500)
                                {
                                    attachment.FileDescription = description.Substring(0, 500);
                                }
                                else
                                {
                                    attachment.FileDescription = description;
                                }
                            }
                            attachment.FileSize = userPostedFile.ContentLength;//FileUploader.PostedFile.ContentLength;
                            string mtype = userPostedFile.ContentType;
                            attachment.FileType = (string.IsNullOrEmpty(mtype) ? "application/octet-stream" : mtype);
                            byte[] fileContent = new byte[userPostedFile.ContentLength];
                            userPostedFile.InputStream.Read(fileContent, 0, userPostedFile.ContentLength);//FileUploader.FileBytes;
                            attachment.FileContents = fileContent;
                            ticket.TicketAttachments.Add(attachment);
                        }
                    }

                    ticket.TicketComments.Add(openingComment);

                    foreach (string tag in tags)
                    {
                        TicketTag tTag = new TicketTag();
                        tTag.TagName = tag;
                        ticket.TicketTags.Add(tTag);
                    }
                }
                else
                {
                    lblDetailsRequired.Visible = true;
                }

            }
            return ticket;
        }
예제 #3
0
 partial void DeleteTicket(Ticket instance);
예제 #4
0
 partial void InsertTicket(Ticket instance);
예제 #5
0
 partial void UpdateTicket(Ticket instance);
예제 #6
0
        private SyndicationItem GetRSSEntryForTicket(Ticket ticket)
        {
            string viewTicket = "/ViewTicket.aspx?id=" + ticket.TicketId.ToString();
            string link = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority +
            HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + viewTicket;
            Uri uri = new Uri(link);

            TextSyndicationContent content = new TextSyndicationContent(GetItemBody(ticket, link), TextSyndicationContentKind.Html);

            SyndicationItem item = new SyndicationItem(ticket.Title, "", uri, ticket.TicketId.ToString(), (DateTimeOffset)ticket.LastUpdateDate);
            item.Content = content;

            return item;
        }
예제 #7
0
        private string GetItemBody(Ticket ticket, string link)
        {
            Page page = new Page();

            StringBuilder stringBuilder = new StringBuilder();
            StringWriter stringWriter = new StringWriter(stringBuilder);
            HtmlTextWriter htmWriter = new HtmlTextWriter(stringWriter);

            EmailTicketView view = (EmailTicketView)page.LoadControl("~/Controls/EmailTicketView.ascx");
            view.TicketToDisplay = ticket;

            view.Populate(link);
            view.RenderControl(htmWriter);

            string body = string.Format("{0}{1}{2}", "<html><head></head><body>", stringBuilder.ToString(), "</body></html>");
            return body;
        }
        private static string GetHTMLComments(Ticket ticket, string userToNotify, int minCommentId)
        {
            StringBuilder commentBuilder = new StringBuilder();
            commentBuilder.Append(@"
            <TR>
            <TD colSpan=2>
                <DIV class=Block>
                    <DIV class=BlockHeader>Activity Log: </DIV>
                    <DIV class=BlockBody>
                    <table class=CommentBoxTable>
            ");

            int repeater = 100;

            foreach (TicketComment tc in ticket.TicketComments.OrderByDescending(t => t.CommentedDate))
            {
                string comment = string.Empty;
                if (repeater > 100)
                {
                    comment += "<tbody><tr><td colspan='2' style='height:10px;'></td></tr></tbody>";
                }

                comment += @"
                         <tbody class='CommentBox'>
                            <tr>
                                <td rowspan='2' runat='server' class='{0}'>
                                    {5}
                                    {1}<br />
                                    <br />
                                    {2}
                                </td>
                                <td class='CommentTitleArea'>
                                    {1}<br />
                                    {2} {3}
                                </td>
                            </tr>
                            <tr>
                                <td class='CommentText'>
                                    {4}
                                </td>
                            </tr>
                         </tbody>";

                string userbackgroundClass = "CommentHead";
                string newCommentHead = string.Empty;

                if (tc.CommentedBy == userToNotify)
                {
                    userbackgroundClass = "UserCommentHead";
                }

                if (tc.CommentId >= minCommentId)
                {
                    newCommentHead = "<div class='NewCommentArea'>New</div>";

                }
                comment = string.Format(comment,
                                        userbackgroundClass,
                                        tc.CommentedDate.ToString("dddd, MM/dd/yyyy hh:mm tt"),
                                        SecurityManager.GetUserDisplayName(tc.CommentedBy),
                                        tc.CommentEvent,
                                        tc.CommentAsHtml,
                                        newCommentHead
                                        );

                //comment = System.String.Format(comment,
                //                                repeater.ToString(),
                //                                tc.CommentedDate.ToString(),
                //                                SecurityManager.GetUserDisplayName(tc.CommentedBy),
                //                                tc.CommentEvent,
                //                                tc.CommentAsHtml,
                //                                backgroundClass,
                //                                userbackgroundClass
                //                                );

                commentBuilder.Append(comment);

                repeater++;
            }

            commentBuilder.Append(@"</table>
                    </DIV>
                </DIV>
            </TD>
            </TR>
            </TBODY>
            </TABLE>
            ");
            return commentBuilder.ToString();
        }
        public static string GetHTMLBody(Ticket ticket, string url, string userToNotify, int minCommentId)
        {
            string viewTicket = string.Format("ViewTicket.aspx?id={0}", ticket.TicketId.ToString());

            url = url.Replace("NewTicket", viewTicket);

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(GetStyle());

            #region Start body
            stringBuilder.Append(@"
            <TABLE style=""WIDTH: 100%"">
            <TBODY>
            <TR>
            <TD style=""VERTICAL-ALIGN: top; WIDTH: 75%"">
                <DIV class=Block>");
            #endregion

            //add url {0} and title {1} placeholders
            #region one
            stringBuilder.Append(@"
                    <DIV class=BlockHeader>
                        <A id=TicketType href=""{0}"">{16}</A> : <A id=TicketTitle href=""{0}"">{1}</A>
                    </DIV>
                    <DIV class=BlockBody style=""HEIGHT: 180px"">
                        <SPAN id=Details>{17}</SPAN>
                    </DIV>
                </DIV>
            </TD>
            ");
            #endregion

            //add Ticket number (ticketid) {2}
            #region two
            stringBuilder.Append(@"
            <TD style=""VERTICAL-ALIGN: top; WIDTH: 25%"">
                <DIV class=Block>
                    <DIV class=BlockHeader>Ticket ID: <A id=TicketId href=""{0}"">{2}</A> </DIV>");
            #endregion

            //add status {3} and priority {4} and category {5}, owner {6), assigned to {7}
            //affects customer {8} and published to kb {9}
            #region three
            stringBuilder.Append(@"
                    <DIV class=BlockBody style=""WHITE-SPACE: nowrap; HEIGHT: 203px"">
                        <TABLE>
                            <TBODY>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Status: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=CurrentStatus>{3}</SPAN>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Priority: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=Priority>{4}</SPAN>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Category: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=Category>{5}</SPAN>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Owned by: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=Owner>{6}</SPAN>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Assigned to: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <A id=AssignedTo>{7}</A>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Affects Customer(s): </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=AffectsCustomer>{8}</SPAN>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Published to KB: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=PublishedToKb>{9}</SPAN>
                                    </TD>
                                </TR>
            ");
            #endregion

            //add tags
            #region tags
            stringBuilder.Append(@"
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Tags: </TD>
            ");

            string tagHtml = String.Format(@"
                                    <TD style=""VERTICAL-ALIGN: top"">
                                        <SPAN id=TagRepeater_ct100_TicketTag>{0}</SPAN>
                                    </TD>
                                </TR>
            ",
                                                ticket.TagList);

            stringBuilder.Append(tagHtml);
            #endregion

            //add Created By {10}, created on {11}, current status by {12},
            //current status on {13}, last update by {14}, and last update on {15}
            #region four
            stringBuilder.Append(@"
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Created by: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=CreatedBy>{10}</SPAN> on: <SPAN id=CreatedDate>{11}</SPAN>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Status set by: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=CurrentStatusBy>{12}</SPAN> on: <SPAN id=CurrentStatusDate>{13}</SPAN>
                                    </TD>
                                </TR>
                                <TR>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap; TEXT-ALIGN: right"">Updated by: </TD>
                                    <TD style=""VERTICAL-ALIGN: top; WHITE-SPACE: nowrap"">
                                        <SPAN id=LastUpdateBy>{14}</SPAN> on: <SPAN id=LastUpdateDate>{15}</SPAN>
                                    </TD>
                                </TR>
                            </TBODY>
                        </TABLE>
                    </DIV>
                </DIV>
            </TD>
            </TR>
            ");
            #endregion

            stringBuilder.Append(GetHTMLAttachments(ticket));

            stringBuilder.Append(GetHTMLComments(ticket, userToNotify, minCommentId));

            string body = stringBuilder.ToString();
            var md = new Markdown();
            body = String.Format(body, //base string
                                    url, // {0}
                                    ticket.Title, // {1}
                                    ticket.TicketId.ToString(), // {2}
                                    ticket.CurrentStatus, // {3}
                                    ticket.Priority, // {4}
                                    ticket.Category, // {5}
                                    SecurityManager.GetUserDisplayName(ticket.Owner), // {6}
                                    SecurityManager.GetUserDisplayName(ticket.AssignedTo), // {7}
                                    BoolToYesNo(ticket.AffectsCustomer),  // {8}
                                    BoolToYesNo(ticket.PublishedToKb), // {9}
                                    SecurityManager.GetUserDisplayName(ticket.CreatedBy), // {10}
                                    ticket.CreatedDate.ToString("g"), // {11}
                                    SecurityManager.GetUserDisplayName(ticket.CurrentStatusSetBy), // {12}
                                    ticket.CurrentStatusDate.ToString("g"), // {13}
                                    SecurityManager.GetUserDisplayName(ticket.LastUpdateBy), // {14}
                                    ticket.LastUpdateDate.ToString("g"), // {15}
                                    ticket.Type, // {16}
                                    ((!ticket.IsHtml) ? md.Transform(ticket.Details, true) : ticket.Details) // {17}
                                    );

            body = string.Format("{0}{1}{2}",
                                    "<html><head></head><body>",
                                    body,
                                    "</body></html>"
                                    );
            return body;
        }
예제 #10
0
        private static string GetHTMLAttachments(Ticket ticket)
        {
            StringBuilder attachBuilder = new StringBuilder();
            attachBuilder.Append(@"
            <TR>
            <TD colSpan=2>
                <DIV class=Block>
                    <DIV class=BlockHeader>Attachments: </DIV>
                    <DIV class=BlockBody style="""">
            ");

            int repeater = 100;

            foreach (TicketAttachment ta in ticket.TicketAttachments)
            {
                string attachment = "";
                if (repeater > 100)
                {
                    attachment += "\n<hr />\n";
                }

                attachment += @"
                                <SPAN id=ttachmentsRepeater_ct{0}_AttachmentLink>{1}</SPAN> -
                                <SPAN id=AttachmentsRepeater_ct{0}_AttachmentUploader>{2}</SPAN> :
                                <SPAN id=AttachmentsRepeater_ct{0}_AttachmentUploadDate>{3}</SPAN>
            ";

                attachment = System.String.Format(attachment,
                                                repeater.ToString(),
                                                ta.FileName,
                                                SecurityManager.GetUserDisplayName(ta.UploadedBy),
                                                ta.UploadedDate.ToShortDateString()
                                                );

                attachBuilder.Append(attachment);
                repeater++;
            }

            attachBuilder.Append(@"
                    </DIV>
                </DIV>
            </TD>
            </TR>
            ");
            return attachBuilder.ToString();
        }