private GetCustomersResult CreateGetCustomersResult(CustomerDto dto)
        {
            var result = new GetCustomersResult
            {
                Id   = dto.Id,
                Name = dto.Name
            };

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <GetCustomersResult> GetCustomersBySiebelId(string endPoint, string userId)
        {
            GetCustomersResult result = new GetCustomersResult();

            try
            {
                result = await GetCustomersBySiebelIdProcess(endPoint, userId).ConfigureAwait(false);

                return(result);
            }
            catch (Exception e)
            {
                result.Status  = ResultStatus.EXTERNAL_SERVICE_ERROR;
                result.Message = "[CustomerService-GetCustomersBySiebelId-Exception] " + e.Message;
                return(result);
            }
        }
Ejemplo n.º 3
0
        public async Task <GetCustomersResult> GetCustomersByCommercialId(string endPoint, string commercialId)
        {
            GetCustomersResult result = new GetCustomersResult();

            try
            {
                var siebelId = _commercialRepository.SingleOrDefault(item => item.Id.Equals(int.Parse(commercialId))).SiebelId;
                result = await GetCustomersBySiebelIdProcess(endPoint, siebelId).ConfigureAwait(false);

                return(result);
            }
            catch (Exception e)
            {
                result.Status  = ResultStatus.EXTERNAL_SERVICE_ERROR;
                result.Message = "[Excep.] " + e.Message;
                return(result);
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetCustomers([FromQuery][Required] string userid)
        {
            StatusResponseDto errorStatus;

            try
            {
                /// <summary>
                /// Método para guardar request en logs
                /// </summary>
                _securityService.RequestLog("api/customers/GetCustomers: " + userid);

                if (string.IsNullOrEmpty(userid) || string.IsNullOrWhiteSpace(userid))
                {
                    return(BadRequest());
                }
                else
                {
                    string             endPoint           = _config.GetValue <string>("ExternalServicesHosts:Siebel:EndPointGetCustomers");
                    GetCustomersResult dataCustomersModel = await _customerService.GetCustomersBySiebelId(endPoint, userid);

                    switch (dataCustomersModel.Status)
                    {
                    case ResultStatus.SUCCESS:
                        return(Ok(_mapper.Map <List <CustomerDto> >(dataCustomersModel.CustomerList)));

                    case ResultStatus.NOT_FOUND:
                        return(StatusCode(StatusCodes.Status404NotFound));

                    case ResultStatus.EXTERNAL_SERVICE_ERROR:
                        errorStatus = _mapper.Map <StatusResponseDto>(dataCustomersModel);
                        return(StatusCode(StatusCodes.Status500InternalServerError, errorStatus));

                    default:
                        errorStatus = _mapper.Map <StatusResponseDto>(dataCustomersModel);
                        return(StatusCode(StatusCodes.Status500InternalServerError, errorStatus));
                    }
                }
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Ejemplo n.º 5
0
        private async Task <GetCustomersResult> GetCustomersBySiebelIdProcess(string endPoint, string siebelId)
        {
            GetCustomersResult result = new GetCustomersResult();

            SAResponseData siebelResponse = await _siebelClient.GetCustomers(endPoint, siebelId).ConfigureAwait(false);

            #region SiebelLog
            string strSiebelRequest  = System.Text.Json.JsonSerializer.Serialize(siebelId);
            string strSiebelResponse = System.Text.Json.JsonSerializer.Serialize(siebelResponse);
            _siebelLog.Write(endPoint, strSiebelRequest, strSiebelResponse);
            #endregion

            if (siebelResponse == null || string.IsNullOrWhiteSpace(siebelResponse.returnCode))
            {
                result.Status  = ResultStatus.EXTERNAL_SERVICE_ERROR;
                result.Message = "Error desconocido en Servicio Siebel";
                return(result);
            }

            // Control de errores
            if (Enum.TryParse(siebelResponse.returnCode, out SiebelResponse resultSRCode))
            {
                switch (resultSRCode)
                {
                case SiebelResponse.OK:
                    break;

                case SiebelResponse.ECTI002:
                    result.Status = ResultStatus.NOT_FOUND;
                    return(result);

                default:
                    result.Status  = ResultStatus.EXTERNAL_SERVICE_ERROR;
                    result.Message = "[" + siebelResponse.returnCode + "] " + siebelResponse.returnMsg;
                    return(result);
                }
            }
            else
            {
                result.Status  = ResultStatus.EXTERNAL_SERVICE_ERROR;
                result.Message = "[" + siebelResponse.returnCode + "] " + siebelResponse.returnMsg;
                return(result);
            }

            List <CustomerModel> customerList = new List <CustomerModel>();
            if (siebelResponse.outputData != null &&
                siebelResponse.outputData.ListOfCustomer != null &&
                siebelResponse.outputData.ListOfCustomer.Customer != null &&
                siebelResponse.outputData.ListOfCustomer.Customer.Count > 0)
            {
                siebelResponse.outputData.ListOfCustomer.Customer.OrderBy(c => c.CustomerName).ToList().ForEach(customer =>
                {
                    List <PhoneNumberModel> phoneNumberListAux = new List <PhoneNumberModel>();
                    if (customer.ListOfPhoneNumber != null && customer.ListOfPhoneNumber.PhoneNumber != null)
                    {
                        customer.ListOfPhoneNumber.PhoneNumber.ForEach(phoneNumber =>
                        {
                            phoneNumberListAux.Add(new PhoneNumberModel
                            {
                                PhoneNumber = phoneNumber.PhoneNumber,
                                PhoneType   = Utilities.GetPhoneType(phoneNumber.PhoneType)
                            });
                        });
                    }

                    customerList.Add(new CustomerModel
                    {
                        CustomerId      = customer.CustomerId,
                        CustomerName    = customer.CustomerName,
                        CustomerType    = Utilities.GetCustomerType(customer.CustomerType),
                        PhoneNumberList = phoneNumberListAux
                    });
                });
            }

            result.Status       = ResultStatus.SUCCESS;
            result.CustomerList = customerList;
            return(result);
        }