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> 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); }