Esempio n. 1
0
        protected void SendKBArticle_Click(object sender, EventArgs e)
        {
            var from = ServiceContext.GetSiteSettingValueByName(Website, "smtp/from");

            var mail = new MailMessage
            {
                From       = new MailAddress(from),
                Subject    = Article.Title,
                Body       = ArticleContent.Replace("style=\"", "style=\"line-height: normal;").Replace("style='", "style='line-height: normal;"),
                IsBodyHtml = true
            };

            mail.To.Add(toEmailAddresses.Text);

            var smtpServer   = ServiceContext.GetSiteSettingValueByName(Website, "smtp/server");
            var smtpUserName = ServiceContext.GetSiteSettingValueByName(Website, "smtp/userName");
            var smtpPassword = ServiceContext.GetSiteSettingValueByName(Website, "smtp/password");

            var smtp = new SmtpClient(smtpServer)
            {
                Credentials = new NetworkCredential(smtpUserName, smtpPassword)
            };

            smtp.Send(mail);

            var noteSubject = "Note created on " + DateTime.Now + " by " + Contact.FullName;

            var contact = XrmContext.MergeClone(Contact);

            XrmContext.AddNoteAndSave(contact, noteSubject, "Knowledge Base Article titled: " + Article.Title + ", was emailed to " + toEmailAddresses.Text + " on " + DateTime.Now);

            toEmailAddresses.Text = "";

            EmailSentMessage.Text = "Your email has been sent.";
        }
Esempio n. 2
0
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            if (Case == null)
            {
                throw new NullReferenceException("Case must not be null. Update failed.");
            }

            Case.Adx_ModifiedByUsername  = Contact.FullName;
            Case.Adx_ModifiedByIPAddress = Request.UserHostAddress;

            XrmContext.Attach(Case);
            XrmContext.UpdateObject(Case);
            XrmContext.SaveChanges();
            XrmContext.Detach(Case);

            var contactName = Contact.FullName;
            var noteSubject = "Note created on " + DateTime.Now + " by " + contactName;

            if (!string.IsNullOrEmpty(NewNote.Text) || (Attachment.PostedFile != null && Attachment.PostedFile.ContentLength > 0))
            {
                XrmContext.AddNoteAndSave(Case, noteSubject, "*WEB* " + NewNote.Text, Attachment.PostedFile);
            }

            if (System.Web.SiteMap.CurrentNode == null)
            {
                return;
            }

            Response.Redirect(Request.RawUrl);
        }
Esempio n. 3
0
        protected void CreateButton_Click(object sender, EventArgs e)
        {
            var access = ServiceContext.GetCaseAccessByContact(Contact) as Adx_caseaccess;

            if (access == null || !access.Adx_Create.GetValueOrDefault())
            {
                return;                 // no permission to create a case
            }

            PriorityCode.SelectedValue = PriorityCode.Items.FindByText(ServiceContext.GetSiteSettingValueByName(Website, "case/prioritycode")).Value;

            var subject = XrmContext.SubjectSet.First(s => s.Title == ServiceContext.GetSiteSettingValueByName(Website, "case/subject"));

            var incident = new Incident
            {
                Title                  = TitleTextBox.Text,
                PriorityCode           = int.Parse(PriorityCode.SelectedValue),
                CaseTypeCode           = int.Parse(CaseType.SelectedValue),
                SubjectId              = subject.ToEntityReference(),
                CustomerId             = Contact.ToEntityReference(),
                Adx_CreatedByUsername  = Contact.FullName,
                Adx_CreatedByIPAddress = Request.UserHostAddress,
            };

            XrmContext.AddObject(incident);

            XrmContext.SaveChanges();

            var noteSubject = "Note created on " + DateTime.Now + " by " + Contact.FullName;

            XrmContext.AddNoteAndSave(incident, noteSubject, WebAnnotationPrefix + " " + Description.Text, Attachment.PostedFile);

            var page = ServiceContext.GetPageBySiteMarkerName(Website, "Cases");

            Response.Redirect(ServiceContext.GetUrl(page));
        }