Beispiel #1
0
        GetCustomerResponse ICustomerServiceBusiness.GetResultCustomerDTOs(ClientesDTO prmsearchClientesDTO)
        {
            GetCustomerResponse customerResponse = new GetCustomerResponse();

            customerResponse.status = new Status();
            CacheHandler lch_cache;
            Dictionary <ClientesDTO, GetCustomerResponse> ld_data;
            GetCustomerResponse customerResponse2 = null;
            bool lb_valCache;

            lch_cache   = new CacheHandler();
            ld_data     = (Dictionary <ClientesDTO, GetCustomerResponse>)lch_cache.GetCache("getClientes");
            lb_valCache = false;

            if (ld_data != null)
            {
                foreach (ClientesDTO lc_key in ld_data.Keys)
                {
                    if (lc_key.Equals(prmsearchClientesDTO))
                    {
                        lb_valCache = ld_data.TryGetValue(lc_key, out customerResponse2);
                        break;
                    }
                }
            }

            if (lb_valCache)
            {
                customerResponse = customerResponse2;
            }
            else
            {
                try
                {
                    //validar tipos de datos
                    List <ClientesDTO> lstClientesDTO;
                    lstClientesDTO = null;

                    ClientesDAL ClientesDAL = new ClientesDAL();
                    lstClientesDTO = ClientesDAL.GetClientes(prmsearchClientesDTO);

                    if (lstClientesDTO != null)
                    {
                        if (lstClientesDTO.Count > 0)
                        {
                            List <GetCustomerResult> GetCustomerResult = new List <GetCustomerResult>();

                            foreach (ClientesDTO clientesDTO in lstClientesDTO)
                            {
                                GetCustomerResult    lCustomer;
                                List <CreditCardGet> lcreditCard = new List <CreditCardGet>();

                                lCustomer = new GetCustomerResult
                                {
                                    IdType         = clientesDTO.CodTypeIdent,
                                    FirstName      = clientesDTO.FName,
                                    LastNames      = clientesDTO.LName,
                                    IdNumber       = clientesDTO.CustID,
                                    PhoneNumber    = clientesDTO.PhoneNumber,
                                    Email          = clientesDTO.Email,
                                    Address        = clientesDTO.Address,
                                    Country        = clientesDTO.Country,
                                    City           = clientesDTO.City,
                                    User           = clientesDTO.User,
                                    Password       = clientesDTO.Password,
                                    StatusCustomer = clientesDTO.Status,
                                    IdUser         = clientesDTO.ID
                                };

                                if (clientesDTO.LCreditCard != null)
                                {
                                    foreach (CreditCardDTO creditCardDTO in clientesDTO.LCreditCard)
                                    {
                                        CreditCardGet creditCard = new CreditCardGet
                                        {
                                            CardName       = creditCardDTO.CardName,
                                            ExpirationDate = creditCardDTO.ExpirationDate,
                                            Type           = creditCardDTO.Type,
                                            Number         = creditCardDTO.Number,
                                            SecurityCode   = creditCardDTO.SecurityCode,
                                            StatusCard     = creditCardDTO.StatusCard
                                        };

                                        lcreditCard.Add(creditCard);
                                        lCustomer.CreditCard = creditCard;
                                    }
                                }

                                GetCustomerResult.Add(lCustomer);
                            }

                            customerResponse.result             = GetCustomerResult.ToArray();
                            customerResponse.status.CodeResp    = "0";
                            customerResponse.status.MessageResp = "Proceso satisfactorio";

                            if (ld_data == null)
                            {
                                ld_data = new Dictionary <ClientesDTO, GetCustomerResponse>();
                            }

                            ld_data.Add(prmsearchClientesDTO, customerResponse);
                            lch_cache.AddCache("getClientes", ld_data);
                        }
                        else
                        {
                            customerResponse.status.CodeResp    = "01";
                            customerResponse.status.MessageResp = "no existen datos....";
                        }
                    }
                    else
                    {
                        customerResponse.status.CodeResp    = "01";
                        customerResponse.status.MessageResp = "error....";
                    }
                }
                catch (Exception ex)
                {
                    customerResponse.status.CodeResp    = "01";
                    customerResponse.status.MessageResp = "Error en la....";
                    Common.CreateTrace.WriteLog(Common.CreateTrace.LogLevel.Error, "ERROR EN LA CAPA DE NEGOCIO CustomerService:GetCustomer");
                    Common.CreateTrace.WriteLog(Common.CreateTrace.LogLevel.Error, " :: " + ex.Message);
                    //throw ex;
                }
            }
            return(customerResponse);
        }