Exemplo n.º 1
0
    public async Task <ServiceResponse <GetTerminalDto> > AddTerminal(GetTerminalDto terminal_dto)
    {
        ServiceResponse <GetTerminalDto> serviceResponse = new ServiceResponse <GetTerminalDto>();

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

            if (ter == null)
            {
                // AGREGA AL ARCHIVO
                _csvfile.AppendTerminalsLine(terminal_dto);

                var terminal = _mapper.Map <Terminal>(terminal_dto);

                var newTerminal = await _context.Terminals.AddAsync(terminal);

                await _context.SaveChangesAsync();

                serviceResponse.Data = _mapper.Map <GetTerminalDto>(terminal);
            }
            else
            {
                serviceResponse.Message = " Terminal ID ya existe. ";
            }
        }
        catch (Exception ex)
        { if (ex is DbUpdateException)
          {
              serviceResponse.Success = false;
              serviceResponse.Message = "DbUpdateException" + ex.Message;
          }
          else
          {
              serviceResponse.Success = false;
          }
          serviceResponse.Message = ex.Message; }
        return(serviceResponse);
    }
Exemplo n.º 2
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);
        }