private bool ValidateServiceRequest(Header requestHeader)
        {
            _commonFacade = new CommonFacade();
            string doNotCallProfilePath = _commonFacade.GetProfileXml("DoNotCallProfile");
            bool   valid = _commonFacade.VerifyServiceRequest <Header>(requestHeader, doNotCallProfilePath);

            return(valid);
        }
Esempio n. 2
0
        public InsertOrUpdateUserResponse InsertOrUpdateUser(InsertOrUpdateUserRequest request)
        {
            var          stopwatch = System.Diagnostics.Stopwatch.StartNew();
            UserResponse response  = new UserResponse();

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

            try
            {
                if (request.ActionType != 1 && request.ActionType != 2)
                {
                    return(new InsertOrUpdateUserResponse()
                    {
                        IsSuccess = false,
                        ErrorCode = "2",
                        ErrorMessage = "Action Type must be 1 or 2. (1=Insert,2=Update)"
                    });
                }

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

                if (!valid)
                {
                    return(new InsertOrUpdateUserResponse()
                    {
                        IsSuccess = false,
                        ErrorCode = "99",
                        ErrorMessage = "Bad Request, the header is not valid"
                    });
                }

                #region == Validate Require Field ==

                if (string.IsNullOrEmpty(request.WindowsUsername))
                {
                    return(GetReturnErrorRequireField("WindowUserName"));
                }

                if (string.IsNullOrEmpty(request.EmployeeCodeNew))
                {
                    return(GetReturnErrorRequireField("EmployeeCodeNew"));
                }

                if (request.ActionType == 2)
                {
                    if (string.IsNullOrEmpty(request.EmployeeCodeOld))
                    {
                        return(GetReturnErrorRequireField("EmployeeCodeOld"));
                    }
                }

                if (string.IsNullOrEmpty(request.FirstName))
                {
                    return(GetReturnErrorRequireField("FirstName"));
                }

                if (string.IsNullOrEmpty(request.Phone1) && !request.IsGroup)
                {
                    return(GetReturnErrorRequireField("Phone1", " (Phone1 เป็น Required Field เมื่อ IsGroup = FALSE)"));
                }

                if (string.IsNullOrEmpty(request.PositionCode))
                {
                    return(GetReturnErrorRequireField("PositionCode"));
                }

                if (string.IsNullOrEmpty(request.RoleSale))
                {
                    return(GetReturnErrorRequireField("RoleSale"));
                }

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

                if (string.IsNullOrEmpty(request.RoleCode))
                {
                    return(GetReturnErrorRequireField("RoleCode"));
                }

                #endregion

                #region == Validate Code ==

                _userDataAccess = new UserDataAccess(_context);

                int?supervisorUserId = null;

                if (!string.IsNullOrEmpty(request.SupervisorEmployeeCode))
                {
                    supervisorUserId = _userDataAccess.GetUserIdByEmployeeCode(request.SupervisorEmployeeCode);
                    if (!supervisorUserId.HasValue)
                    {
                        return(new InsertOrUpdateUserResponse()
                        {
                            IsSuccess = false,
                            ErrorCode = "3",
                            ErrorMessage = "ไม่พบ Employee Code ของ Supervisor ในฐานข้อมูล CSM"
                        });
                    }
                }

                int?roleId = _userDataAccess.GetRoleIdByRoleCode(request.RoleCode);
                if (!roleId.HasValue)
                {
                    return(new InsertOrUpdateUserResponse()
                    {
                        IsSuccess = false,
                        ErrorCode = "4",
                        ErrorMessage = "ไม่พบ Role Code ในฐานข้อมูล CSM",
                    });
                }

                var branchDataAccess = new BranchDataAccess(_context);
                int?branchId         = branchDataAccess.GetBranchIdByBranchCode(request.BranchCode);
                if (!branchId.HasValue)
                {
                    Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
                    stopwatch.Stop();
                    Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);

                    return(new InsertOrUpdateUserResponse()
                    {
                        IsSuccess = false,
                        ErrorCode = "5",
                        ErrorMessage = "ไม่พบ Branch Code ในฐานข้อมูล CSM",
                    });
                }
                else
                {
                    response.StatusResponse = new StatusResponse
                    {
                        ErrorCode   = string.Empty,
                        Status      = Constants.StatusResponse.Success,
                        Description = "Save successful"
                    };

                    Logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
                    stopwatch.Stop();
                    Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds);
                    var result = _userDataAccess.InsertOrUpdateUser(request, supervisorUserId, roleId.Value, branchId.Value);
                    if (!result.IsSuccess)
                    {
                        return(new InsertOrUpdateUserResponse()
                        {
                            IsSuccess = false,
                            ErrorCode = "5",
                            ErrorMessage = result.ErrorMessage
                        });
                    }
                    return(result);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                return(new InsertOrUpdateUserResponse()
                {
                    IsSuccess = false,
                    ErrorCode = "1",
                    ErrorMessage = ex.Message
                });
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public ImportSubscriptionResponse ImportSubscription(ImportSubscriptionRequest request)
        {
            ThreadContext.Properties["EventClass"]    = ApplicationHelpers.GetCurrentMethod(1);
            ThreadContext.Properties["RemoteAddress"] = ApplicationHelpers.GetClientIP();

            if (request != null && request.Header != null)
            {
                ThreadContext.Properties["UserID"] = request.Header.user_name.ToUpperInvariant();
            }

            _logger.Info(_logMsg.Clear().SetPrefixMsg("Call CustomerService.ImportSubscription").ToInputLogString());
            _logger.Debug("I:--START--:--CustomerService.ImportSubscription--");

            ImportSubscriptionResponse response = new ImportSubscriptionResponse();

            _stopwatch = System.Diagnostics.Stopwatch.StartNew();

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

                if (request == null)
                {
                    throw new Exception("CustomerService.ImportSubscription : Request is null!");
                }

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

                #region "Call Validator"

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

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

                    if (!valid)
                    {
                        response.StatusResponse           = new StatusResponse();
                        response.StatusResponse.ErrorCode = Constants.ErrorCode.CSMCust002;
                        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));
                        }

                        _logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
                        return(response);
                    }
                }

                #endregion

                ImportSubscriptionAsync(request.ImportDateValue.Value, request.SkipSFTP).ConfigureAwait(false);

                response.StatusResponse = new StatusResponse
                {
                    ErrorCode   = string.Empty,
                    Status      = Constants.StatusResponse.Success,
                    Description = string.Empty
                };
            }
            catch (Exception ex)
            {
                _logger.Error("Exception occur:\n", ex);
                response.StatusResponse = new StatusResponse
                {
                    ErrorCode   = Constants.ErrorCode.CSMCust003,
                    Status      = Constants.StatusResponse.Failed,
                    Description = "Fail to import customer data"
                };
            }
            finally
            {
                _logger.DebugFormat("-- XMLResponse --\n{0}", response.SerializeObject());
                _stopwatch.Stop();
                _logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", _stopwatch.ElapsedMilliseconds);
            }

            return(response);
        }