initial commit
[CPE_learningsite] / CPE / CPE.App / CPE.App.NotifyConsole / Helpers / AdobeCertificateHelper.cs
1 /*
2 Developer: Tyler Allen
3 Date Created: 08/24/2016
4 ---------------------------------------------------
5 */
6
7 using System;
8 using System.Configuration;
9 using System.Net.Mail;
10 using CPE.App.NotifyConsole.Extensions;
11 using CPE.App.NotifyConsole.Models.Enums;
12
13 namespace CPE.App.NotifyConsole.Helpers {
14     public class EmailCertificateHelper {
15         /// <summary>
16         ///     Email the certificate results to the participant
17         /// </summary>
18         /// <param name="to">Email recipient</param>
19         /// <param name="scoId">Primary key of the meeting room</param>
20         /// <param name="purchaseDate">The date the meeting access was purchased</param>
21         /// <param name="purchaseTicket">The ticket recieved when the meeting room was purchased</param>
22         /// <returns></returns>
23         public static EmailCertificateResults SendWebcastCert(string to, int scoId, DateTime purchaseDate, string purchaseTicket) {
24             var subject = ConfigurationManager.AppSettings["WebcastCertEmailSubject"].Log(message: "Subject");
25             var certUrl = EmailRenderHelper.RenderCertificateLink(scoId, purchaseDate, purchaseTicket)
26                                            .Log(message: "RenderCertificateLink");
27             var body = EmailRenderHelper.RenderWebcastEmail(certUrl)
28                                         .Log(message: "Body");
29             return sendEmail(to, subject, body)
30                 .Log();
31         }
32
33         /// <summary>
34         ///     Send a failure notice to the participant
35         /// </summary>
36         /// <param name="to">Email recipient</param>
37         /// <returns></returns>
38         public static EmailCertificateResults SendFailNotice(string to) {
39             var subject = ConfigurationManager.AppSettings["WebcastFailEmailSubject"].Log(message: "Subject");
40             var body = EmailRenderHelper.RenderFailEmail()
41                                         .Log(message: "Body");
42             return sendEmail(to, subject, body)
43                 .Log();
44         }
45
46         /// <summary>
47         ///     Send email
48         /// </summary>
49         /// <param name="to">Recipient</param>
50         /// <param name="subject">Subject</param>
51         /// <param name="body">Body</param>
52         /// <returns></returns>
53         private static EmailCertificateResults sendEmail(string to, string subject, string body) {
54             try {
55                 var mail = new MailMessage(ConfigurationManager.AppSettings["WebcastEmailSender"], to) {
56                     Subject = subject,
57                     Body = body,
58                     IsBodyHtml = true
59                 };
60                 var client = new SmtpClient {
61                     Port = 25,
62                     DeliveryMethod = SmtpDeliveryMethod.Network,
63                     UseDefaultCredentials = false,
64                     Host = ConfigurationManager.AppSettings["EmailServer"]
65                 };
66                 client.Send(mail);
67             } catch (Exception exception) {
68                 exception.Log(LoggingLevels.Fatal);
69                 return EmailCertificateResults.Fail;
70             }
71
72             return EmailCertificateResults.Success;
73         }
74     }
75 }