public int LogSystemEmailToDB(EmailRequestDto email) { Logger.Instance.LogFunctionEntry(this.GetType().Name, "LogSystemEmailToDB"); if (email == null) return 0; var repo = RepositoryFactory.Get<Email>(); var emailLog = new Email { EmailTypeId = (int)email.EmailType, DocumentLink = "", ToAddress = string.Join(",", email.To.Select(e => e.Address)), SendDate = System.DateTime.Now, IsSuccess = true, UserId = 1, Subject = email.Subject, Body = email.Body }; try { repo.Insert(emailLog); repo.SaveChanges(); } catch (Exception ex) { Logger.Instance.Error(this.GetType().Name, "LogSystemEmailToDB", ex, "Exception logging email to DB"); } Logger.Instance.LogFunctionExit(this.GetType().Name, "LogSystemEmailToDB"); return emailLog.EmailId; }
public int LogEmailToDB(EmailRequestDto email, DateTime sendDate, string fileName) { Logger.Instance.LogFunctionEntry(this.GetType().Name, "LogEmailToDB"); if (email == null) return 0; var repo = RepositoryFactory.Get<Email>(); var emailLog = new Email { EmailTypeId = (int)email.EmailType, DocumentLink = fileName, ToAddress = string.Join(",", email.To.Select(e => e.Address)), SendDate = sendDate, IsSuccess=true, UserId = AuthManager.GetCurrentUserId(), Subject = email.Subject, Body = email.Body, InvoiceId = email.InvoiceId, Url = email.Url }; try { //Note: Some times the client itinerary page was posted twice, so the emails were sent back to back //before sending the email,it will check the cache.If the DTO is not in the cache then the email will be sent if (!string.IsNullOrWhiteSpace(email.EmailIdentifier)) { ICachingManager cachingManager = ServiceLocator.CachingManager; //Check it in the Cache var emails = cachingManager.Get<Email>(email.EmailIdentifier); if (emails != null) { return 0; } else { //Add it to the cache cachingManager.Add<Email>(email.EmailIdentifier, emailLog); } } repo.Insert(emailLog); repo.SaveChanges(); } catch (Exception ex) { Logger.Instance.Error(this.GetType().Name, "LogEmailToDB", ex, "Exception logging email to DB"); } Logger.Instance.LogFunctionExit(this.GetType().Name, "LogEmailToDB"); return emailLog.EmailId; }