public static async Task addEmailToCache(EmailCacheModel ECM) { using (WebDocs.DataAccessLayer.WebDocsEntities db = new DataAccessLayer.WebDocsEntities()) { ECM.EntityState = DomainModels.EntityState.Added; db.EmailCacheModels.Add(ECM); await db.SaveChangesAsync(); } }
private void SendEmail(EmailCacheModel EC, EmailSetting ES) { Boolean SentSuccsessfully; try { Common.Helper.Email.EmailHelper.sendMessage( _ToAddress: EC.EmailRecipient.Email, _FromAddress: EC.EmailSender.Email, _ToName: EC.EmailRecipient.UserFullName, _FromName: EC.EmailSender.UserFullName, _Subject: EC.EmailSubject, _Message: EC.EmailMessage, _SMTP_HOST: ES.SmtpHost, _SMTP_PORT: ES.SmtpPort, _IsSsl: ES.SslEnabled, _Credentials_Password: ES.Password, _Credentials_UserName: ES.UserName ); SentSuccsessfully = true; //Common.WindowsServices.ServiceLogFiles.WrtieToLog("11111111111111111111Successfully Sent Email for: " + EC.EmailRecipient.UserFullName + " From: " + EC.EmailSender.UserFullName + " - email Cahce Item: " + EC.EmailCacheID); } catch { SentSuccsessfully = false; // Common.WindowsServices.ServiceLogFiles.WrtieToLog("11111111111111111111111111111Failed Sent Email for: " + EC.EmailRecipient.UserFullName + " From: " + EC.EmailSender.UserFullName + " - email Cahce Item: " + EC.EmailCacheID); } using (WebDocs.DataAccessLayer.WebDocsEntities db = new DataAccessLayer.WebDocsEntities()) { if (SentSuccsessfully) { EC.HasBeenSent = true; db.EmailCacheModels.Attach(EC); db.Entry(EC).State = EntityState.Modified; db.SaveChanges(); //Common.WindowsServices.ServiceLogFiles.WrtieToLog("Successfully Updated Email for: " + EC.EmailRecipient.UserFullName + " From: " + EC.EmailSender.UserFullName + " - email Cahce Item: " + EC.EmailCacheID); } else { if (EC.RetryAttempt < 5) { EC.RetryAttempt = EC.RetryAttempt + 1; db.EmailCacheModels.Attach(EC); db.Entry(EC).State = EntityState.Modified; db.SaveChanges(); //Common.WindowsServices.ServiceLogFiles.WrtieToLog("222222222222222222222222Failed to Update Email for: " + EC.EmailRecipient.UserFullName + " From: " + EC.EmailSender.UserFullName + " - email Cahce Item: " + EC.EmailCacheID); } } } }