public async Task <bool> SendEmail(int fromEmpID, String msgFrom, string msgTo, string Subject, string msgBody) { MailMessage mailMessage = new MailMessage(); string strPassword = ServiceEmployee.GetEmailPasswordForEmployee(fromEmpID); string strEmailAddress = ServiceEmployee.GetEmployeeEmailByID(fromEmpID); string strEmpName = ServiceEmployee.GetEmployeeNameByID(fromEmpID); if (strPassword == string.Empty) { MessageBox.Show("You cannot send Emails, unless you set your valid Password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!new EmailAddressAttribute().IsValid(strEmailAddress)) { MessageBox.Show("It appears that you have not set your Email Address in the Employee database or is Invalid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } mailMessage.From = new MailAddress(strEmailAddress, strEmpName); foreach (var address in msgTo.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { if (new EmailAddressAttribute().IsValid(address)) { mailMessage.To.Add(address); } } if (mailMessage.To.Count == 0) { MessageBox.Show("Invalid number of Recipients or Invalid Email Address", "Terminating", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } mailMessage.Subject = Subject; mailMessage.Body = msgBody; mailMessage.IsBodyHtml = false; //SmtpClient smtp = new SmtpClient(Properties.Settings.Default.EMAIL_SERVER.ToString()); //smtp.Port = int.Parse(Properties.Settings.Default.EMAIL_PORT.ToString()); //smtp.Credentials = new NetworkCredential(strEmailAddress, strPassword); //smtp.EnableSsl = Properties.Settings.Default.EMAIL_ENABLE_SSL; SmtpClient smtp = new SmtpClient(ConfigurationManager.AppSettings["EMAIL_SERVER"].ToString()); smtp.Port = int.Parse(ConfigurationManager.AppSettings["EMAIL_PORT"].ToString()); smtp.Credentials = new NetworkCredential(strEmailAddress, strPassword); smtp.EnableSsl = (ConfigurationManager.AppSettings["EMAIL_ENABLE_SSL"].ToString() == "True") ? true : false; await smtp.SendMailAsync(mailMessage); return(true); }
public async Task <int> AddNewScheduleCall(ScheduleCallAddEditModel model, int createdBy) { string strMessage = string.Empty; string strAssignees = string.Empty; string strRequirements = string.Empty; try { progressForm = new frmProgress(); progressForm.Text = "CREATING A NEW SCHEDULE CALL"; progressForm.lblProgressText.Text = "Inserting a New Business Schecule Call"; progressForm.Show(); Application.DoEvents(); model.DB_MODEL.EntityType = (int)model.SOURCE_ENTITY; model.DB_MODEL.EntityID = (int)model.SOURCE_ENTITY_ID; model.DB_MODEL.CreatedBy = createdBy; model.DB_MODEL.CreatedDatetime = AppCommon.GetServerDateTime(); model.DB_MODEL.Reminder = model.DB_MODEL.Reminder; model.DB_MODEL.IsDeleted = false; model.DB_MODEL.Completed = false; _dbContext.TBL_MP_CRM_ScheduleCallLog.Add(model.DB_MODEL); _dbContext.SaveChanges(); model.ScheduleID = model.DB_MODEL.ScheduleID; progressForm.SetProgress(30, string.Format("\nSuccess ID: {0}\n\nInserting Assignees for this schedule in Database.", model.ScheduleID)); Application.DoEvents(); string mailTo = string.Empty; foreach (MultiSelectListItem item in model.listAssignees) { _dbContext.TBL_MP_CRM_ScheduleCallLogAssignee.Add(new TBL_MP_CRM_ScheduleCallLogAssignee() { EmployeeID = item.ID, IsDeleted = false, ScheduleID = model.ScheduleID }); strAssignees += item.Description.Split('\n')[0] + " , "; _dbContext.SaveChanges(); mailTo += ServiceEmployee.GetEmployeeEmailByID(item.ID) + ";"; } strAssignees = strAssignees.TrimEnd(' ').TrimEnd(','); mailTo += "*****@*****.**"; progressForm.SetProgress(60, string.Format("\nSuccess: {0} Assignee(s) inserted in Database for Schdeule #{1}", model.listAssignees.Count, model.ScheduleID)); progressForm.SetProgress(60, string.Format("\n\n\nSending Email to {0}", mailTo.Replace(";", "; "))); Application.DoEvents(); ServiceEmail mail = new ServiceEmail(); string strSubject = string.Format("New Schedule Call: {0}", model.DB_MODEL.Subject.ToUpper()); switch (model.SOURCE_ENTITY) { case APP_ENTITIES.SALES_LEAD: LeadMasterInfoModel lead = (new ServiceSalesLead(_dbContext)).GetLeadMasterInfo(model.SOURCE_ENTITY_ID); if (lead != null) { strMessage += String.Format("\n\n\nLead No.: {0} dt. {1}\nParty Name: {2}\n", lead.LeadNo, lead.LeadDate.Value.ToString("dd MMMyy"), lead.LeadName); strRequirements = string.Format("Lead Requirements:\n{0}", lead.LeadRequirement); } break; case APP_ENTITIES.SALES_ENQUIRY: TBL_MP_CRM_SalesEnquiry enquiry = (new ServiceSalesEnquiry(_dbContext)).GetEnquiryMasterDBInfo(model.SOURCE_ENTITY_ID); if (enquiry != null) { strMessage += String.Format("\n\n\nEnquiry No.: {0} dt. {1}\nParty Name: {2}\n", enquiry.SalesEnquiry_No, enquiry.SalesEnquiry_Date.ToString("dd MMMyy"), enquiry.Tbl_MP_Master_Party.PartyName); strRequirements = string.Format("Description:\n{0}", enquiry.General_Description); } break; case APP_ENTITIES.SALES_QUOTATION: TBL_MP_CRM_SalesQuotation quotation = (new ServiceSalesQuotation(_dbContext)).GetSalesQuotationMasterDBInfo(model.SOURCE_ENTITY_ID); if (quotation != null) { strMessage += String.Format("\n\n\n Quotation No.: {0} dt. {1}\nParty Name: {2}\n", quotation.Quotation_No, quotation.Quotation_Date.ToString("dd MMMyy"), quotation.Tbl_MP_Master_Party.PartyName); strRequirements = string.Format("Special Note:\n{0}", quotation.SpecialNotes); } break; case APP_ENTITIES.SALES_ORDER: TBL_MP_CRM_SalesOrder order = (new ServiceSalesOrder(_dbContext)).GetSalesOrderDBInfoByID(model.SOURCE_ENTITY_ID); if (order != null) { strMessage += String.Format("\n\n\n Order No.: {0} dt. {1}\nParty Name: {2}\n", order.SalesOrderNo, order.SalesOrderDate.ToString("dd MMMyy"), order.Tbl_MP_Master_Party.PartyName); strRequirements = string.Empty; } break; } strMessage += string.Format("\nContact Person(s) : {0}", model.DB_MODEL.ContactPerson); strMessage += string.Format("\nContact Number(s) : {0}", model.DB_MODEL.ContactNumber); strMessage += string.Format("\nAddress : {0}", model.DB_MODEL.Location); strMessage += string.Format("\n\nSCHEDULE\nSchedule Type: {0}", (new ServiceMASTERS(_dbContext)).GetAllScheduleCallActions().Where(x => x.ID == model.DB_MODEL.ActionID).FirstOrDefault().Description); strMessage += string.Format("\nSchdeule Date: {0}\nSchedule Time:{1}", model.DB_MODEL.StartAt.Value.ToString("dd MMM yyyy"), model.DB_MODEL.StartAt.Value.ToString("hh:mm tt")); strMessage += string.Format("\nPlan/Action: {0}", model.DB_MODEL.Subject.ToUpper()); strMessage += string.Format("\nRemarks: {0}\n", model.DB_MODEL.Remarks); strMessage += string.Format("\nAssigned To : {0}", strAssignees); strMessage += string.Format("\n\n{0}", strRequirements); string strEmailFrom = ServiceEmployee.GetEmployeeEmailByID(createdBy); await mail.SendScheduleCallCreatedEmailNotification(createdBy, strEmailFrom, mailTo, strSubject, strMessage); Application.DoEvents(); progressForm.Close(); this.IsScuccess = true; return(model.ScheduleID); } catch (Exception ex) { MessageBox.Show(ex.Message, "ServiceScheduleCallLog::AddNewScheduleCall", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(model.ScheduleID); }
public async Task <bool> SendFollowUpEmail(int followupID) { bool result = false; string strSubject = string.Empty; string strMessage = string.Empty; string strMailTo = string.Empty; try { TBL_MP_CRM_ScheduleCallLogFollowUp followup = _dbContext.TBL_MP_CRM_ScheduleCallLogFollowUp.Where(x => x.FollowUpID == followupID).FirstOrDefault(); if (followup == null) { MessageBox.Show("Unable to locate a valid Followup"); return(false); } TBL_MP_CRM_ScheduleCallLog schdeule = _dbContext.TBL_MP_CRM_ScheduleCallLog.Where(x => x.ScheduleID == followup.ScheduleID).FirstOrDefault(); if (schdeule == null) { MessageBox.Show("Unable to locate a valid Schedule for the selected FolowUp"); return(false); } strSubject = string.Format("FOLLOWUP- {0}", schdeule.Subject); strMessage += string.Format("REMARKS\n{0}\n", followup.FollowUpRemark); strMessage += string.Format("\nAttended By - {0}", followup.TBL_MP_Master_Employee.EmployeeName); strMessage += string.Format("\nStatus - {0}", followup.TBL_MP_Admin_UserList.Admin_UserList_Desc); if ((bool)followup.NextFollowupRequired) { strMessage += string.Format("\n\nNEXT FOLLOWUP DETAILS\n\n"); strMessage += String.Format("{0}\n", followup.NextFollowUpSubject); strMessage += String.Format("Timings: {0} - {1}\n\n", followup.NextFollowUpStartDatetime.Value.ToString("dd MMM yy hh:mmtt"), followup.NextFollowUpEndDatetime.Value.ToString("dd MMM yy hh:mmtt")); strMessage += String.Format("\nParty Name: {0}", schdeule.CustomerName.ToUpper()); strMessage += String.Format("\nContact: {0}", followup.NextFollowUpContactName.ToUpper()); strMessage += String.Format("\nPhone: {0}", followup.NextFollowUpContactNumber); strMessage += String.Format("\nLocation: {0}\n", followup.NextFollowUpLocation); } else { strMessage += string.Format("\n\nCLIENT INFO.\n"); strMessage += String.Format("\nParty Name: {0}", schdeule.CustomerName.ToUpper()); strMessage += String.Format("\nContact: {0}", schdeule.ContactPerson); strMessage += String.Format("\nPhone: {0}", schdeule.ContactNumber); strMessage += String.Format("\nLocation: {0}\n", schdeule.Location); } strMessage += String.Format("\n\nSOURCE INFO:\n"); switch ((APP_ENTITIES)schdeule.EntityType) { case APP_ENTITIES.SALES_LEAD: TBL_MP_CRM_SM_SalesLead lead = _dbContext.TBL_MP_CRM_SM_SalesLead.Where(x => x.PK_SalesLeadID == schdeule.EntityID).FirstOrDefault(); if (lead != null) { strMessage += String.Format("\nLead: {0} dt. {1}\n", lead.LeadNo, lead.LeadDate.ToString("dd MMM yyyy")); strMessage += String.Format("\n{0}\n", lead.LeadRequirement); } break; } List <TBL_MP_CRM_ScheduleCallLogAssignee> lstAssignees = _dbContext.TBL_MP_CRM_ScheduleCallLogAssignee.Where(x => x.ScheduleID == schdeule.ScheduleID).Where(x => x.IsDeleted == false).ToList(); foreach (TBL_MP_CRM_ScheduleCallLogAssignee ass in lstAssignees) { strMailTo += ass.TBL_MP_Master_Employee.EmailAddress + ";"; } string strMailFrom = ServiceEmployee.GetEmployeeEmailByID((int)followup.CreatedBy); ServiceEmail mail = new ServiceEmail(); await mail.SendEmail((int)followup.CreatedBy, strMailFrom, strMailTo, strSubject, strMessage); result = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "ServiceScheduleCallLog::SendFollowUpEmail", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(result); }
public async Task <bool> UpdateScheduleCall(ScheduleCallAddEditModel model, int empID) { try { progressForm = new frmProgress(); progressForm.Text = "UPDAING SCHEDULE CALL ID: " + model.ScheduleID; progressForm.lblProgressText.Text = "Updating Business Schecule Call Master Info"; progressForm.Show(); Application.DoEvents(); int statusClose = _dbContext.APP_DEFAULTS.Where(x => x.ID == (int)APP_DEFAULT_VALUES.ScheduleCallStatusClose).FirstOrDefault().DEFAULT_VALUE; if (model.DB_MODEL.ScheduleStatus == statusClose) { model.DB_MODEL.Completed = true; } model.DB_MODEL.EntityType = (int)model.SOURCE_ENTITY; model.DB_MODEL.EntityID = (int)model.SOURCE_ENTITY_ID; model.DB_MODEL.ModifiedBy = empID; model.DB_MODEL.ModifiedDatetime = AppCommon.GetServerDateTime(); model.DB_MODEL.Reminder = model.DB_MODEL.Reminder; TBL_MP_CRM_ScheduleCallLog dbModel = _dbContext.TBL_MP_CRM_ScheduleCallLog.Where(x => x.ScheduleID == model.ScheduleID).FirstOrDefault(); if (dbModel != null) { dbModel.Subject = model.DB_MODEL.Subject; dbModel.Priority = model.DB_MODEL.Priority; dbModel.ActionID = model.DB_MODEL.ActionID; dbModel.ScheduleStatus = model.DB_MODEL.ScheduleStatus; dbModel.Completed = model.DB_MODEL.Completed; dbModel.ContactNumber = model.DB_MODEL.ContactNumber; dbModel.ContactPerson = model.DB_MODEL.ContactPerson; dbModel.CustomerName = model.DB_MODEL.CustomerName; dbModel.EndsAt = model.DB_MODEL.EndsAt; dbModel.StartAt = model.DB_MODEL.StartAt; dbModel.Reminder = model.DB_MODEL.Reminder; dbModel.EntityID = model.DB_MODEL.EntityID; dbModel.EntityType = model.DB_MODEL.EntityType; dbModel.ModifiedBy = empID; dbModel.ModifiedDatetime = AppCommon.GetServerDateTime(); dbModel.Remarks = model.DB_MODEL.Remarks; _dbContext.SaveChanges(); } progressForm.SetProgress(25, string.Format("\nSuccess: Updated Schedule Call Information into the Database")); Application.DoEvents(); progressForm.SetProgress(30, string.Format("\nSuccess ID: \n\nUpdating Assignees for this schedule in Database.")); Application.DoEvents(); string mailTo = string.Empty; // MARK ALL ASSIGNEES AS DELETED List <TBL_MP_CRM_ScheduleCallLogAssignee> dbAssignees = _dbContext.TBL_MP_CRM_ScheduleCallLogAssignee.Where(x => x.ScheduleID == model.ScheduleID).ToList(); foreach (TBL_MP_CRM_ScheduleCallLogAssignee item in dbAssignees) { item.IsDeleted = true; } _dbContext.SaveChanges(); // OF EMPLOYEE FOUND SET DELETED=FALSE OR INSERT IF NOT FOUND foreach (MultiSelectListItem item in model.listAssignees) { TBL_MP_CRM_ScheduleCallLogAssignee emp = _dbContext.TBL_MP_CRM_ScheduleCallLogAssignee.Where(x => x.ScheduleID == model.ScheduleID).Where(x => x.EmployeeID == item.ID).FirstOrDefault(); if (emp != null) { emp.IsDeleted = false; } else { _dbContext.TBL_MP_CRM_ScheduleCallLogAssignee.Add(new TBL_MP_CRM_ScheduleCallLogAssignee() { EmployeeID = item.ID, IsDeleted = false, ScheduleID = model.ScheduleID }); } _dbContext.SaveChanges(); mailTo += ServiceEmployee.GetEmployeeEmailByID(item.ID) + ";"; } mailTo += "*****@*****.**"; progressForm.SetProgress(60, string.Format("\nSuccess: {0} Assignee(s) updated in Database for Schdeule #{1}", model.listAssignees.Count, model.ScheduleID)); progressForm.SetProgress(60, string.Format("\n\n\nSending Email to {0}", mailTo.Replace(";", "; "))); Application.DoEvents(); List <SelectListItem> scheduleStatusList = (new ServiceMASTERS()).GetAllScheduleCallsStatus(); ServiceEmail mail = new ServiceEmail(); string strSubject = string.Format("Updated Schedule Call: {0}", model.DB_MODEL.Subject); string strMessage = string.Empty; strMessage += string.Format("{0}\nStatus: {1}", model.DB_MODEL.Subject.ToUpper(), scheduleStatusList.Where(x => x.ID == model.DB_MODEL.ScheduleStatus).FirstOrDefault().Description); strMessage += string.Format("\nRemarks:{0}\n", model.DB_MODEL.Remarks); strMessage += string.Format("\nParty : {0}", model.DB_MODEL.CustomerName); strMessage += string.Format("\nContact Person(s) : {0}", model.DB_MODEL.ContactPerson); strMessage += string.Format("\nContact Number(s) : {0}", model.DB_MODEL.ContactNumber); strMessage += string.Format("\nLocation : {0}", model.DB_MODEL.Location); strMessage += string.Format("\n\nStarts At : {0}", model.DB_MODEL.StartAt.Value.ToString("dd MMMyy hh:mmtt")); strMessage += string.Format("\nEnds At : {0}", model.DB_MODEL.StartAt.Value.ToString("dd MMMyyy hh:mmtt")); switch (model.SOURCE_ENTITY) { case APP_ENTITIES.SALES_LEAD: LeadMasterInfoModel lead = (new ServiceSalesLead(_dbContext)).GetLeadMasterInfo(model.SOURCE_ENTITY_ID); if (lead != null) { strMessage += String.Format("\n\n\nSOURCE INFO.\nLead: {0} dt. {1}\n{2}", lead.LeadNo, lead.LeadDate.Value.ToString("dd MMMyy"), lead.LeadRequirement); } break; } string strEmailAddress = ServiceEmployee.GetEmployeeEmailByID(empID); await mail.SendScheduleCallCreatedEmailNotification(empID, strEmailAddress, mailTo, strSubject, strMessage); Application.DoEvents(); progressForm.Close(); this.IsScuccess = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "ServiceScheduleCallLog::UpdateScheduleCall", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(IsScuccess); }