Beispiel #1
0
        private async Task <string> DetermineNewOrgCode(CommitAgencyRequest commitAgencyRequest, AgencyService agencyService)
        {
            if (commitAgencyRequest.Organization.OrganizationType != OrganizationType.ThirdParty)
            {
                return(commitAgencyRequest.Organization.OrganizationCode.Trim());
            }
            var str  = commitAgencyRequest.Organization.OrganizationName.Trim().ToUpper().Replace(" ", "");
            var str2 = string.Empty;

            if (str.Length >= 7)
            {
                str2 = str.Substring(0, 7);
            }
            else
            {
                str2 = str;
                for (var i = str.Length; i < 7; i++)
                {
                    str2 += "0";
                }
            }

            var suffixNumber = 1;
            var str3         = string.Empty;
            var keepTrying   = true;

            while (keepTrying && suffixNumber <= 100)
            {
                try
                {
                    str3 = str2 + suffixNumber.ToString();
                    var result = await agencyService.GetAgency(new GetOrganizationRequestData
                    {
                        OrganizationCode = str3
                    });

                    if (result == null || result.Organization == null)
                    {
                        keepTrying = false;
                    }
                }
                catch {}
                finally { suffixNumber++; }
            }
            if (keepTrying)
            {
                throw new ResponseErrorException(ResponseErrorCode.OrganizationCodeGenerationFailure, "Failed to generate Organization Code for third party organization. ");
            }
            return(str3);
        }
Beispiel #2
0
 public async Task <IActionResult> Post([FromBody] CommitAgencyRequest commitAgencyRequest)
 {
     return(new OkObjectResult(await _agencyService.AddAgency(commitAgencyRequest)));
 }