public ApplicationLog Create(ApplicationLog objectToCreate) { //throw new NotImplementedException(); repository.Add(objectToCreate); Save(); return(objectToCreate); }
private void AppLogManager(string source, string type, string errMsg) { ApplicationLog log = new ApplicationLog(); log.Source = source.ToString(); log.Type = type; log.Description = errMsg.ToString(); log.CreatedDate = DateTime.Now; _applicationLogs.Add(log); _applicationLogs.Save(); }
public void SendEmail(string[] to, string[] cc, string[] bcc, int emailTemplateID, Hashtable param, string userID) { try { EmailTemplate emailTemplate = _serviceEmailTemplate.GetById(emailTemplateID); param.Add("%TemplateName", emailTemplate.Description); string subject = emailTemplate.Subject; string emailBody = emailTemplate.Body; //replace the tags with actual values if (param != null) { foreach (DictionaryEntry p in param) { if (emailTemplate.Subject.Contains(p.Key.ToString())) { subject = subject.Replace(p.Key.ToString(), p.Value.ToString()); } if (emailTemplate.Body.Contains(p.Key.ToString())) { emailBody = emailBody.Replace(p.Key.ToString(), p.Value.ToString()); } } } else { subject = emailTemplate.Subject; emailBody = emailTemplate.Body; } //save the email in the queue table to be sent later on if (!string.IsNullOrEmpty(subject) && !string.IsNullOrEmpty(emailBody)) { EmailQueue emailQueue = new EmailQueue(); if (to != null) { if (to.Length > 0) { foreach (string toAddress in to) { emailQueue.Recipient = emailQueue.Recipient + toAddress + ","; } //remove the last comma emailQueue.Recipient = emailQueue.Recipient.Remove(emailQueue.Recipient.LastIndexOf(",")); } } if (cc != null) { if (cc.Length > 0) { foreach (string ccAddress in cc) { emailQueue.CC = ccAddress + ","; } //remove the last comma emailQueue.CC = emailQueue.CC.Remove(emailQueue.CC.LastIndexOf(",")); } } else { emailQueue.CC = ""; } if (bcc != null) { if (bcc.Length > 0) { foreach (string bccAddress in cc) { emailQueue.Bcc = bccAddress + ","; } //remove the last comma emailQueue.Bcc = emailQueue.Bcc.Remove(emailQueue.Bcc.LastIndexOf(",")); } } else { emailQueue.Bcc = ""; } DateTime currentDateTime = DateTime.Now; emailQueue.ToUserID = userID; emailQueue.Subject = subject; emailQueue.Email = emailBody; emailQueue.IsSent = false; emailQueue.CreatedDate = currentDateTime; emailQueue.SentDate = currentDateTime; try { if (!emailQueue.IsSent) { SendEmail(emailQueue.Recipient, emailQueue.CC.ToString(), emailQueue.Bcc, emailQueue.Subject, emailQueue.Email); emailQueue.IsSent = true; emailQueue.SentDate = DateTime.Now; _serviceEmailQueue.Add(emailQueue); _serviceEmailQueue.Save(); } } catch (Exception ex) { ApplicationLog log = new ApplicationLog(); log.CreatedDate = DateTime.UtcNow; log.Source = ex.Source; log.Type = "Error in Sending Email."; log.Description = ex.Message; _serviceAppLog.Add(log); _serviceAppLog.Save(); } } } catch (Exception ex) { ApplicationLog log = new ApplicationLog(); log.CreatedDate = DateTime.UtcNow; log.Source = ex.Source; log.Type = "Error in Sending Email."; log.Description = ex.Message; _serviceAppLog.Add(log); _serviceAppLog.Save(); } }