Exemple #1
0
        public ActionResult CTP060_UpdateEmailContentOfNotifyEmail()
        {
            ObjectResultData        res                  = new ObjectResultData();
            IContractHandler        conHandler           = ServiceContainer.GetService <IContractHandler>() as IContractHandler;
            IRentralContractHandler rentalConHandler     = ServiceContainer.GetService <IRentralContractHandler>() as IRentralContractHandler;
            IMasterHandler          masterHandler        = ServiceContainer.GetService <IMasterHandler>() as IMasterHandler;
            IEmployeeMasterHandler  empMasterHandler     = ServiceContainer.GetService <IEmployeeMasterHandler>() as IEmployeeMasterHandler;
            IBillingMasterHandler   billingmasterhandler = ServiceContainer.GetService <IBillingMasterHandler>() as IBillingMasterHandler;
            IOfficeMasterHandler    officehandler        = ServiceContainer.GetService <IOfficeMasterHandler>() as IOfficeMasterHandler;
            IBillingHandler         billinghandler       = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;

            List <tbm_Customer>  dtCustomer;
            List <doGetTbm_Site> dtSite;
            List <tbm_Employee>  dtEmployee;
            decimal?contractFeeBeforeChange;
            decimal?ChangeContractFee;

            try
            {
                CommonUtil comUtil = new CommonUtil();
                doNotifyChangeFeeContract doNotifyEmail           = new doNotifyChangeFeeContract();
                List <tbt_ContractEmail>  updateContractEmailList = new List <tbt_ContractEmail>();

                using (TransactionScope scope = new TransactionScope())
                {
                    List <tbt_ContractEmail> contractEmailList = conHandler.GetUnsentNotifyEmail();
                    foreach (tbt_ContractEmail data in contractEmailList)
                    {
                        List <tbt_BillingBasic>  doBillingBasic  = billinghandler.GetTbt_BillingBasic(data.ContractCode, "01");
                        List <tbt_BillingTarget> doBillingTarget = billinghandler.GetTbt_BillingTarget(doBillingBasic[0].BillingTargetCode, null, null);

                        dsRentalContractData dsRentalContract = rentalConHandler.GetEntireContract(data.ContractCode, data.OCC);
                        if (dsRentalContract.dtTbt_RentalSecurityBasic[0].ReturnToOriginalFeeDate != null)
                        {
                            var operationOfficeDat = officehandler.GetTbm_Office(dsRentalContract.dtTbt_RentalContractBasic[0].OperationOfficeCode);
                            var billingOfficeDat   = officehandler.GetTbm_Office(doBillingTarget[0].BillingOfficeCode);

                            EmailTemplateUtil mailUtil = new EmailTemplateUtil(EmailTemplateName.C_EMAIL_TEMPLATE_NAME_CHANGE_FEE);
                            dtCustomer = masterHandler.GetTbm_Customer(dsRentalContract.dtTbt_RentalContractBasic[0].ContractTargetCustCode);
                            dtSite     = masterHandler.GetTbm_Site(dsRentalContract.dtTbt_RentalContractBasic[0].SiteCode);
                            dtEmployee = empMasterHandler.GetTbm_Employee(data.CreateBy);
                            contractFeeBeforeChange = rentalConHandler.GetContractFeeBeforeChange(dsRentalContract.dtTbt_RentalContractBasic[0].ContractCode, dsRentalContract.dtTbt_RentalSecurityBasic[0].OCC, dsRentalContract);

                            doNotifyEmail.ContractCode            = comUtil.ConvertContractCode(dsRentalContract.dtTbt_RentalContractBasic[0].ContractCode, CommonUtil.CONVERT_TYPE.TO_SHORT);
                            doNotifyEmail.ContractTargetNameEN    = dtCustomer[0].CustFullNameEN;
                            doNotifyEmail.ContractTargetNameLC    = dtCustomer[0].CustFullNameLC;
                            doNotifyEmail.SiteNameEN              = dtSite[0].SiteNameEN;
                            doNotifyEmail.SiteNameLC              = dtSite[0].SiteNameLC;
                            doNotifyEmail.ChangeDateOfContractFee = CommonUtil.TextDate(dsRentalContract.dtTbt_RentalSecurityBasic[0].ChangeImplementDate);
                            doNotifyEmail.ContractFeeBeforeChange = CommonUtil.TextNumeric(contractFeeBeforeChange);

                            if (dsRentalContract.dtTbt_RentalContractBasic[0].ContractStatus == ContractStatus.C_CONTRACT_STATUS_STOPPING)
                            {
                                ChangeContractFee = dsRentalContract.dtTbt_RentalSecurityBasic[0].ContractFeeOnStop;
                            }
                            else
                            {
                                ChangeContractFee = dsRentalContract.dtTbt_RentalSecurityBasic[0].OrderContractFee;
                            }

                            doNotifyEmail.ContractFeeAfterChange  = CommonUtil.TextNumeric(ChangeContractFee);
                            doNotifyEmail.ReturnToOriginalFeeDate = CommonUtil.TextDate(dsRentalContract.dtTbt_RentalSecurityBasic[0].ReturnToOriginalFeeDate);
                            doNotifyEmail.OperationOfficeEN       = operationOfficeDat[0].OfficeNameEN;
                            doNotifyEmail.OperationOfficeLC       = operationOfficeDat[0].OfficeNameLC;
                            doNotifyEmail.RegisterChangeEmpNameEN = dtEmployee[0].EmpFirstNameEN + ' ' + dtEmployee[0].EmpLastNameEN;
                            doNotifyEmail.RegisterChangeEmpNameLC = dtEmployee[0].EmpFirstNameLC + ' ' + dtEmployee[0].EmpLastNameLC;
                            doNotifyEmail.BillingOfficeEN         = billingOfficeDat[0].OfficeNameEN;
                            doNotifyEmail.BillingOfficeLC         = billingOfficeDat[0].OfficeNameLC;

                            var mailTemplate = mailUtil.LoadTemplate(doNotifyEmail);
                            data.EmailContent = mailTemplate.TemplateContent;

                            tbt_ContractEmail conEmailTemp = CommonUtil.CloneObject <tbt_ContractEmail, tbt_ContractEmail>(data);
                            updateContractEmailList.Add(conEmailTemp);
                        }
                    }

                    if (updateContractEmailList != null && updateContractEmailList.Count > 0)
                    {
                        conHandler.UpdateTbt_ContractEmail(updateContractEmailList);
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }