Beispiel #1
0
        public UpdateCalendarResponse UpdateBranchCalendar(UpdateBranchCalendarRequest request)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
            UpdateCalendarResponse response = new UpdateCalendarResponse();

            Logger.Info(_logMsg.Clear().SetPrefixMsg("Call BranchService.UpdateBranchCalendar").ToInputLogString());
            Logger.Debug("I:--START--:--BranchService.UpdateBranchCalendar--");

            try
            {
                bool valid = false;
                _commonFacade = new CommonFacade();

                if (request.Header != null)
                {
                    valid           = _commonFacade.VerifyServiceRequest <Header>(request.Header);
                    response.Header = new Header
                    {
                        reference_no     = request.Header.reference_no,
                        service_name     = request.Header.service_name,
                        system_code      = request.Header.system_code,
                        transaction_date = request.Header.transaction_date
                    };
                }

                Logger.DebugFormat("-- XMLRequest --\n{0}", request.SerializeObject());
                var auditLog = new AuditLogEntity();
                auditLog.Module    = Constants.Module.WebService;
                auditLog.Action    = Constants.AuditAction.CreateBranch;
                auditLog.IpAddress = ApplicationHelpers.GetClientIP();

                if (!valid)
                {
                    response.StatusResponse = new StatusResponse()
                    {
                        ErrorCode   = Constants.ErrorCode.CSMCalendar001,
                        Status      = Constants.StatusResponse.Failed,
                        Description = "Bad Request, the header is not valid"
                    };

                    return(response);
                }
                else
                {
                    #region == Validate Require Field ==

                    if (string.IsNullOrEmpty(request.HolidayDesc))
                    {
                        response.StatusResponse = new StatusResponse()
                        {
                            ErrorCode   = Constants.ErrorCode.CSMCalendar002,
                            Status      = Constants.StatusResponse.Failed,
                            Description = "ข้อมูลที่ส่งมาไม่ครบถ้วน ไม่สามารถบันทึกรายการได้ (Field=HolidateDesc)"
                        };

                        return(response);
                    }

                    if (request.UpdateMode != 1 && request.UpdateMode != 2)
                    {
                        response.StatusResponse = new StatusResponse()
                        {
                            ErrorCode   = Constants.ErrorCode.CSMCalendar002,
                            Status      = Constants.StatusResponse.Failed,
                            Description = "ข้อมูลที่ไม่สามารถบันทึกรายการได้ เนื่องจากข้อมูลที่ส่งมาอยู่ในรูปแบบไม่ถูกต้อง (UpdateMode ต้องมีค่า 1 (Delete and Insert) หรือ 2 (Merge) เท่านั้น)"
                        };

                        return(response);
                    }

                    #endregion

                    #region == Validate Code ==

                    var branchDataAccess = new BranchDataAccess(_context);

                    var branchCodes = request.BranchCodeList;
                    var branchIds   = new List <int>();

                    if (request.BranchCodeList != null)
                    {
                        var branchCodeNotFoundList = new List <string>();

                        foreach (var code in branchCodes)
                        {
                            var branchId = branchDataAccess.GetBranchIdByBranchCode(code);

                            if (branchId == null)
                            {
                                branchCodeNotFoundList.Add(code);
                            }
                            else
                            {
                                branchIds.Add(branchId.Value);
                            }
                        }

                        //ถ้าlist ของ branch code ที่ไม่มีเบส CSM มากกว่า 0 ให้ส่ง code list กลับไป
                        if (branchCodeNotFoundList.Count > 0)
                        {
                            response.StatusResponse = new StatusResponse()
                            {
                                ErrorCode = Constants.ErrorCode.CSMCalendar004,
                                Status    = Constants.StatusResponse.Failed,
                                BranchCodeNotFoundList = branchCodeNotFoundList,
                                Description            = string.Format(CultureInfo.InvariantCulture, "ข้อมูลที่ไม่สามารถบันทึกรายการได้ เนื่องจากไม่พบ Branch Code ในฐานข้อมูล")
                            };

                            return(response);
                        }
                    }
                    else
                    {
                        request.BranchCodeList = new List <string>();
                    }

                    #endregion

                    var result = branchDataAccess.UpdateBranchCalendar(request, branchIds);

                    if (result.IsSuccess)
                    {
                        response.StatusResponse = new StatusResponse
                        {
                            ErrorCode   = string.Empty,
                            Status      = Constants.StatusResponse.Success,
                            Description = "Save successful"
                        };
                    }
                    else
                    {
                        response.StatusResponse = new StatusResponse
                        {
                            ErrorCode   = Constants.ErrorCode.CSMCalendar003,
                            Status      = Constants.StatusResponse.Failed,
                            Description = result.ErrorMessage
                        };
                        AppLog.AuditLog(auditLog, LogStatus.Fail, response.StatusResponse.Description);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                response.StatusResponse = new StatusResponse
                {
                    ErrorCode   = Constants.ErrorCode.CSMBranch004,
                    Status      = Constants.StatusResponse.Failed,
                    Description = ex.ToString()
                };
            }
            finally
            {
                Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
            }

            return(response);
        }
Beispiel #2
0
        public CreateBranchResponse InsertOrUpdateBranch(InsertOrUpdateBranchRequest request)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();
            CreateBranchResponse response = new CreateBranchResponse();

            Logger.Info(_logMsg.Clear().SetPrefixMsg("Call BranchService.InsertOrUpdateBranch").ToInputLogString());
            Logger.Debug("I:--START--:--BranchService.InsertOrUpdateBranch--");

            try
            {
                bool valid = false;
                _commonFacade = new CommonFacade();

                if (request.Header != null)
                {
                    valid           = _commonFacade.VerifyServiceRequest <Header>(request.Header);
                    response.Header = new Header
                    {
                        reference_no     = request.Header.reference_no,
                        service_name     = request.Header.service_name,
                        system_code      = request.Header.system_code,
                        transaction_date = request.Header.transaction_date
                    };
                }

                Logger.DebugFormat("-- XMLRequest --\n{0}", request.SerializeObject());
                var auditLog = new AuditLogEntity();
                auditLog.Module    = Constants.Module.WebService;
                auditLog.Action    = Constants.AuditAction.CreateBranch;
                auditLog.IpAddress = ApplicationHelpers.GetClientIP();

                #region == Validate Require Field ==

                if (!valid)
                {
                    response.StatusResponse = new StatusResponse()
                    {
                        ErrorCode   = Constants.ErrorCode.CSMBranch001,
                        Status      = Constants.StatusResponse.Failed,
                        Description = "Bad Request, the header is not valid"
                    };

                    return(response);
                }
                else
                {
                    if (string.IsNullOrEmpty(request.BranchCode))
                    {
                        return(GetReturnErrorRequireField("BranchCode", response));
                    }

                    if (string.IsNullOrEmpty(request.BranchName))
                    {
                        return(GetReturnErrorRequireField("BranchName", response));
                    }

                    if (string.IsNullOrEmpty(request.ChannelCode))
                    {
                        return(GetReturnErrorRequireField("ChannelCode", response));
                    }

                    if (request.StartTimeHour < 0 || request.StartTimeHour > 23)
                    {
                        return(GetReturnErrorInvalidFormat("StartTimeHour", "ต้องมีค่าระหว่าง 0 ถึง 23", "5", response));
                    }

                    if (request.StartTimeMinute < 0 || request.StartTimeMinute > 59)
                    {
                        return(GetReturnErrorInvalidFormat("StartTimeHour", "ต้องมีค่าระหว่าง 0 ถึง 59", "5", response));
                    }

                    if (request.EndTimeHour < 0 || request.EndTimeHour > 23)
                    {
                        return(GetReturnErrorInvalidFormat("EndTimeHour", "ต้องมีค่าระหว่าง 0 ถึง 23", "5", response));
                    }

                    if (request.EndTimeMinute < 0 || request.EndTimeMinute > 59)
                    {
                        return(GetReturnErrorInvalidFormat("EndTimeHour", "ต้องมีค่าระหว่าง 0 ถึง 59", "5", response));
                    }

                    if (request.Status != 0 && request.Status != 1)
                    {
                        return(GetReturnErrorInvalidFormat("Status", "ต้องมีค่าระหว่าง 0 ถึง 1", "5", response));
                    }
                }

                #endregion

                #region == Validate Code ==

                var channelDataAccess = new ChannelDataAccess(_context);

                int?channelId = channelDataAccess.GetChannelIdByChannelCode(request.ChannelCode);
                if (!channelId.HasValue)
                {
                    response.StatusResponse = new StatusResponse()
                    {
                        ErrorCode   = Constants.ErrorCode.CSMBranch003,
                        Status      = Constants.StatusResponse.Failed,
                        Description = "Fail to save branch:\r\nไม่พบ Channel Code ในฐานข้อมูล CSM"
                    };

                    return(response);
                }

                var branchDataAccess = new BranchDataAccess(_context);

                int?upperBranchId = null;

                if (!string.IsNullOrEmpty(request.UpperBranchCode))
                {
                    upperBranchId = branchDataAccess.GetBranchIdByBranchCode(request.UpperBranchCode);
                    if (!upperBranchId.HasValue)
                    {
                        response.StatusResponse = new StatusResponse()
                        {
                            ErrorCode   = Constants.ErrorCode.CSMBranch003,
                            Status      = Constants.StatusResponse.Failed,
                            Description = "Fail to save branch:\r\nไม่พบ Upper Branch Code ในฐานข้อมูล CSM"
                        };

                        return(response);
                    }
                }

                #endregion

                var result = branchDataAccess.InsertOrUpdateBranch(request, channelId.Value, upperBranchId);
                if (result.IsSuccess)
                {
                    response.StatusResponse = new StatusResponse
                    {
                        ErrorCode   = string.Empty,
                        Status      = Constants.StatusResponse.Success,
                        Description = "Save successful"
                    };
                    AppLog.AuditLog(auditLog, LogStatus.Success, response.StatusResponse.Description);
                }
                else
                {
                    response.StatusResponse = new StatusResponse
                    {
                        ErrorCode   = Constants.ErrorCode.CSMBranch003,
                        Status      = Constants.StatusResponse.Failed,
                        Description = result.ErrorMessage
                    };
                    AppLog.AuditLog(auditLog, LogStatus.Fail, response.StatusResponse.Description);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                response.StatusResponse = new StatusResponse
                {
                    ErrorCode   = Constants.ErrorCode.CSMBranch004,
                    Status      = Constants.StatusResponse.Failed,
                    Description = ex.ToString()
                };
            }
            finally
            {
                Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
            }

            return(response);
        }
Beispiel #3
0
        private Ticket SearchLead(AuditLogEntity auditLog, string cardNo)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Debug("I:--START--:--COCService.SearchLead--");

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

                COC.ServiceRequest reqLead = new COC.ServiceRequest();
                reqLead.RequestHeader = new COC.Header
                {
                    ChannelID = profile.channel_id,
                    Username  = profile.user_name,
                    Password  = profile.password,
                    System    = profile.system_code
                };

                DataSet   ds = ReadSearchLeadXml();
                DataTable dt = ds.Tables[0];
                dt.Rows[0]["cid"]            = cardNo;
                dt.Rows[0]["firstname"]      = "";
                dt.Rows[0]["lastname"]       = "";
                dt.Rows[0]["status"]         = "";
                dt.Rows[0]["productGroupId"] = "";
                dt.Rows[0]["productId"]      = "";
                dt.Rows[0]["maxRecord"]      = "30";
                reqLead.RequestXml           = ds.ToXml();

                COC.ServiceResponse resLead = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                // Avoid error codes
                _commonFacade = new CommonFacade();
                List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.COC, Constants.ServiceName.SearchLead);

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

                        using (var client = new COC.ServiceClient())
                        {
                            resLead = ((COC.IService)client).SearchLead(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.ResponseXml);

                    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,
                        TotalLeads = x.Element("totalLeads") == null ? string.Empty : x.Element("totalLeads").Value
                    })).FirstOrDefault();


                    if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(ticket.ResponseCode))
                    {
                        ticket.ResponseCode = Constants.TicketResponse.COC_Success;
                    }

                    if (Constants.TicketResponse.COC_Success.Equals(ticket.ResponseCode))
                    {
                        List <TicketItem> items = null;

                        if (xdoc.Descendants("result") != null && xdoc.Descendants("result").Count() > 0)
                        {
                            items = xdoc.Descendants("result")
                                    .Select(x => new TicketItem
                            {
                                TicketId           = x.Element("ticketId").Value,
                                CardNo             = x.Element("cid").Value,
                                FirstName          = x.Element("firstname").Value,
                                LastName           = x.Element("lastname").Value,
                                TelNo1             = x.Element("telNo1").Value,
                                Status             = x.Element("status").Value,
                                StatusDesc         = x.Element("statusDesc").Value,
                                CampaignCode       = x.Element("campaign").Value,
                                CampaignDesc       = x.Element("campaignDesc").Value,
                                ProductGroupId     = x.Element("productGroupId").Value,
                                ProductGroupDesc   = x.Element("productGroupDesc").Value,
                                ProductId          = x.Element("productId").Value,
                                ProductDesc        = x.Element("productDesc").Value,
                                ChannelId          = x.Element("channelId").Value,
                                OwnerLead          = x.Element("ownerLead").Value,
                                OwnerLeadName      = x.Element("ownerLeadName").Value,
                                DelegateLead       = x.Element("delegateLead").Value,
                                DelegateLeadName   = x.Element("delegateLeadName").Value,
                                CreatedUser        = x.Element("createdUser").Value,
                                CreatedUserName    = x.Element("createdUserName").Value,
                                StrCreatedDate     = x.Element("createdDate").Value,
                                StrCreatedTime     = x.Element("createdTime").Value,
                                StrAssignedDate    = x.Element("assignedDate").Value,
                                StrAssignedTime    = x.Element("assignedTime").Value,
                                OwnerBranch        = x.Element("ownerBranch").Value,
                                OwnerBranchName    = x.Element("ownerBranchName").Value,
                                DelegateBranch     = x.Element("delegateBranch").Value,
                                DelegateBranchName = x.Element("delegateBranchName").Value,
                                CreatedBranch      = x.Element("createdBranch").Value,
                                CreatedBranchName  = x.Element("createdBranchName").Value
                            }).ToList();
                        }

                        ticket.Items = items;
                        AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty);
                        return(ticket);
                    }

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

            return(null);
        }
Beispiel #4
0
        public CreateProductMasterResponse CreateProductMaster(CreateProductMasterRequest request)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Info(_logMsg.Clear().SetPrefixMsg("Call MasterService.CreateProductMaster").ToInputLogString());
            Logger.Debug("I:--START--:--MasterService.CreateProductMaster--");

            bool valid = false;

            _commonFacade = new CommonFacade();
            CreateProductMasterResponse response = new CreateProductMasterResponse();

            if (request.Header != null)
            {
                valid           = _commonFacade.VerifyServiceRequest <Header>(request.Header);
                response.Header = new Header
                {
                    reference_no     = request.Header.reference_no,
                    service_name     = request.Header.service_name,
                    system_code      = request.Header.system_code,
                    transaction_date = request.Header.transaction_date
                };
            }

            Logger.DebugFormat("-- XMLRequest --\n{0}", request.SerializeObject());

            var auditLog = new AuditLogEntity();

            auditLog.Module    = Constants.Module.Customer;
            auditLog.Action    = Constants.AuditAction.CreateProductMaster;
            auditLog.IpAddress = ApplicationHelpers.GetClientIP();

            #region "Call Validator"

            if (!valid)
            {
                response.StatusResponse = new StatusResponse
                {
                    ErrorCode   = Constants.ErrorCode.CSMProd001,
                    Status      = Constants.StatusResponse.Failed,
                    Description = "Bad Request, the header is not valid"
                };

                AppLog.AuditLog(auditLog, LogStatus.Fail, response.StatusResponse.Description);
                Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());

                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);

                return(response);
            }
            else
            {
                dynamic[] results = DoValidation(request);
                valid = (bool)results[0];
                List <ValidationResult> validationResults = (List <ValidationResult>)results[1];

                if (!valid)
                {
                    response.StatusResponse           = new StatusResponse();
                    response.StatusResponse.ErrorCode = Constants.ErrorCode.CSMProd002;
                    response.StatusResponse.Status    = Constants.StatusResponse.Failed;

                    if (validationResults != null && validationResults.Count > 0)
                    {
                        string msg = "Bad Request, the body is not valid:\n{0}";
                        response.StatusResponse.Description = string.Format(CultureInfo.InvariantCulture, msg,
                                                                            validationResults.Select(x => x.ErrorMessage).Aggregate((i, j) => i + Delimeter + j));
                    }

                    AppLog.AuditLog(auditLog, LogStatus.Fail, response.StatusResponse.Description);
                    Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());

                    stopwatch.Stop();
                    Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);

                    return(response);
                }
            }

            #endregion

            ProductEntity         product      = null;
            CampaignServiceEntity campaign     = null;
            ProductGroupEntity    productGroup = null;

            if (!string.IsNullOrWhiteSpace(request.ProductGroup.Code) &&
                !string.IsNullOrWhiteSpace(request.ProductGroup.Name))
            {
                productGroup = new ProductGroupEntity
                {
                    ProductGroupCode = request.ProductGroup.Code,
                    ProductGroupName = request.ProductGroup.Name,
                    IsActive         = Constants.ApplicationStatus.Active.ConvertToString().Equals(request.ProductGroup.Status) ? true : false,
                    CreateUser       = request.ProductGroup.CreateUser,
                    CreateDate       = request.ProductGroup.CreateDateValue,
                    UpdateUser       = request.ProductGroup.UpdateUser,
                    UpdateDate       = request.ProductGroup.UpdateDateValue
                };
            }

            if (request.Product != null && !string.IsNullOrWhiteSpace(request.Product.Code) &&
                !string.IsNullOrWhiteSpace(request.Product.Name))
            {
                product = new ProductEntity
                {
                    ProductCode = request.Product.Code,
                    ProductName = request.Product.Name,
                    ProductType = request.Product.ProductType,
                    IsActive    = Constants.ApplicationStatus.Active.ConvertToString().Equals(request.Product.Status) ? true : false,
                    CreateUser  = request.Product.CreateUser,
                    CreateDate  = request.Product.CreateDateValue,
                    UpdateUser  = request.Product.UpdateUser,
                    UpdateDate  = request.Product.UpdateDateValue
                };
            }

            if (request.Campaign != null && !string.IsNullOrWhiteSpace(request.Campaign.Code) &&
                !string.IsNullOrWhiteSpace(request.Campaign.Name))
            {
                campaign = new CampaignServiceEntity
                {
                    CampaignServiceCode = request.Campaign.Code,
                    CampaignServiceName = request.Campaign.Name,
                    IsActive            = Constants.ApplicationStatus.Active.ConvertToString().Equals(request.Campaign.Status) ? true : false,
                    CreateUser          = request.Campaign.CreateUser,
                    CreateDate          = request.Campaign.CreateDateValue,
                    UpdateUser          = request.Campaign.UpdateUser,
                    UpdateDate          = request.Campaign.UpdateDateValue
                };
            }

            if (productGroup != null)
            {
                _productDataAccess = new ProductDataAccess(_context);
                bool success = _productDataAccess.SaveProductMaster(productGroup, product, campaign);

                if (success)
                {
                    response.StatusResponse = new StatusResponse
                    {
                        ErrorCode   = string.Empty,
                        Status      = Constants.StatusResponse.Success,
                        Description = "Create successful data"
                    };

                    AppLog.AuditLog(auditLog, LogStatus.Success, response.StatusResponse.Description);

                    Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
                    stopwatch.Stop();
                    Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);

                    return(response);
                }
            }

            response.StatusResponse = new StatusResponse
            {
                ErrorCode   = Constants.ErrorCode.CSMProd003,
                Status      = Constants.StatusResponse.Failed,
                Description = "Fail to create data"
            };

            AppLog.AuditLog(auditLog, LogStatus.Fail, response.StatusResponse.Description);
            Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
            stopwatch.Stop();
            Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);

            return(response);
        }
Beispiel #5
0
        private InquiryActivityLogResponse InquiryActivityLog(AuditLogEntity auditLog, ActivitySearchFilter searchFilter)
        {
            CAR.CASLogServiceSoapClient client = null;

            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Debug("I:--START--:--CARLogService.InquiryActivityLog--");

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

                var header = new CAR.LogServiceHeader
                {
                    ReferenceNo         = profile.reference_no,
                    ServiceName         = profile.service_name,
                    SystemCode          = profile.system_code,
                    SecurityKey         = profile.password,
                    TransactionDateTime = DateTime.Now,
                };

                decimal subsTypeCodeAsDecimal;
                try
                {
                    subsTypeCodeAsDecimal = Convert.ToDecimal(searchFilter.SubsTypeCode, CultureInfo.InvariantCulture);
                }
                catch (Exception ex)
                {
                    subsTypeCodeAsDecimal = 0;
                    Logger.Error("Exception occur:\n", ex);
                }

                if (subsTypeCodeAsDecimal == 0 || string.IsNullOrEmpty(searchFilter.CardNo))
                {
                    subsTypeCodeAsDecimal = 0;
                    searchFilter.CardNo   = null;
                }

                var activitiyLogData = new CAR.InqueryActivityLogData
                {
                    ActivityStartDateTime = searchFilter.ActivityStartDateTimeValue,          // "2015-01-01".ParseDateTime("yyyy-MM-dd").Value
                    ActivityEndDateTime   = searchFilter.ActivityEndDateTimeValue,            // "2016-06-07".ParseDateTime("yyyy-MM-dd").Value
                    ChannelID             = null,
                    SubscriptionTypeID    = searchFilter.SrOnly ? 0 : subsTypeCodeAsDecimal,  // 1,
                    SubscriptionID        = searchFilter.SrOnly ? null : searchFilter.CardNo, // "3601000025739",
                    SrID       = searchFilter.SrOnly ? searchFilter.SrNo : null,              // "162817263527",
                    CampaignID = string.Empty,
                    TypeID     = 0,
                    AreaID     = 0,
                    SubAreaID  = 0
                };

                CAR.InqueryActivytyLogResponse resActivity = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                // Avoid error codes
                _commonFacade = new CommonFacade();
                List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.CAR, Constants.ServiceName.InquiryActivityLog);

                try
                {
                    Retry.Do(() =>
                    {
                        flgCatchErrorCode = string.Empty;
                        Logger.DebugFormat("-- XMLRequest --\n{0}\n{1}", header.SerializeObject(), activitiyLogData.SerializeObject());
                        client      = new CAR.CASLogServiceSoapClient("CASLogServiceSoap");
                        resActivity = client.InquiryActivityLog(header, activitiyLogData);
                        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 (resActivity != null)
                {
                    Logger.DebugFormat("-- XMLResponse --\n{0}", resActivity.SerializeObject());

                    InquiryActivityLogResponse response = new InquiryActivityLogResponse();
                    response.StatusResponse.ErrorCode   = resActivity.ResponseStatus.ResponseCode;
                    response.StatusResponse.Description = resActivity.ResponseStatus.ResponseMessage;

                    if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(resActivity.ResponseStatus.ResponseCode))
                    {
                        response.StatusResponse.ErrorCode = Constants.ActivityResponse.Success;
                    }

                    if (Constants.ActivityResponse.Success.Equals(response.StatusResponse.ErrorCode))
                    {
                        if (resActivity.InquiryActivityDataList != null)
                        {
                            response.ActivityDataItems = resActivity.InquiryActivityDataList
                                                         .Select(ac => new ActivityDataItem
                            {
                                ActivityDateTime     = ac.ActivityDateTime,
                                ActivityID           = ac.ActivityID,
                                ActivityTypeID       = ac.ActivityTypeID,
                                ActivityTypeName     = ac.ActivityTypeName,
                                AreaID               = ac.AreaID,
                                AreaName             = ac.AreaName,
                                CISID                = ac.CISID,
                                CampaignID           = ac.CampaignID,
                                CampaignName         = ac.CampaignName,
                                ChannelID            = ac.ChannelID,
                                ChannelName          = ac.ChannelName,
                                ContractID           = ac.ContractID,
                                TypeID               = ac.TypeID,
                                TypeName             = ac.TypeName,
                                TicketID             = ac.TicketID,
                                ProductID            = ac.ProductID,
                                ProductName          = ac.ProductName,
                                ProductGroupID       = ac.ProductGroupID,
                                ProductGroupName     = ac.ProductGroupName,
                                SrID                 = ac.SrID,
                                SubAreaID            = ac.SubAreaID,
                                SubAreaName          = ac.SubAreaName,
                                Status               = ac.Status,
                                SubStatus            = ac.SubStatus,
                                SubscriptionTypeName = ac.SubscriptionTypeName,
                                SubscriptionID       = ac.SubscriptonID,
                                CustomerInfo         = new CustomerInfo
                                {
                                    SubscriptionType = GetDataItemValue(ac.CustomerInfoList.FirstOrDefault(x => x.SeqNo == 1)),
                                    SubscriptionID   = GetDataItemValue(ac.CustomerInfoList.FirstOrDefault(x => x.SeqNo == 2)),
                                    FullName         = GetDataItemValue(ac.CustomerInfoList.FirstOrDefault(x => x.SeqNo == 3))
                                },
                                ContractInfo = new ContractInfo
                                {
                                    AccountNo      = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 1)),
                                    CreateSystem   = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 2)),
                                    RegistrationNo = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 3)),
                                    FullName       = GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 11)) + " " + GetDataItemValue(ac.ContractInfoList.FirstOrDefault(x => x.SeqNo == 12)),
                                },
                                ActivityInfo = new ActivityInfo
                                {
                                    CreatorBranch       = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 10)),
                                    CreatorSR           = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 11)),
                                    OwnerBranch         = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 12)),
                                    OwnerSR             = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 13)),
                                    DelegateBranch      = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 14)),
                                    DelegateSR          = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 15)),
                                    SendEmail           = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 16)),
                                    EmailTo             = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 17)),
                                    EmailCc             = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 18)),
                                    EmailSubject        = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 19)),
                                    EmailBody           = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 20)),
                                    EmailAttachments    = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 21)),
                                    ActivityDescription = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 22)),
                                    ActivityType        = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 23)),
                                    SRStatus            = GetDataItemValue(ac.ActivityInfoList.FirstOrDefault(x => x.SeqNo == 24)),
                                },
                                OfficerInfo = new OfficerInfo
                                {
                                    FullName = GetDataItemValue(ac.OfficerInfoList.FirstOrDefault(x => x.SeqNo == 1))
                                },
                                ProductInfo = new ProductInfo
                                {
                                    ProductGroup = GetDataItemValue(ac.ProductInfoList.FirstOrDefault(x => x.SeqNo == 1)),
                                    Product      = GetDataItemValue(ac.ProductInfoList.FirstOrDefault(x => x.SeqNo == 2)),
                                    Campaign     = GetDataItemValue(ac.ProductInfoList.FirstOrDefault(x => x.SeqNo == 3))
                                }
                            })
                                                         .OrderByDescending(x => x.SrID)
                                                         .ThenByDescending(x => x.ActivityDateTime)
                                                         .ToList();
                        }

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

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

            return(null);
        }
Beispiel #6
0
        public ServiceRequestSaveCarResult InsertActivityLogToCAR(AuditLogEntity auditLog, ServiceRequestForInsertLogEntity entity)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Call CARLogService.CreateActivityLog").ToInputLogString());

            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            Logger.Debug("I:--START--:--CARLogService.CreateActivityLog--");

            ServiceRequestSaveCarResult result = new ServiceRequestSaveCarResult();

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

                var header = new CAR.LogServiceHeader
                {
                    ReferenceNo         = entity.SrActivityId.ConvertToString(),
                    ServiceName         = Constants.ServiceName.CreateActivityLog,
                    SystemCode          = profile.system_code,
                    SecurityKey         = profile.password,
                    TransactionDateTime = DateTime.Now
                };

                var accountNo = entity.AccountNo;
                if (!string.IsNullOrEmpty(entity.AccountNo) && entity.AccountNo.ToUpper() == "DUMMY")
                {
                    accountNo = string.Format("DUMMY-{0}", entity.CustomerId);
                }

                #region "Customer Info"

                var customerInfoList = new List <CAR.DataItem>();
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 1, DataLabel = "Subscription Type", DataValue = entity.CustomerSubscriptionTypeName
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 2, DataLabel = "Subscription ID", DataValue = entity.CustomerCardNo
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 3, DataLabel = "วันเกิด", DataValue = entity.CustomerBirthDateDisplay
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 4, DataLabel = "คำนำหน้า", DataValue = entity.CustomerTitleTh
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 5, DataLabel = "ชื่อลูกค้า", DataValue = entity.CustomerFirstNameTh
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 6, DataLabel = "นามสกุลลูกค้า", DataValue = entity.CustomerLastNameTh
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 7, DataLabel = "Title", DataValue = entity.CustomerTitleEn
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 8, DataLabel = "First Name", DataValue = entity.CustomerFirstNameEn
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 9, DataLabel = "Last Name", DataValue = entity.CustomerLastNameEn
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 10, DataLabel = "เบอร์โทรศัพท์ #1", DataValue = entity.CustomerPhoneNo1
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 11, DataLabel = "เบอร์โทรศัพท์ #2", DataValue = entity.CustomerPhoneNo2
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 12, DataLabel = "เบอร์โทรศัพท์ #3", DataValue = entity.CustomerPhoneNo3
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 13, DataLabel = "เบอร์แฟกซ์", DataValue = entity.CustomerFax
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 14, DataLabel = "อีเมล์", DataValue = entity.CustomerEmail
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 15, DataLabel = "รหัสพนักงาน", DataValue = entity.CustomerEmployeeCode
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 16, DataLabel = "A Number.", DataValue = entity.ANo
                });
                customerInfoList.Add(new CAR.DataItem {
                    SeqNo = 17, DataLabel = "Call ID.", DataValue = entity.CallId
                });

                #endregion

                #region "Contract Info"

                var contractInfoList = new List <CAR.DataItem>();
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 1, DataLabel = "เลขที่บัญชี/สัญญา", DataValue = accountNo
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 2, DataLabel = "สถานะบัญชี", DataValue = entity.AccountStatus
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 3, DataLabel = "ทะเบียนรถ", DataValue = entity.AccountCarNo
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 4, DataLabel = "Product Group", DataValue = entity.AccountProductGroup
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 5, DataLabel = "Product", DataValue = entity.AccountProduct
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 6, DataLabel = "ชื่อสาขา", DataValue = entity.AccountBranchName
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 7, DataLabel = "Subscription Type", DataValue = entity.ContactSubscriptionTypeName
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 8, DataLabel = "Subscription ID", DataValue = entity.ContactCardNo
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 9, DataLabel = "วันเกิด", DataValue = entity.ContactBirthDateDisplay
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 10, DataLabel = "คำนำหน้า", DataValue = entity.ContactTitleTh
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 11, DataLabel = "ชื่อลูกค้า", DataValue = entity.ContactFirstNameTh
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 12, DataLabel = "นามสกุลลูกค้า", DataValue = entity.ContactLastNameTh
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 13, DataLabel = "Title", DataValue = entity.ContactTitleEn
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 14, DataLabel = "First Name", DataValue = entity.ContactFirstNameEn
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 15, DataLabel = "Last Name", DataValue = entity.ContactLastNameEn
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 16, DataLabel = "เบอร์โทรศัพท์ #1", DataValue = entity.ContactPhoneNo1
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 17, DataLabel = "เบอร์โทรศัพท์ #2", DataValue = entity.ContactPhoneNo2
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 18, DataLabel = "เบอร์โทรศัพท์ #3", DataValue = entity.ContactPhoneNo3
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 19, DataLabel = "เบอร์แฟกซ์", DataValue = entity.ContactFax
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 20, DataLabel = "อีเมล์", DataValue = entity.ContactEmail
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 21, DataLabel = "เลขที่สัญญาที่เกี่ยวข้องกับผู้ติดต่อ", DataValue = entity.ContactAccountNo
                });
                contractInfoList.Add(new CAR.DataItem {
                    SeqNo = 22, DataLabel = "ความสัมพันธ์", DataValue = entity.ContactRelationshipName
                });

                #endregion

                #region "Product Info

                var productInfoList = new List <CAR.DataItem>();
                productInfoList.Add(new CAR.DataItem {
                    SeqNo = 1, DataLabel = "Product Group", DataValue = entity.ProductGroupName
                });
                productInfoList.Add(new CAR.DataItem {
                    SeqNo = 2, DataLabel = "Product", DataValue = entity.ProductName
                });
                productInfoList.Add(new CAR.DataItem {
                    SeqNo = 3, DataLabel = "Campaign/Service", DataValue = entity.CampaignServiceName
                });

                #endregion

                #region "Office Info"

                var officeInfoList = new List <CAR.DataItem>();
                officeInfoList.Add(new CAR.DataItem {
                    SeqNo = 1, DataLabel = "Officer", DataValue = entity.ActivityCreateUserFullName
                });

                #endregion

                #region "Activity Info"

                var activityInfoList = new List <CAR.DataItem>();

                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 1, DataLabel = "Area", DataValue = entity.AreaName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 2, DataLabel = "Sub Area", DataValue = entity.SubAreaName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 3, DataLabel = "Type", DataValue = entity.TypeName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 4, DataLabel = "SR Channel", DataValue = entity.ChannelCode
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 5, DataLabel = "Media Source", DataValue = entity.MediaSourceName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 6, DataLabel = "Subject", DataValue = entity.Subject
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 7, DataLabel = "Remark", DataValue = entity.Remark
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 8, DataLabel = "Verify", DataValue = entity.Verify
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 9, DataLabel = "Verify Result", DataValue = entity.VerifyResult
                });

                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 10, DataLabel = "Creator Branch", DataValue = entity.SRCreatorBranchName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 11, DataLabel = "Creator SR", DataValue = entity.SRCreatorUserFullName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 12, DataLabel = "Owner Branch", DataValue = entity.OwnerBranchName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 13, DataLabel = "Owner SR", DataValue = entity.OwnerUserFullName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 14, DataLabel = "Delegate Branch", DataValue = entity.DelegateBranchName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 15, DataLabel = "Delegate SR", DataValue = entity.DelegateUserFullName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 16, DataLabel = "Send E-Mail", DataValue = entity.SendEmail
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 17, DataLabel = "E-Mail To", DataValue = entity.EmailTo
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 18, DataLabel = "E-Mail Cc", DataValue = entity.EmailCc
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 19, DataLabel = "E-Mail Subject", DataValue = entity.EmailSubject
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 20, DataLabel = "E-Mail Body", DataValue = entity.EmailBody
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 21, DataLabel = "E-Mail Attachments", DataValue = entity.EmailAttachments
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 22, DataLabel = "รายละเอียดการติดต่อ", DataValue = entity.ActivityDescription
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 23, DataLabel = "Activity Type", DataValue = entity.ActivityTypeName
                });
                activityInfoList.Add(new CAR.DataItem {
                    SeqNo = 24, DataLabel = "SR Status", DataValue = entity.SRStatusName
                });

                if (entity.SrPageId == Constants.SRPage.DefaultPageId)
                {
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 25, DataLabel = "ที่อยู่ในการจัดส่งเอกสาร", DataValue = entity.AddressForDisplay
                    });
                }
                else if (entity.SrPageId == Constants.SRPage.AFSPageId)
                {
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 25, DataLabel = "รหัสสินทรัพย์รอขาย", DataValue = entity.AFSAssetNo
                    });
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 26, DataLabel = "รายละเอียดทรัพย์", DataValue = entity.AFSAssetDesc
                    });
                }
                else if (entity.SrPageId == Constants.SRPage.NCBPageId)
                {
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 25, DataLabel = "วันเกิด/วันที่จดทะเบียน (พ.ศ.)", DataValue = entity.NCBCustomerBirthDateDisplay
                    });
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 26, DataLabel = "Marketing Branch Upper #1", DataValue = entity.NCBMarketingBranchUpper1Name
                    });
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 27, DataLabel = "Marketing Branch Upper #2", DataValue = entity.NCBMarketingBranchUpper2Name
                    });
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 28, DataLabel = "Marketing Branch", DataValue = entity.NCBMarketingBranchName
                    });
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 29, DataLabel = "Marketing", DataValue = entity.NCBMarketingFullName
                    });
                    activityInfoList.Add(new CAR.DataItem {
                        SeqNo = 30, DataLabel = "NCB Check Status", DataValue = entity.NCBCheckStatus
                    });
                }

                #endregion

                #region "ActivitiyLog Data"

                int customerSubscriptionTypeCode;

                try
                {
                    customerSubscriptionTypeCode = Convert.ToInt32(entity.CustomerSubscriptionTypeCode, CultureInfo.InvariantCulture);
                }
                catch (Exception ex)
                {
                    customerSubscriptionTypeCode = 0;
                    Logger.Error("Exception occur:\n", ex);
                }

                var customerCardNo = entity.CustomerCardNo;

                if (string.IsNullOrEmpty(customerCardNo) || customerSubscriptionTypeCode == 0)
                {
                    customerCardNo = null;
                    customerSubscriptionTypeCode = 0;
                }

                var activitiyLogData = new CAR.CreateActivityLogData
                {
                    ChannelID          = profile.channel_id,
                    ActivityDateTime   = entity.ActivityCreateDate.Value,
                    SubscriptionTypeID = customerSubscriptionTypeCode,
                    SubscriptionID     = customerCardNo,
                    LeadID             = null,
                    TicketID           = null,
                    SrID             = entity.SrNo,
                    ContractID       = accountNo,
                    ProductGroupID   = entity.ProductGroupCode,
                    ProductID        = entity.ProductCode,
                    CampaignID       = entity.CampaignServiceCode,
                    ActivityTypeID   = entity.ActivityTypeId,
                    ActivityTypeName = entity.ActivityTypeName,
                    TypeID           = entity.TypeCode,
                    AreaID           = entity.AreaCode,
                    SubAreaID        = entity.SubAreaCode,
                    TypeName         = entity.TypeName,
                    AreaName         = entity.AreaName,
                    SubAreaName      = entity.SubAreaName,
                    Status           = entity.SRStatusName,
                    KKCISID          = entity.KKCISID,
                    NoncustomerID    = entity.CustomerId.ConvertToString(),
                    OfficerInfoList  = officeInfoList.ToArray(),
                    ProductInfoList  = productInfoList.ToArray(),
                    CustomerInfoList = customerInfoList.ToArray(),
                    ActivityInfoList = activityInfoList.ToArray(),
                    ContractInfoList = contractInfoList.ToArray(),
                };

                #endregion

                CAR.CreateActivityLogResponse resActivity = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                try
                {
                    flgCatchErrorCode = string.Empty;
                    using (var client = new CAR.CASLogServiceSoapClient("CASLogServiceSoap"))
                    {
                        resActivity = ((CAR.CASLogServiceSoapClient)client).CreateActivityLog(header, activitiyLogData);
                        if (client != null)
                        {
                            ((ICommunicationObject)client).Abort();
                        }
                    }
                }
                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);
                        }
                    });

                    result.IsSuccess    = false;
                    result.ErrorCode    = flgCatchErrorCode;
                    result.ErrorMessage = aex.Message;
                    return(result);
                }

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

                #endregion

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

                    if (Constants.ActivityResponse.Success.Equals(resActivity.ResponseStatus.ResponseCode))
                    {
                        AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty);

                        result.IsSuccess    = true;
                        result.ErrorCode    = "";
                        result.ErrorMessage = "";
                        return(result);
                    }
                    else
                    {
                        // Log DB
                        AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CAR, Constants.ServiceName.CreateActivityLog,
                                                                                     resActivity.ResponseStatus.ResponseCode, true));

                        result.IsSuccess    = false;
                        result.ErrorCode    = resActivity.ResponseStatus.ResponseCode;
                        result.ErrorMessage = resActivity.ResponseStatus.ResponseMessage;
                        return(result);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                result.IsSuccess    = false;
                result.ErrorCode    = "1";
                result.ErrorMessage = ex.Message;
                return(result);
            }
            finally
            {
                stopwatch.Stop();
                Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
            }

            return(null);
        }
Beispiel #7
0
        private RecommendCampaignResponse GetCampaignByCustomer(AuditLogEntity auditLog, string cardNo, string hasOffered,
                                                                string isInterested, string customerFlag, int campaignNum)
        {
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

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

            try
            {
                Header      profile = GetHeaderByServiceName <Header>(Constants.ServiceName.CampaignByCustomer);
                CMT.Header2 header  = new CMT.Header2
                {
                    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
                };

                CMT.CampaignByCustomersRequest reqCamp = new CMT.CampaignByCustomersRequest
                {
                    header = header,
                    CampByCitizenIdBody = new CMT.ReqCampByCusEntity
                    {
                        CitizenId     = cardNo,
                        HasOffered    = hasOffered,
                        IsInterested  = isInterested,
                        CustomerFlag  = customerFlag,
                        Command       = profile.command,
                        RequestDate   = DateTime.Now.FormatDateTime("yyyyMMdd"),
                        Channel       = profile.channel_id,
                        CampaignNum   = campaignNum,
                        ProductTypeId = "0,2"
                    }
                };

                CMT.CampaignByCustomersResponse resCamp = null;

                #region "Call Service"

                string flgCatchErrorCode = string.Empty;

                // Avoid error codes
                _commonFacade = new CommonFacade();
                List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer);

                try
                {
                    Retry.Do(() =>
                    {
                        flgCatchErrorCode = string.Empty;
                        Logger.DebugFormat("-- XMLRequest --\n{0}", reqCamp.SerializeObject());
                        using (var client = new CMT.CmtServiceClient())
                        {
                            resCamp = ((CMT.ICmtService)client).CampaignByCustomers(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());

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

                    if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(resCamp.status.error_code))
                    {
                        response.StatusResponse.Status = Constants.StatusResponse.Success;
                    }

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

                            if (resCamp.detail.CitizenIds != null && resCamp.detail.CitizenIds.Count() > 0)
                            {
                                var results = resCamp.detail.CitizenIds.Where(x => x != null).Select(x => new CampaignDetail
                                {
                                    CampaignCriteria = x.CampaignCreiteria,
                                    CampaignDesc     = x.CampaignDescription,
                                    CampaignId       = x.CampaignId,
                                    CampaignName     = x.CampaignName,
                                    CampaignOffer    = x.CampaignOffer,
                                    CampaignScore    = x.CampaignScore,
                                    Channel          = x.Channel,
                                    CitizenIds       = x.CitizenIds,
                                    DescCust         = x.DescCust,
                                    StrExpireDate    = x.ExpireDate,
                                    IsInterested     = x.IsInterested,
                                    ContractNoRefer  = x.ContractNo,
                                    ProductTypeId    = x.ProductTypeId,
                                    ProductTypeName  = x.ProductTypeName
                                });

                                response.RecommendCampaignDetails = results.OrderBy(x => x.ExpireDate).ToList();
                            }
                        }

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

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

            return(null);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }