コード例 #1
0
ファイル: CampaignFacade.cs プロジェクト: KKPBank/CSM
        public Ticket CreateLead(AuditLogEntity auditLog, CampaignSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Call LeadService.InsertLead").Add("CampaignId", searchFilter.CampaignId)
                        .Add("FirstName", searchFilter.FirstName).Add("LastName", searchFilter.LastName).Add("PhoneNo", searchFilter.PhoneNo)
                        .Add("Email", searchFilter.Email).ToInputLogString());

            return(InsertLead(auditLog, searchFilter));
        }
コード例 #2
0
        public ActionResult Edit(CampaignViewModel campaignVM)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Save Recommended Campaign").Add("CardNo", campaignVM.CardNo.MaskCardNo())
                        .Add("HasInterested", campaignVM.Interested).Add("FirstName", campaignVM.FirstName).Add("LastName", campaignVM.LastName)
                        .Add("PhoneNo", campaignVM.PhoneNo).ToInputLogString());

            _auditLog              = new AuditLogEntity();
            _auditLog.Module       = Constants.Module.Customer;
            _auditLog.Action       = Constants.AuditAction.RecommendedCampaign;
            _auditLog.IpAddress    = ApplicationHelpers.GetClientIP();
            _auditLog.Status       = LogStatus.Success;
            _auditLog.CreateUserId = this.UserInfo.UserId;

            try
            {
                if (ModelState.IsValid)
                {
                    _userFacade   = new UserFacade();
                    _commonFacade = new CommonFacade();

                    var searchFilter = new CampaignSearchFilter
                    {
                        CampaignId      = campaignVM.CampaignId,
                        HasOffered      = Constants.CMTParamConfig.Offered,
                        IsInterested    = campaignVM.Interested,
                        Comments        = campaignVM.Comments,
                        UpdatedBy       = this.UserInfo.Username,
                        FirstName       = campaignVM.FirstName,
                        LastName        = campaignVM.LastName,
                        PhoneNo         = campaignVM.PhoneNo,
                        Email           = campaignVM.Email,
                        CardNo          = campaignVM.CardNo,
                        ChannelName     = campaignVM.ChannelName,
                        AvailableTime   = campaignVM.AvailableTime,
                        ContractNoRefer = campaignVM.ContractNoRefer
                    };

                    int?ownerLeadId = campaignVM.OwnerLead.ToNullable <int>();
                    if (ownerLeadId != null)
                    {
                        UserEntity ownerLead = _userFacade.GetUserById(ownerLeadId.Value);
                        searchFilter.OwnerLeadCode = ownerLead.EmployeeCode;
                    }

                    _campaignFacade = new CampaignFacade();

                    if (Constants.CMTParamConfig.Interested.Equals(campaignVM.Interested))
                    {
                        Ticket resLead = _campaignFacade.CreateLead(_auditLog, searchFilter);
                        Logger.Info(_logMsg.Clear().SetPrefixMsg("Create Lead").Add("ResponseCode", resLead.ResponseCode)
                                    .Add("ResponseMessage", resLead.ResponseMessage).ToSuccessLogString());
                    }

                    UpdateCampaignFlagsResponse resCamp = _campaignFacade.SaveCampaignFlags(_auditLog, campaignVM.CardNo, searchFilter);
                    Logger.Info(_logMsg.Clear().SetPrefixMsg("Save Recommended Campaign").Add("UpdateStatus", resCamp.UpdateStatus).ToSuccessLogString());

                    // Call CMT and SLM Services
                    return(Json(new
                    {
                        Valid = true,
                        Error = string.Empty,
                    }));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty,
                    Errors = GetModelValidationErrors()
                }));
            }
            catch (CustomException cex)
            {
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Campaign").Add("Error Message", cex.Message).ToFailLogString());
                return(Json(new
                {
                    Valid = false,
                    Error = cex.Message
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search Campaign").Add("Error Message", ex.Message).ToFailLogString());
                return(Json(new
                {
                    Valid = false,
                    Error = ex.Message
                }));
            }
        }
コード例 #3
0
ファイル: CampaignFacade.cs プロジェクト: KKPBank/CSM
        private Ticket InsertLead(AuditLogEntity auditLog, CampaignSearchFilter searchFilter)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Debug("I:--START--:--LeadService.InsertLead--");

            try
            {
                Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.InsertLead);

                SLM.InsertLeadRequest reqLead = new SLM.InsertLeadRequest();
                reqLead.RequestHeader = new SLM.Header
                {
                    ChannelID = profile.channel_id,
                    Encoding  = "",
                    Username  = profile.user_name,
                    Password  = profile.password,
                    Version   = ""
                };

                DataSet   ds          = ReadInsertLeadXml();
                DataTable dtMandatory = ds.Tables["mandatory"];
                dtMandatory.Rows[0]["firstname"] = searchFilter.FirstName;
                dtMandatory.Rows[0]["telNo1"]    = searchFilter.PhoneNo;
                dtMandatory.Rows[0]["campaign"]  = searchFilter.CampaignId;
                DataTable dtCustomerInfo = ds.Tables["customerInfo"];
                dtCustomerInfo.Rows[0]["lastname"]        = searchFilter.LastName;
                dtCustomerInfo.Rows[0]["email"]           = searchFilter.Email;
                dtCustomerInfo.Rows[0]["cid"]             = searchFilter.CardNo;
                dtCustomerInfo.Rows[0]["contractNoRefer"] = searchFilter.ContractNoRefer ?? string.Empty;
                DataTable dtCustomerDetail = ds.Tables["customerDetail"];
                dtCustomerDetail.Rows[0]["availableTime"] = searchFilter.AvailableTime.ToSLMTimeFormat();
                dtCustomerDetail.Rows[0]["detail"]        = searchFilter.Comments;
                DataTable dtAppInfo = ds.Tables["appInfo"];
                dtAppInfo.Rows[0]["lastOwner"] = searchFilter.OwnerLeadCode;
                reqLead.RequestXml             = ds.ToXml();

                SLM.InsertLeadResponse resLead = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                try
                {
                    Retry.Do(() =>
                    {
                        flgCatchErrorCode = string.Empty;
                        Logger.DebugFormat("-- XMLRequest --\n{0}", reqLead.SerializeObject());

                        using (var client = new SLM.LeadServiceClient())
                        {
                            resLead = ((SLM.ILeadService)client).InsertLead(reqLead);
                            if (client != null)
                            {
                                ((ICommunicationObject)client).Abort();
                            }
                        }
                    }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo());
                }
                catch (AggregateException aex)
                {
                    aex.Handle((x) =>
                    {
                        if (x is EndpointNotFoundException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0002;
                            Logger.Error("EndpointNotFoundException occur:\n", x);
                            return(true);
                        }
                        else if (x is CommunicationException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0002;
                            Logger.Error("CommunicationException occur:\n", x);
                            return(true);
                        }
                        else if (x is TimeoutException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0001;
                            Logger.Error("TimeoutException occur:\n", x);
                            return(true);
                        }
                        else
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0003;
                            Logger.Error("Exception occur:\n", x);
                            return(true);
                        }
                    });
                }

                if (!string.IsNullOrEmpty(flgCatchErrorCode))
                {
                    AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true));
                    throw new CustomException(GetMessageResource(flgCatchErrorCode, false));
                }

                #endregion

                if (resLead != null)
                {
                    Logger.DebugFormat("-- XMLResponse --\n{0}", resLead.SerializeObject());
                    var    xdoc   = XDocument.Parse(resLead.ResponseStatus);
                    Ticket ticket = (xdoc.Descendants("ticket")
                                     .Select(x => new Ticket
                    {
                        TicketId = x.Attribute("id").Value,
                        ResponseCode = x.Element("responseCode").Value,
                        ResponseMessage = x.Element("responseMessage").Value,
                        StrResponseDate = x.Element("responseDate").Value,
                        StrResponseTime = x.Element("responseTime").Value,
                    })).FirstOrDefault();

                    if (Constants.TicketResponse.SLMSuccess.Equals(ticket.ResponseCode))
                    {
                        AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty);
                        return(ticket);
                    }

                    // Log DB
                    AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.SLM, Constants.ServiceName.InsertLead,
                                                                                 ticket.ResponseCode, true));
                    throw new CustomException(GetMessageResource(Constants.SystemName.SLM, Constants.ServiceName.InsertLead,
                                                                 ticket.ResponseCode, false));
                }
            }
            finally
            {
                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
            }

            return(null);
        }
コード例 #4
0
ファイル: CampaignFacade.cs プロジェクト: KKPBank/CSM
        public UpdateCampaignFlagsResponse SaveCampaignFlags(AuditLogEntity auditLog, string cardNo, CampaignSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Call CmtService.UpdateCustomerFlags").Add("CardNo", cardNo.MaskCardNo())
                        .Add("HasOffered", searchFilter.HasOffered).Add("IsInterested", searchFilter.IsInterested)
                        .Add("UpdatedBy", searchFilter.UpdatedBy).ToInputLogString());

            return(UpdateCampaignFlagsByCustomer(auditLog, cardNo, searchFilter));
        }
コード例 #5
0
ファイル: CampaignFacade.cs プロジェクト: KKPBank/CSM
        private UpdateCampaignFlagsResponse UpdateCampaignFlagsByCustomer(AuditLogEntity auditLog, string cardNo, CampaignSearchFilter searchFilter)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Debug("I:--START--:--CmtService.UpdateCustomerFlags--");

            try
            {
                Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.CampaignByCustomer);

                var criteria = new CMT.UpdInquiry
                {
                    CampaignId   = searchFilter.CampaignId,
                    HasOffered   = searchFilter.HasOffered,
                    IsInterested = searchFilter.IsInterested,
                    UpdatedBy    = searchFilter.UpdatedBy,
                    Comments     = searchFilter.Comments,
                    Command      = profile.command
                };

                CMT.UpdateCustomerFlagsRequest reqCamp = new CMT.UpdateCustomerFlagsRequest
                {
                    header = new CMT.Header
                    {
                        password         = profile.password,
                        reference_no     = profile.reference_no,
                        service_name     = profile.service_name,
                        system_code      = profile.system_code,
                        transaction_date = profile.transaction_date,
                        user_name        = profile.user_name
                    },
                    UpdateCustFlag = new CMT.ReqUpdFlagEntity
                    {
                        CitizenId    = cardNo,
                        UpdInquiries = new CMT.UpdInquiry[] { criteria }
                    }
                };

                CMT.UpdateCustomerFlagsResponse resCamp = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                try
                {
                    Retry.Do(() =>
                    {
                        flgCatchErrorCode = string.Empty;
                        Logger.DebugFormat("-- XMLRequest --\n{0}", reqCamp.SerializeObject());
                        using (var client = new CMT.CmtServiceClient())
                        {
                            resCamp = ((CMT.ICmtService)client).UpdateCustomerFlags(reqCamp);
                            if (client != null)
                            {
                                ((ICommunicationObject)client).Abort();
                            }
                        }
                    }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo());
                }
                catch (AggregateException aex)
                {
                    aex.Handle((x) =>
                    {
                        if (x is EndpointNotFoundException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0002;
                            Logger.Error("EndpointNotFoundException occur:\n", x);
                            return(true);
                        }
                        else if (x is CommunicationException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0002;
                            Logger.Error("CommunicationException occur:\n", x);
                            return(true);
                        }
                        else if (x is TimeoutException)
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0001;
                            Logger.Error("TimeoutException occur:\n", x);
                            return(true);
                        }
                        else
                        {
                            flgCatchErrorCode = Constants.ErrorCode.CSM0003;
                            Logger.Error("Exception occur:\n", x);
                            return(true);
                        }
                    });
                }

                if (!string.IsNullOrEmpty(flgCatchErrorCode))
                {
                    AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true));
                    throw new CustomException(GetMessageResource(flgCatchErrorCode, false));
                }

                #endregion

                if (resCamp != null)
                {
                    Logger.DebugFormat("-- XMLResponse --\n{0}", resCamp.SerializeObject());

                    UpdateCampaignFlagsResponse response = new UpdateCampaignFlagsResponse();
                    response.StatusResponse.Status      = resCamp.status.status;
                    response.StatusResponse.ErrorCode   = resCamp.status.error_code;
                    response.StatusResponse.Description = resCamp.status.description;

                    if (Constants.StatusResponse.Success.Equals(response.StatusResponse.Status))
                    {
                        response.CitizenId = resCamp.detail.CitizenId;
                        if (resCamp.detail.Result != null)
                        {
                            response.UpdateStatus = resCamp.detail.Result.UpdateStatus;
                        }

                        AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty);
                        return(response);
                    }

                    // Log DB
                    AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.UpdateCustomerFlags,
                                                                                 response.StatusResponse.ErrorCode, true));
                    throw new CustomException(GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.UpdateCustomerFlags,
                                                                 response.StatusResponse.ErrorCode, false));
                }
            }
            finally
            {
                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
            }

            return(null);
        }