コード例 #1
0
        private bool ValidateInquireDoNotCallRequest(InquireDoNotCallRequest request, out string errorMessage)
        {
            bool validInput = false;

            errorMessage = string.Empty;
            StringBuilder error = new StringBuilder();

            if (request == null)
            {
                error.AppendLine("Request is null");
            }
            else
            {
                _commonFacade = new CommonFacade();
                bool hasAtLeastOneCriteria = request.CisId > 0 ||
                                             !string.IsNullOrWhiteSpace(request.CardNo) ||
                                             !string.IsNullOrWhiteSpace(request.SubscriptionTypeCode) ||
                                             !string.IsNullOrWhiteSpace(request.ProductCode) ||
                                             !string.IsNullOrWhiteSpace(request.PhoneNo) ||
                                             !string.IsNullOrWhiteSpace(request.Email);

                if (!hasAtLeastOneCriteria)
                {
                    error.AppendLine("Must insert at least one search criteria");
                }
                else
                {
                    // Card Info
                    bool hasCardNo           = !string.IsNullOrWhiteSpace(request.CardNo);
                    bool hasSubscriptionType = !string.IsNullOrWhiteSpace(request.SubscriptionTypeCode);
                    bool incompleteCardInfo  = hasCardNo ^ hasSubscriptionType;// exclusive-or: ONLY ONE condition is true
                    if (incompleteCardInfo)
                    {
                        error.AppendLine("Incomplete card info: missing CardNo or SubscriptionTypeCode");
                    }
                    // Total Limit
                    int  doNotCallUploadLimit = _commonFacade.GetDoNotCallUploadTotalRecord();
                    bool validLimitNumber     = request.DataLimit >= 1 && request.DataLimit <= doNotCallUploadLimit;
                    if (!validLimitNumber)
                    {
                        error.AppendLine($"Limit must be between 1 and {doNotCallUploadLimit.FormatNumber()} records");
                    }

                    validInput = validLimitNumber && !incompleteCardInfo;
                }
            }

            if (!validInput)
            {
                errorMessage = error.ToString();
            }

            return(validInput);
        }