Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo 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);
        }