public void UpdateAgent(AgentDataNew agent, int?idprofile) { if (idprofile == null) { return; } var payeeid = int.Parse(agent.PayeeID, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite); // returns 100 var dao = new LogAgentDataUpdateDao(); var data = dao.FindById(payeeid); if (data != null) { //update var requestdata = RequestBody(agent); var taspenApi = new TaspenApi(); var responsedata = taspenApi.UpdateAgent(requestdata, (int)idprofile); data.REQUESTDATA = requestdata; data.RESPONSEDATA = responsedata; data.CREATEDDATE = DateTime.Now; dao.Update(data); } else { //create new var requestdata = RequestBody(agent); var taspenApi = new TaspenApi(); var responsedata = taspenApi.UpdateAgent(requestdata, (int)idprofile); data = new LogAgentDataUpdate(); data.IDAGENT = payeeid; data.REQUESTDATA = requestdata; data.RESPONSEDATA = responsedata; data.CREATEDDATE = DateTime.Now; dao.Create(data); } LogAgentDataUpdateHistoryDao historyDao = new LogAgentDataUpdateHistoryDao(); var history = new LogAgentDataUpdateHistory(); history.IDAGENT = data.IDAGENT; history.REQUESTDATA = data.REQUESTDATA; history.RESPONSEDATA = data.RESPONSEDATA; history.CREATEDDATE = DateTime.Now; historyDao.Create(history); }
private void ProcessData(AgentDataNew agent) { var requestdata = RequestBody(agent); Console.WriteLine("requestdata :: " + requestdata); if (requestdata == null) { return; } int?idprofile = null; var taspenApi = new TaspenApi(); var responsedata = taspenApi.CreateNewAgent(requestdata); Console.WriteLine("responsedata :: " + responsedata); if (responsedata != null) { var agentDto = JsonConvert.DeserializeObject <AgentDto>(responsedata); if (agentDto?.listAgentProfile != null) { idprofile = agentDto.listAgentProfile.id; } } var payeeid = int.Parse(agent.PayeeID, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite); var data = new LogAgentDataNew() { IDAGENT = payeeid, CREATEDDATE = DateTime.Now, REQUESTDATA = requestdata, RESPONSEDATA = responsedata, IDPROFILE = idprofile }; Console.WriteLine("IDAGENT : " + payeeid); Console.WriteLine("IDPROFILE : " + idprofile); var logDao = new LogAgentDataNewDao(); logDao.Create(data); }
private void DeleteData(int idprofile) { Console.WriteLine("===== DeleteData : " + idprofile); var dao = new LogAgentDataDeleteDao(); var data = dao.FindById(idprofile); if (data != null) { return; } var taspenApi = new TaspenApi(); var responsedata = taspenApi.DeleteAgent(idprofile); data = new LogAgentDataDelete(); data.IDPROFILE = idprofile; data.REQUESTDATA = idprofile.ToString(); data.RESPONSEDATA = responsedata; data.CREATEDDATE = DateTime.Now; dao.Create(data); }
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); }
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); }