Esempio n. 1
0
        public async Task <ServiceResponse <GetTerminalExternalClientDto> > UpdateTerminalExternalClient(UpdateTerminalExternalClientDto updateTerminalExternal)
        {
            ServiceResponse <GetTerminalExternalClientDto> serviceResponse = new ServiceResponse <GetTerminalExternalClientDto>();

            try
            {
                Terminal terminal = await _context.Terminals.FirstOrDefaultAsync(ct => ct.TerminalID.Equals(updateTerminalExternal.TerminalID));

                //SI ES NULL MANTIENE EL VALOR ACTUAL ?.
                terminal.Custom1 = updateTerminalExternal.nombreComercial?.ToUpper() ?? terminal.Custom1;
                terminal.Custom2 = updateTerminalExternal.direccionFiscal?.ToUpper() ?? terminal.Custom2;
                if (updateTerminalExternal.rut != null)
                {
                    terminal.Custom3 = addRUT + updateTerminalExternal.rut;
                }

                //AcquirerDto acq = new AcquirerDto();

                if (updateTerminalExternal.acquirer != null)
                {
                    terminal.Custom4 = updateTerminalExternal.acquirer.acqVisanet ?? terminal.Custom4;

                    terminal.Custom6 = updateTerminalExternal.acquirer.acqOca ?? terminal.Custom6;

                    terminal.Custom8 = updateTerminalExternal.acquirer.acqCabal ?? terminal.Custom8;

                    terminal.Custom12 = updateTerminalExternal.acquirer.acqAnda ?? terminal.Custom12;

                    terminal.Custom13 = updateTerminalExternal.acquirer.acqAMEX ?? terminal.Custom13;

                    terminal.Custom19 = updateTerminalExternal.acquirer.acqCabal_usd ?? terminal.Custom19;

                    //rst-64
                    //acqFirstdata, acqCreditel, acqPasscard, acqEdenred, acqClubDelEste
                    //CAMBIOS GONZALO
                    ////terminal.Custom5 = updateTerminalExternal.acquirer.acqFirstdata ?? terminal.Custom5;
                    ////terminal.Custom7 = updateTerminalExternal.acquirer.acqCreditosDirectos ?? terminal.Custom7;
                    ////terminal.Custom9 = updateTerminalExternal.acquirer.acqCreditel ?? terminal.Custom9;
                    ////terminal.Custom10 = updateTerminalExternal.acquirer.acqPasscard ?? terminal.Custom10;
                    terminal.Custom11 = updateTerminalExternal.acquirer.acqEdenred ?? terminal.Custom11;
                    terminal.Custom14 = updateTerminalExternal.acquirer.acqClubDelEste ?? terminal.Custom14;
                    //rst-64
                }

                SystemPOS systempos = await _context.SystemPOSs.FirstOrDefaultAsync(ct => ct.TerminalID.Equals(updateTerminalExternal.TerminalID));

                bool rstTerminalChecksum = false;
                bool rstTranConnChecksum = false;
                bool rstControlChecksum  = false;
                bool newPackage          = false;
                if (updateTerminalExternal.nombreComercial != null ||
                    updateTerminalExternal.direccionFiscal != null ||
                    updateTerminalExternal.rut != null ||
                    updateTerminalExternal.acquirer != null
                    )
                {
                    if (systempos != null)
                    {
                        systempos.TerminalChecksum = 0;
                        rstTerminalChecksum        = true;
                    }
                }

                if (updateTerminalExternal.merchantType != null)
                {
                    if (systempos != null)
                    {
                        systempos.ControlGroup = (int)updateTerminalExternal.merchantType;
                        rstControlChecksum     = true;
                    }
                }

                //terminalEnabled -> Activar o desactivar Terminal en el Switch JPOS. 1:Activo 0:Inactivo
                TerminalStatus term = await _context.TerminalsStatus.FirstOrDefaultAsync(t => t.TerminalID.Equals(updateTerminalExternal.TerminalID));

                bool termStatus = term?.status != null && term.status == 1;
                if (updateTerminalExternal.terminalEnabled == 1 || updateTerminalExternal.terminalEnabled == 0)
                {
                    if (term != null)
                    {
                        term.status = (int)updateTerminalExternal.terminalEnabled;
                    }
                    else
                    {
                        term            = new TerminalStatus();
                        term.TerminalID = updateTerminalExternal.TerminalID;
                        term.status     = (int)updateTerminalExternal.terminalEnabled;
                        await _context.AddAsync(term);
                    }
                }

                // SI ALGUN PARAMETRO NO ES NULO
                if (updateTerminalExternal.ca_name != null ||
                    updateTerminalExternal.mcc != null ||
                    updateTerminalExternal.pf_id != null ||
                    updateTerminalExternal.visa_spnsrd_mercht != null ||
                    updateTerminalExternal.amex_id_comercio != null
                    )
                {
                    // SI LA TERMINAL ESTA HABILITADA
                    if (termStatus || updateTerminalExternal.terminalEnabled == 1)
                    {
                        jpos jpos_value = new jpos();

                        string[] parameters = new string[] {
                            updateTerminalExternal.ca_name,
                            updateTerminalExternal.mcc,
                            updateTerminalExternal.pf_id,
                            updateTerminalExternal.visa_spnsrd_mercht,
                            updateTerminalExternal.amex_id_comercio,
                        };

                        Sysconfig sys = await _MySqlcontext.sysconfig.FirstOrDefaultAsync(s => s.id.Equals(addca + updateTerminalExternal.TerminalID));

                        if (sys != null)
                        {
                            if (sys.value != null)
                            {
                                jpos_value.setSysconfigValue_CA(sys.value);
                            }
                        }
                        else
                        {
                            sys    = new Sysconfig();
                            sys.id = addca + updateTerminalExternal.TerminalID;
                            await _MySqlcontext.sysconfig.AddAsync(sys);
                        }

                        jpos_value.updateSysconfigValue_CA(parameters);
                        sys.value = jpos_value.genSysconfigValue_CA();
                    }
                }


                await _context.SaveChangesAsync();

                await _MySqlcontext.SaveChangesAsync();

                serviceResponse = await GetTerminalExternalClientById(updateTerminalExternal.TerminalID);

                serviceResponse.Success = true;


                //ACTUALIZA LINEA AL ARCHIVO TERMINALS
                _csvfile.UpdateTerminalsLine(updateTerminalExternal.TerminalID, updateTerminalExternal);

                //ACTUALIZA LINEA AL ARCHIVO SYSTEM
                _csvfile.UpdateSystemLine(updateTerminalExternal.TerminalID, updateTerminalExternal, rstTerminalChecksum, rstTranConnChecksum, rstControlChecksum, newPackage);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }
Esempio n. 2
0
        public async Task <ServiceResponse <GetTerminalExternalClientDto> > GetTerminalExternalClientById(string terminalID)
        {
            ServiceResponse <GetTerminalExternalClientDto> serviceResponse = new ServiceResponse <GetTerminalExternalClientDto>();

            try{
                Terminal terminalExternal = await _context.Terminals
                                            .Include(s => s.SystemPOS)
                                            .Where(t => t.TerminalID.Equals(terminalID))
                                            .FirstAsync();

                //var terminalExternalDto = _mapper.Map<List<TerminalsExternalDto>>(terminalsExternal);

                GetTerminalExternalClientDto terextDto = new GetTerminalExternalClientDto();


                AcquirerDto acq = new AcquirerDto();
                terextDto.TerminalID      = terminalExternal.TerminalID;
                terextDto.SerialNumber    = terminalExternal.SerialNumber;
                terextDto.nombreComercial = terminalExternal.Custom1;
                terextDto.direccionFiscal = terminalExternal.Custom2;
                terextDto.rut             = terminalExternal.Custom3;



                acq.acqVisanet          = terminalExternal.Custom4;
                acq.acqFirstdata        = terminalExternal.Custom5;
                acq.acqOca              = terminalExternal.Custom6;
                acq.acqCreditosDirectos = terminalExternal.Custom7;
                acq.acqCabal            = terminalExternal.Custom8;
                acq.acqCreditel         = terminalExternal.Custom9;
                acq.acqPasscard         = terminalExternal.Custom10;
                acq.acqEdenred          = terminalExternal.Custom11;
                acq.acqAnda             = terminalExternal.Custom12;
                acq.acqAMEX             = terminalExternal.Custom13;
                acq.acqClubDelEste      = terminalExternal.Custom14;
                acq.acqMides            = terminalExternal.Custom15;
                acq.acqCabal_usd        = terminalExternal.Custom19;

                terextDto.acquirer     = acq;
                terextDto.ConnectGroup = terminalExternal.SystemPOS.ConnectGroup;
                terextDto.terminalInit = terminalExternal.SystemPOS.TerminalChecksum;
                terextDto.merchantType = terminalExternal.SystemPOS.ControlGroup;


                TerminalStatus ter = await _context.TerminalsStatus.FirstOrDefaultAsync(t => t.TerminalID.Equals(terminalID));

                if (ter != null)
                {
                    terextDto.terminalEnabled = ter.status;
                }
                else
                {
                    terextDto.terminalEnabled = TerminalStatusDisabled;
                }


                if (existTerminalJPOS(terminalID).Result)
                {
                    //ver cual tomamos del value si el campo que está en ptf o ca
                    //string term = addca+terminalID;
                    //Sysconfig sysconfig = await _MySqlcontext.sysconfig.FirstOrDefaultAsync(t => t.id.Equals(term));
                    //parametros de JPOS falta definir cuales son
                    var jpos = await _MySqlcontext.sysconfig.FirstOrDefaultAsync(j => j.id.Equals(addca + terminalID));

                    if (jpos != null)
                    {
                        if (jpos.value != null)
                        {
                            jpos jp = new jpos();
                            jp.setSysconfigValue_CA(jpos.value);

                            string ca    = jp.getCA();
                            string mcc   = jp.getMcc();
                            string pf_id = jp.getPf_id();
                            string visa_spnsrd_mercht = jp.getVisa_spnsrd_mercht();
                            string amex_id_comercio   = jp.getAmex_id_comercio();

                            terextDto.ca_name            = ca.Length == 0 ? null : ca;
                            terextDto.mcc                = mcc.Length == 0 ? null : mcc;
                            terextDto.pf_id              = pf_id.Length == 0 ? null : pf_id;
                            terextDto.visa_spnsrd_mercht = visa_spnsrd_mercht.Length == 0 ? null : visa_spnsrd_mercht;
                            terextDto.amex_id_comercio   = amex_id_comercio.Length == 0 ? null : amex_id_comercio;
                        }
                    }


                    ///terextDto.id = sysconfig.id;
                    ///terextDto.value = sysconfig.value;

                    //RESPETAR ORDEN COMO EN FullTerminalSystemService
                    //fullTerminalSystem.ca+"."+fullTerminalSystem.mcc+"."+fullTerminalSystem.pf_id+
                    //"."+fullTerminalSystem.visa_spnsrd_mercht+"."+fullTerminalSystem.amex_id_comercio

                    //se agrega ',' (coma) segun req.
                    //RST-64

                    /*char [] splitchar = {','};
                     * string [] strArr = null;
                     * string value = sysconfig.value;
                     * //tomo los 40 caracteres primero y los agrego en caname2
                     * if(value.TrimEnd() != "0")
                     * {
                     *  string caname2 = value.Substring(0,40);
                     *  //tring[] jpos_values= sysconfig.value.Split('.');
                     *  //me quedo con el string luego del caname
                     *  string aux = value.Substring(41);
                     *  //separo por '.' el string restante
                     *  strArr = aux.Split(splitchar);
                     *
                     *  if(strArr.Length > 1)
                     *  {
                     *      //Quita los espacios en blanco del final del String
                     *      terextDto.ca_name=caname2.TrimEnd();
                     *      terextDto.mcc= strArr[0];
                     *      terextDto.pf_id=strArr[1];
                     *      terextDto.visa_spnsrd_mercht=strArr[2];
                     *      terextDto.amex_id_comercio=strArr[3];
                     *  }
                     *  else
                     *  {
                     *      terextDto.ca_name=caname2.TrimEnd();
                     *      terextDto.mcc=null;
                     *      terextDto.pf_id=null;
                     *      terextDto.visa_spnsrd_mercht=null;
                     *      terextDto.amex_id_comercio=null;
                     *
                     *  }
                     * }else
                     * {
                     *  terextDto.ca_name=value.TrimEnd();
                     *  terextDto.mcc=null;
                     *  terextDto.pf_id=null;
                     *  terextDto.visa_spnsrd_mercht=null;
                     *  terextDto.amex_id_comercio=null;
                     * }*/
                }

                terextDto.terminalInit = _csvfile.TerminalInitialized(terminalID) ? 1 : 0;

                serviceResponse.Data = terextDto;
            }

            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
Esempio n. 3
0
        public async Task <ServiceResponse <GetTerminalDto> > InsertFullTerminalSystem(AddFullTerminalSystemDto fullTerminalSystem)
        {
            ServiceResponse <GetTerminalDto> serviceResponse = new ServiceResponse <GetTerminalDto>();


            try
            {
                serviceResponse = await GetTerminalByID(fullTerminalSystem.TerminalID);


                //AGREGO TERMINAL SI NO EXISTE
                if (serviceResponse.Data == null)
                {
                    Terminal terminal = new Terminal();

                    terminal.TerminalID   = fullTerminalSystem.TerminalID;
                    terminal.SerialNumber = fullTerminalSystem.SerialNumber;
                    //rst-69
                    terminal.ParmConnectTime = GetConnectTime.getConnectTime(_context);

                    terminal.Custom1 = fullTerminalSystem.HeaderLine1;
                    terminal.Custom2 = fullTerminalSystem.HeaderLine2;
                    //RUT
                    terminal.Custom3  = addRUT + fullTerminalSystem.HeaderLine3;
                    terminal.Custom4  = fullTerminalSystem.Custom4;
                    terminal.Custom5  = fullTerminalSystem.Custom5;
                    terminal.Custom6  = fullTerminalSystem.Custom6;
                    terminal.Custom7  = fullTerminalSystem.Custom7;
                    terminal.Custom8  = fullTerminalSystem.Custom8;
                    terminal.Custom9  = fullTerminalSystem.Custom9;
                    terminal.Custom10 = fullTerminalSystem.Custom10;
                    terminal.Custom11 = fullTerminalSystem.Custom11;
                    terminal.Custom12 = fullTerminalSystem.Custom12;
                    terminal.Custom13 = fullTerminalSystem.Custom13;
                    terminal.Custom14 = fullTerminalSystem.Custom14;
                    terminal.Custom15 = fullTerminalSystem.Custom15;
                    terminal.Custom16 = fullTerminalSystem.Custom16;
                    //cabal u$s
                    terminal.Custom19 = fullTerminalSystem.Custom19;
                    await _context.Terminals.AddAsync(terminal);

                    //AGREGO SYSTEM
                    SystemPOS systempos = new SystemPOS();
                    systempos.TerminalID   = fullTerminalSystem.TerminalID;
                    systempos.ControlGroup = fullTerminalSystem.ControlGroup;
                    //bool tiene true (checked) por defecto
                    //RST-20
                    if (fullTerminalSystem.ControlCheckSum)
                    {
                        systempos.ControlCheckSum = 0;
                    }

                    systempos.ParameterGroup = fullTerminalSystem.ParameterGroup;
                    //bool tiene true por defecto
                    //RST-20
                    if (fullTerminalSystem.ParameterReload)
                    {
                        systempos.ParameterReload = 1;
                    }

                    systempos.ParameterVersion = fullTerminalSystem.ParameterVersion;
                    systempos.ProgramID        = fullTerminalSystem.ProgramID;
                    //bool Cargar Programa (Program Reload)
                    //RST-20
                    if (fullTerminalSystem.ProgramReload)
                    {
                        systempos.ProgramReload = 1;
                    }

                    systempos.ProgramVersion = fullTerminalSystem.ProgramVersion;
                    systempos.Paquete        = fullTerminalSystem.Paquete;
                    systempos.ConnectGroup   = fullTerminalSystem.ConnectGroup;
                    //bool tiene true (checked) por defecto
                    //RST-20
                    if (fullTerminalSystem.ParmConnChecksum)
                    {
                        systempos.ParmConnChecksum = 0;
                    }

                    //bool viene true por defecto
                    //RST-20
                    if (fullTerminalSystem.TerminalChecksum)
                    {
                        systempos.TerminalChecksum = 0;
                    }


                    await _context.SystemPOSs.AddAsync(systempos);

                    //await _context.SaveChangesAsync();



                    if (fullTerminalSystem.enabled_JPOS)
                    {
                        //AGREGO TerminalStatus 1
                        TerminalStatus term = new TerminalStatus();
                        term.TerminalID = fullTerminalSystem.TerminalID;
                        term.status     = 1;
                        await _context.TerminalsStatus.AddAsync(term);


                        jpos     jpos_value = new jpos();
                        char     pad        = '0';
                        string[] parameters = new string[] {
                            fullTerminalSystem.ca == "" ? null : fullTerminalSystem.ca,
                            fullTerminalSystem.mcc == "" ? null : fullTerminalSystem.mcc,
                            fullTerminalSystem.pf_id == "" || fullTerminalSystem.pf_id == null ? null : fullTerminalSystem.pf_id.PadLeft(11, pad),
                            fullTerminalSystem.visa_spnsrd_mercht == "" ? null : fullTerminalSystem.visa_spnsrd_mercht,
                            fullTerminalSystem.amex_id_comercio == "" ? null : fullTerminalSystem.amex_id_comercio,
                        };

                        Sysconfig sys = await _MySqlcontext.sysconfig.FirstOrDefaultAsync(j => j.id.Equals(addca + fullTerminalSystem.TerminalID));

                        //Existe terminal en jpos con ca.
                        if (sys != null)
                        {
                            if (sys.value != null)
                            {
                                jpos_value.setSysconfigValue_CA(sys.value);
                            }
                        }
                        else
                        {
                            sys    = new Sysconfig();
                            sys.id = addca + fullTerminalSystem.TerminalID;
                            await _MySqlcontext.sysconfig.AddAsync(sys);

                            //AGREGA pft.
                            Sysconfig syspft = new Sysconfig();
                            syspft.id    = addpft + fullTerminalSystem.TerminalID;
                            syspft.value = "handy";
                            await _MySqlcontext.sysconfig.AddAsync(syspft);
                        }

                        jpos_value.updateSysconfigValue_CA(parameters);
                        sys.value = jpos_value.genSysconfigValue_CA();
                    }



                    //commit luego de todos los cambios
                    await _context.SaveChangesAsync();

                    await _MySqlcontext.SaveChangesAsync();

                    //AGREGO LINEA AL ARCHIVO TERMINALS
                    _csvfile.AppendTerminalsLine(fullTerminalSystem);

                    //AGREGO LINEA AL ARCHIVO SYSTEM
                    _csvfile.AppendSystemLine(fullTerminalSystem);

                    serviceResponse = await GetTerminalByID(fullTerminalSystem.TerminalID);
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Terminal Existente.";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
Esempio n. 4
0
        public async Task <ServiceResponse <GetFullTerminalSystemDto> > UpdateFulTerminalSystem(GetFullTerminalSystemDto updateFullTerminalSystem)
        {
            ServiceResponse <GetFullTerminalSystemDto> serviceResponse = new ServiceResponse <GetFullTerminalSystemDto>();

            try
            {
                bool     rstTerminalChecksum = false;
                bool     rstTranConnChecksum = false;
                bool     rstControlChecksum  = false;
                bool     newPackage          = false;
                Terminal terminal            = await _context.Terminals.FirstOrDefaultAsync(ct => ct.TerminalID.Equals(updateFullTerminalSystem.TerminalID));

                SystemPOS systempos = await _context.SystemPOSs.FirstOrDefaultAsync(ct => ct.TerminalID.Equals(updateFullTerminalSystem.TerminalID));

                if (terminal.TerminalID != updateFullTerminalSystem.TerminalID ||
                    terminal.SerialNumber != updateFullTerminalSystem.SerialNumber ||
                    //rst-69
                    terminal.ParmConnectTime != updateFullTerminalSystem.ParmConnectTime ||
                    terminal.Custom1 != updateFullTerminalSystem.HeaderLine1 ||
                    terminal.Custom2 != updateFullTerminalSystem.HeaderLine2 ||
                    //addRUT
                    terminal.Custom3 != addRUT + updateFullTerminalSystem.HeaderLine3 ||
                    terminal.Custom4 != updateFullTerminalSystem.Custom4 ||
                    terminal.Custom5 != updateFullTerminalSystem.Custom5 ||
                    terminal.Custom6 != updateFullTerminalSystem.Custom6 ||
                    terminal.Custom7 != updateFullTerminalSystem.Custom7 ||
                    terminal.Custom8 != updateFullTerminalSystem.Custom8 ||
                    terminal.Custom9 != updateFullTerminalSystem.Custom9 ||
                    terminal.Custom10 != updateFullTerminalSystem.Custom10 ||
                    terminal.Custom11 != updateFullTerminalSystem.Custom11 ||
                    terminal.Custom12 != updateFullTerminalSystem.Custom12 ||
                    terminal.Custom13 != updateFullTerminalSystem.Custom13 ||
                    terminal.Custom14 != updateFullTerminalSystem.Custom14 ||
                    terminal.Custom15 != updateFullTerminalSystem.Custom15 ||
                    terminal.Custom16 != updateFullTerminalSystem.Custom16 ||
                    terminal.Custom19 != updateFullTerminalSystem.Custom19 ||
                    updateFullTerminalSystem.TerminalChecksum)
                {
                    systempos.TerminalChecksum = 0;
                    rstTerminalChecksum        = true;
                }

                terminal.TerminalID   = updateFullTerminalSystem.TerminalID;
                terminal.SerialNumber = updateFullTerminalSystem.SerialNumber;
                //rst-69
                terminal.ParmConnectTime = updateFullTerminalSystem.ParmConnectTime;
                terminal.Custom1         = updateFullTerminalSystem.HeaderLine1;
                terminal.Custom2         = updateFullTerminalSystem.HeaderLine2;
                //addRUT
                terminal.Custom3  = addRUT + updateFullTerminalSystem.HeaderLine3;
                terminal.Custom4  = updateFullTerminalSystem.Custom4;
                terminal.Custom5  = updateFullTerminalSystem.Custom5;
                terminal.Custom6  = updateFullTerminalSystem.Custom6;
                terminal.Custom7  = updateFullTerminalSystem.Custom7;
                terminal.Custom8  = updateFullTerminalSystem.Custom8;
                terminal.Custom9  = updateFullTerminalSystem.Custom9;
                terminal.Custom10 = updateFullTerminalSystem.Custom10;
                terminal.Custom11 = updateFullTerminalSystem.Custom11;
                terminal.Custom12 = updateFullTerminalSystem.Custom12;
                terminal.Custom13 = updateFullTerminalSystem.Custom13;
                terminal.Custom14 = updateFullTerminalSystem.Custom14;
                terminal.Custom15 = updateFullTerminalSystem.Custom15;
                terminal.Custom16 = updateFullTerminalSystem.Custom16;
                terminal.Custom19 = updateFullTerminalSystem.Custom19;


                if (systempos.ControlGroup != updateFullTerminalSystem.merchanType || updateFullTerminalSystem.ControlCheckSum)
                {
                    systempos.ControlGroup    = updateFullTerminalSystem.merchanType;
                    systempos.ControlCheckSum = 0;
                    rstControlChecksum        = true;
                }


                if (systempos.ConnectGroup != updateFullTerminalSystem.ConnectGroup || updateFullTerminalSystem.ParmConnChecksum)
                {
                    systempos.ConnectGroup      = updateFullTerminalSystem.ConnectGroup;
                    systempos.ParmConnChecksum  = 0;
                    systempos.TranConnChecksum1 = 0;
                    systempos.TranConnChecksum2 = 0;
                    rstTranConnChecksum         = true;
                }

                //rst-70
                if (updateFullTerminalSystem.ParameterReload)
                {
                    systempos.ParameterReload = 1;
                }
                //rst70 inicio
                else
                {
                    systempos.ParameterReload = 0;
                }
                //rst70 fin

                if (updateFullTerminalSystem.ProgramReload)
                {
                    systempos.ProgramReload = 1;
                }
                //rst70 inicio
                else
                {
                    systempos.ProgramReload = 0;
                }
                //rst70 fin

                if (systempos.Paquete != updateFullTerminalSystem.Paquete)
                {
                    newPackage = true;
                }

                systempos.ParameterGroup   = updateFullTerminalSystem.ParameterGroup;
                systempos.ParameterVersion = updateFullTerminalSystem.ParameterVersion;
                systempos.ProgramID        = updateFullTerminalSystem.ProgramID;
                systempos.ProgramVersion   = updateFullTerminalSystem.ProgramVersion;
                systempos.Paquete          = updateFullTerminalSystem.Paquete;


                TerminalStatus term = await _context.TerminalsStatus.FirstOrDefaultAsync(te => te.TerminalID.Equals(updateFullTerminalSystem.TerminalID));

                if (term == null)
                {
                    term            = new TerminalStatus();
                    term.TerminalID = updateFullTerminalSystem.TerminalID;
                    term.status     = updateFullTerminalSystem.enabled_JPOS ? 1 : 0;
                    await _context.TerminalsStatus.AddAsync(term);
                }
                else
                {
                    term.status = updateFullTerminalSystem.enabled_JPOS ? 1 : 0;
                }

                jpos     jpos_value = new jpos();
                char     pad        = '0';
                string[] parameters = new string[] {
                    updateFullTerminalSystem.ca == "" ? null : updateFullTerminalSystem.ca,
                    updateFullTerminalSystem.mcc == "" ? null : updateFullTerminalSystem.mcc,
                    updateFullTerminalSystem.pf_id == "" || updateFullTerminalSystem.pf_id == null ? null : updateFullTerminalSystem.pf_id.PadLeft(11, pad),
                    updateFullTerminalSystem.visa_spnsrd_mercht == "" ? null : updateFullTerminalSystem.visa_spnsrd_mercht,
                    updateFullTerminalSystem.amex_id_comercio == "" ? null : updateFullTerminalSystem.amex_id_comercio,
                };


                Sysconfig sys = await _MySqlcontext.sysconfig.FirstOrDefaultAsync(j => j.id.Equals(addca + updateFullTerminalSystem.TerminalID));

                if (sys == null)
                {
                    sys    = new Sysconfig();
                    sys.id = addca + updateFullTerminalSystem.TerminalID;
                    await _MySqlcontext.sysconfig.AddAsync(sys);
                }

                jpos_value.updateSysconfigValue_CA(parameters);
                sys.value = jpos_value.genSysconfigValue_CA();

                await _context.SaveChangesAsync();

                await _MySqlcontext.SaveChangesAsync();

                //ACTUALIZA LINEA AL ARCHIVO TERMINALS
                _csvfile.UpdateTerminalsLine(updateFullTerminalSystem.TerminalID, updateFullTerminalSystem);

                //ACTUALIZA LINEA AL ARCHIVO SYSTEM

                _csvfile.UpdateSystemLine(updateFullTerminalSystem.TerminalID, updateFullTerminalSystem, rstTerminalChecksum, rstTranConnChecksum, rstControlChecksum, newPackage);

                serviceResponse = await GetFullTerminalSystemByID(updateFullTerminalSystem.TerminalID);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }
Esempio n. 5
0
        public async Task <ServiceResponse <GetFullTerminalSystemDto> > GetFullTerminalSystemByID(string terminal_id)
        {
            ServiceResponse <GetFullTerminalSystemDto> serviceResponse = new ServiceResponse <GetFullTerminalSystemDto>();

            try
            {
                var terminal = await _context.Terminals.FirstOrDefaultAsync(t => t.TerminalID.Equals(terminal_id));

                var system = await _context.SystemPOSs.FirstOrDefaultAsync(t => t.TerminalID.Equals(terminal_id));

                GetFullTerminalSystemDto fullTerminalSystem = new GetFullTerminalSystemDto();
                fullTerminalSystem.TerminalID   = terminal.TerminalID;
                fullTerminalSystem.SerialNumber = terminal.SerialNumber;
                //rst-69
                fullTerminalSystem.ParmConnectTime = terminal.ParmConnectTime;
                fullTerminalSystem.HeaderLine1     = terminal.Custom1;
                fullTerminalSystem.HeaderLine2     = terminal.Custom2;

                //remove RUT:
                fullTerminalSystem.HeaderLine3 = terminal.Custom3.Remove(0, 4);
                fullTerminalSystem.Custom4     = terminal.Custom4;
                fullTerminalSystem.Custom5     = terminal.Custom5;
                fullTerminalSystem.Custom6     = terminal.Custom6;
                fullTerminalSystem.Custom7     = terminal.Custom7;
                fullTerminalSystem.Custom8     = terminal.Custom8;
                fullTerminalSystem.Custom9     = terminal.Custom9;
                fullTerminalSystem.Custom10    = terminal.Custom10;
                fullTerminalSystem.Custom11    = terminal.Custom11;
                fullTerminalSystem.Custom12    = terminal.Custom12;
                fullTerminalSystem.Custom13    = terminal.Custom13;
                fullTerminalSystem.Custom14    = terminal.Custom14;
                fullTerminalSystem.Custom15    = terminal.Custom15;
                fullTerminalSystem.Custom16    = terminal.Custom16;
                fullTerminalSystem.Custom19    = terminal.Custom19;
                fullTerminalSystem.merchanType = system.ControlGroup;

                //actualizar datos terminal
                if (system.TerminalChecksum == 0)
                {
                    fullTerminalSystem.TerminalChecksum = true;
                }
                else
                {
                    fullTerminalSystem.TerminalChecksum = false;
                }

                //actualizar parametros de conexion
                if (system.ParmConnChecksum == 0)
                {
                    fullTerminalSystem.ParmConnChecksum = true;
                }
                else
                {
                    fullTerminalSystem.ParmConnChecksum = false;
                }

                //actualizar tipo de comercio - controlchecksum
                if (system.ControlCheckSum == 0)
                {
                    fullTerminalSystem.ControlCheckSum = true;
                }
                else
                {
                    fullTerminalSystem.ControlCheckSum = false;
                }

                //cargar parametros de conexion
                if (system.ParameterReload == 1)
                {
                    fullTerminalSystem.ParameterReload = true;
                }
                else
                {
                    fullTerminalSystem.ParameterReload = false;
                }

                //cargar programa - program reload
                if (system.ProgramReload == 1)
                {
                    fullTerminalSystem.ProgramReload = true;
                }
                else
                {
                    fullTerminalSystem.ProgramReload = false;
                }

                fullTerminalSystem.ParameterGroup   = system.ParameterGroup;
                fullTerminalSystem.ParameterVersion = system.ParameterVersion;
                fullTerminalSystem.ProgramID        = system.ProgramID;
                fullTerminalSystem.ProgramVersion   = system.ProgramVersion;
                fullTerminalSystem.Paquete          = system.Paquete;
                fullTerminalSystem.ConnectGroup     = system.ConnectGroup;


                //parametros de JPOS falta definir cuales son
                var jpos = await _MySqlcontext.sysconfig.FirstOrDefaultAsync(j => j.id.Equals(addca + fullTerminalSystem.TerminalID));

                if (jpos != null)
                {
                    if (jpos.value != null)
                    {
                        jpos jp = new jpos();
                        jp.setSysconfigValue_CA(jpos.value);

                        string ca    = jp.getCA();
                        string mcc   = jp.getMcc();
                        string pf_id = jp.getPf_id();
                        string visa_spnsrd_mercht = jp.getVisa_spnsrd_mercht();
                        string amex_id_comercio   = jp.getAmex_id_comercio();

                        fullTerminalSystem.ca    = ca.Length == 0 ? null : ca;
                        fullTerminalSystem.mcc   = mcc.Length == 0 ? null : mcc;
                        fullTerminalSystem.pf_id = pf_id.Length == 0 ? null : pf_id;
                        fullTerminalSystem.visa_spnsrd_mercht = visa_spnsrd_mercht.Length == 0 ? null : visa_spnsrd_mercht;
                        fullTerminalSystem.amex_id_comercio   = amex_id_comercio.Length == 0 ? null : amex_id_comercio;
                    }

                    var status = await _context.TerminalsStatus.FirstOrDefaultAsync(s => s.TerminalID.Equals(terminal_id));

                    if (status != null)
                    {
                        if (status.status == 1)
                        {
                            fullTerminalSystem.enabled_JPOS = true;
                        }
                        else
                        {
                            fullTerminalSystem.enabled_JPOS = false;
                        }
                    }
                    else
                    {
                        fullTerminalSystem.enabled_JPOS = false;
                    }
                }
                serviceResponse.Data = fullTerminalSystem;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }