Exemplo n.º 1
0
        private string RequestBody(AgentDataNew agent)
        {
            var payeeid = int.Parse(agent.PayeeID, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);

            var nameAgentPosition   = agent.Title;
            var taspenApi           = new TaspenApi();
            var resultAgentPosition = taspenApi.SearchAgentPosition(nameAgentPosition);
            var agentPositionDto    = JsonConvert.DeserializeObject <AgentPositionDto>(resultAgentPosition);

            if (agentPositionDto == null)
            {
                return(null);
            }

            Console.WriteLine("agentPositionDto - ok :: " + nameAgentPosition);
            if (agentPositionDto.PositionMetaDto?.PositionMetaPaginationDto == null ||
                agentPositionDto.PositionMetaDto.PositionMetaPaginationDto.Total == 0)
            {
                return(null);
            }

            Console.WriteLine("PositionMetaPaginationDto - ok");
            var positionAgentDto = agentPositionDto.ListAgentPosition.FirstOrDefault();

            if (positionAgentDto == null)
            {
                return(null);
            }

            var licenseExpireAt = agent.ExpiryDate != null
                ? agent.ExpiryDate.GetValueOrDefault().ToString("yyyy-MM-dd")
                : "-";

            // var licenseExpireAt = agent.ExpiryDate;
            Console.WriteLine("licenseExpireAt --> " + licenseExpireAt);
            Console.WriteLine("payeeid --> " + payeeid);
            var licenseNumber = agent.LicenseID != null && agent.LicenseID.Trim().Length > 0
                ? agent.LicenseID : "-";

            var licenseStatus = "";

            if (agent.EmployeeStatus != null && agent.EmployeeStatus.StartsWith("A") && licenseNumber != null &&
                !"-".Equals(licenseNumber) && !"-".Equals(licenseExpireAt))
            {
                licenseStatus = "valid";
            }

            var dto = new AgentNewPayloadDTO
            {
                instanceId = taspenApi.FindByInstanceProfileName("JAKARTA"),
                code       = agent.PayeeID,
                name       = agent.Name,
                // address = agent.Address,
                //20 Sept 2021: Address diganti GA Office Name
                address         = agent.GAOfficeName != null && agent.GAOfficeName.Trim().Length > 0 ? agent.GAOfficeName : "",
                phone           = agent.Phone != null && agent.Phone.Trim().Length > 0 ? agent.Phone : "-",
                email           = agent.EmailAddress != null && agent.EmailAddress.Trim().Length > 0 ? agent.EmailAddress : "-",
                positionId      = positionAgentDto.Id,
                licenseNumber   = licenseNumber,
                licenseDate     = "-",
                licenseExpireAt = licenseExpireAt,
                licenseStatus   = licenseStatus
            };


            var payload = new AgentNewPayload {
                agentProfile = dto
            };

            var jsonString = JsonConvert.SerializeObject(payload);

            return(jsonString);
        }
Exemplo n.º 2
0
        private string RequestBody(AgentDataNew agent)
        {
            var nameAgentPosition = agent.Title;
            var taspenApi         = new TaspenApi();

            var resultAgentPosition = taspenApi.SearchAgentPosition(nameAgentPosition);
            var agentPositionDto    = JsonConvert.DeserializeObject <AgentPositionDto>(resultAgentPosition);

            if (agentPositionDto == null)
            {
                return(null);
            }

            if (agentPositionDto.PositionMetaDto?.PositionMetaPaginationDto == null ||
                agentPositionDto.PositionMetaDto.PositionMetaPaginationDto.Total == 0)
            {
                return(null);
            }

            var positionAgentDto = agentPositionDto.ListAgentPosition.FirstOrDefault();

            if (positionAgentDto == null)
            {
                return(null);
            }

            var licenseExpireAt = agent.ExpiryDate != null
                ? agent.ExpiryDate.GetValueOrDefault().ToString("yyyy-MM-dd")
                : "-";

            // var licenseExpireAt = agent.ExpiryDate;
            var licenseNumber = agent.LicenseID != null && agent.LicenseID.Trim().Length > 0
                ? agent.LicenseID : "-";

            var licenseStatus = "";

            if (agent.EmployeeStatus != null && agent.EmployeeStatus.StartsWith("A") && licenseNumber != null &&
                !"-".Equals(licenseNumber) && !"-".Equals(licenseExpireAt))
            {
                licenseStatus = "valid";
            }

            var dto = new AgentNewPayloadDTO();

            dto.instanceId = 2; //TODO (saat ini di set default = 2)
            dto.code       = agent.PayeeID;
            dto.name       = agent.Name;
            // dto.address = agent.Address;
            // address = agent.Address,
            //20 Sept 2021: Address diganti GA Office Name
            dto.address         = agent.GAOfficeName != null && agent.GAOfficeName.Trim().Length > 0 ? agent.GAOfficeName : "";
            dto.phone           = agent.Phone != null && agent.Phone.Trim().Length > 0 ? agent.Phone : "-";
            dto.email           = agent.EmailAddress != null && agent.EmailAddress.Trim().Length > 0 ? agent.EmailAddress : "-";
            dto.positionId      = positionAgentDto.Id; //TODO
            dto.licenseNumber   = licenseNumber;
            dto.licenseDate     = "-";
            dto.licenseExpireAt = licenseExpireAt;
            dto.licenseStatus   = licenseStatus;

            Console.WriteLine("licenseExpireAt --> " + licenseExpireAt);
            Console.WriteLine("code --> " + dto.code);

            var payload = new AgentNewPayload();

            payload.agentProfile = dto;

            var jsonString = JsonConvert.SerializeObject(payload);

            return(jsonString);
        }