Beispiel #1
0
        public async Task <bool> ValidatePassword(int idUsuario, string passwordApp)
        {
            SpGetPassword procedure = await _context.Query <SpGetPassword>().FromSql("EXEC SP_GET_PASSWORD @p0", idUsuario).SingleOrDefaultAsync();

            if (!procedure.pw.Equals(passwordApp))
            {
                return(false);
            }

            return(true);
        }
        public async Task<ActionResult> GetLoginRequest(LoginRequest req)
        {
            if (req == null) return BadRequest("No se ingresaron los datos solicitados");

            try
            {
                var dataApp = await _context.BdApplicationVersions.Where(x => x.Status).FirstOrDefaultAsync();
                if(dataApp.BuildNumber == req.buildNumber && dataApp.Version == req.version)
                {
                    int idusuario = await _context.CUsuarios.Where(x => x.Username == req.username).Select(x => x.IdUsuario).SingleOrDefaultAsync();
                    var usuario = await _context.CUsuarios.Where(x => x.IdUsuario == idusuario).SingleOrDefaultAsync();
                    var UsuarioPhone = _context.BdUsuarioCelular.Where(x => x.IdUsuario == idusuario).FirstOrDefault();

                    if (UsuarioPhone != null)
                    {
                        if (UsuarioPhone.Imei != req.imei)
                        {
                            if (UsuarioPhone.Imei == null)
                            {
                                UsuarioPhone.Imei = req.imei;
                                _context.SaveChanges();
                            }
                            else
                            {
                                return NotFound(new { Texterror = "IMEI" });
                            }
                        }
                    }
                    else
                    {
                        BdUsuarioCelular celular = new BdUsuarioCelular()
                        {
                            IdUsuario = idusuario,
                            IdUsuarioAlta = 559,
                            FecAlta = DateTime.Now,
                            Imei = req.imei
                        };
                        _context.BdUsuarioCelular.Add(celular);
                        _context.SaveChanges();
                    }

                    if (usuario == null)
                    {
                        return NotFound();
                    }

                    SpGetPassword pw = await _context.Query<SpGetPassword>().FromSql("EXEC SP_GET_PASSWORD @p0", idusuario).SingleOrDefaultAsync();

                    if (usuario.IsPda != 1)
                    {
                        return NotFound(new { Texterror = "El usuario no es PDA" });
                    }

                    if (!req.password.Equals(pw.pw))
                    {
                        return NotFound();
                    }

                    BdBitacoraAcceso acceso = new BdBitacoraAcceso()
                    {
                        IdUsuario = idusuario,
                        Acceso = DateTime.Now,
                        FecStatus = DateTime.Now,
                        Status = "ACTIVO",
                        IpCliente = req.imei,
                        Host = "ACCESO APLICACION"
                    };
                    _context.BdBitacoraAcceso.Add(acceso);
                    await _context.SaveChangesAsync();
                    return Ok(new { user = usuario.Nombre + " " + usuario.Paterno + " " + usuario.Materno, idusuario = usuario.IdUsuario });
                }
                else
                {
                    return BadRequest(new { Texterror = "VERSION"});
                }
            }
            catch (Exception ex)
            {
                return BadRequest(ex.StackTrace);
            }

        }
        public async Task <ActionResult> LayoutMasivo(LayoutMasivoRequest layout, CancellationToken cancellationToken)
        {
            if (layout == null)
            {
                return(BadRequest("La solicitud esta vacia."));
            }

            try
            {
                string           folder      = "C:\\inetpub\\wwwroot\\" + appname + "\\REPORTES\\LAYOUT_MASIVO\\ARCHIVOS";
                string           name        = "Layout_Masivo_OTD.xlsx";
                string           downloadUrl = "C:\\inetpub\\wwwroot\\" + appname + "\\REPORTES\\LAYOUT_MASIVO\\ARCHIVOS\\" + name;
                Nullable <Int64> inull       = null;
                FileInfo         file        = new FileInfo(Path.Combine(folder, name));

                var columHeaders = new string[]
                {
                    "ODT",
                    "Discover",
                    "Afiliación",
                    "Comercio",
                    "Dirección",
                    "Colonia",
                    "Ciudad",
                    "Estado",
                    "Fecha Alta",
                    "Fecha Vencimiento",
                    "Descripción",
                    "Observaciones",
                    "Telefono",
                    "Tipo Comercio",
                    "Nivel",
                    "Tipo Servicio",
                    "Subtipo Servicio",
                    "Criterio de Cambio",
                    "Tecnico",
                    "Proveedor",
                    "Estatus Servicio",
                    "Fecha Atención Proveedor",
                    "Fecha Cierre Sistema",
                    "Fecha Alta Sistema",
                    "Codigo Postal",
                    "Conclusiones",
                    "Conectividad",
                    "Modelo",
                    "Id Equipo",
                    "Id Caja",
                    "RFC",
                    "Razón Social",
                    "Horas Vencidas",
                    "Tiempo en atender",
                    "SLA Fijo",
                    "Nivel",
                    "Telefonos en Campo",
                    "Tipo Comercio",
                    "Afiliacion Amex",
                    "IdAmex",
                    "Producto",
                    "Motivo Cancelación",
                    "Motivo Rechazo",
                    "Email",
                    "Rollos a instalar",
                    "Num Serie Terminal Entra",
                    "Num Serie Terminal Sale",
                    "Num Serie Terminal mto",
                    "Num Serie Sim Sale",
                    "Num Serie Sim Entra",
                    "VersionSW",
                    "Cargador",
                    "Base",
                    "Rollo Entregados",
                    "Cable corriente",
                    "Zona",
                    "Modelo Instalado",
                    "Modelo Terminal Sale",
                    "Correo Ejecutivo",
                    "Rechazo",
                    "Contacto 1",
                    "Atiende en comercio",
                    "Tid Amex Cierre",
                    "Afiliacion Amex Cierre",
                    "Codigo",
                    "Tiene Amex",
                    "Act Referencias",
                    "Tipo_A_b",
                    "Domicilio Alterno",
                    "Cantidad Archivos",
                    "Area Carga",
                    "Alta Por",
                    "Tipo Carga",
                    "Cerrado Por",
                    "Serie"
                };
                if (file.Exists)
                {
                    file.Delete();
                    file = new FileInfo(Path.Combine(folder, name));
                }
                List <SpGetLayoutMasivo> procedure = new List <SpGetLayoutMasivo>();

                procedure = await context_.Query <SpGetLayoutMasivo>().FromSql("EXEC SP_LAYOUT_MASIVO @p0,@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8",
                                                                               layout.fec_ini,
                                                                               layout.fec_fin,
                                                                               layout.id_proveedor,
                                                                               layout.status_servicio,
                                                                               layout.id_zona,
                                                                               layout.id_proyecto,
                                                                               layout.fec_ini_cierre,
                                                                               layout.fec_fin_cierre,
                                                                               layout.serie).ToListAsync();

                using (var package = new ExcelPackage(file))
                {
                    var worksheet = package.Workbook.Worksheets.Add("Consulta");
                    using (var cells = worksheet.Cells[1, 1, 1, 75])
                    {
                        cells.Style.Font.Bold = true;
                        cells.Style.Font.Color.SetColor(Color.White);
                        cells.Style.Fill.PatternType = ExcelFillStyle.Solid;
                        cells.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(0, 128, 255));
                    }

                    for (int i = 0; i < columHeaders.Count(); i++)
                    {
                        worksheet.Cells[1, i + 1].Value = columHeaders[i];
                    }

                    var j = 2;

                    foreach (var servicio in procedure)
                    {
                        worksheet.Cells["A" + j].Value = servicio.ODT;
                        worksheet.Cells["B" + j].Value = servicio.DISCOVER;
                        worksheet.Cells["C" + j].Style.Numberformat.Format = "0";
                        worksheet.Cells["C" + j].Value = servicio.AFILIACION == "" ? inull : Convert.ToInt64(servicio.AFILIACION);
                        worksheet.Cells["D" + j].Value = servicio.COMERCIO;
                        worksheet.Cells["E" + j].Value = servicio.DIRECCION;
                        worksheet.Cells["F" + j].Value = servicio.COLONIA;
                        worksheet.Cells["G" + j].Value = servicio.POBLACION;
                        worksheet.Cells["H" + j].Value = servicio.ESTADO;
                        worksheet.Cells["I" + j].Style.Numberformat.Format = "dd/mm/yyyy hh:mm:ss";
                        worksheet.Cells["I" + j].Value = servicio.FECHA_ALTA;
                        worksheet.Cells["J" + j].Style.Numberformat.Format = "dd/mm/yyyy hh:mm:ss";
                        worksheet.Cells["J" + j].Value = servicio.FECHA_VENCIMIENTO;
                        worksheet.Cells["K" + j].Value = servicio.DESCRIPCION;
                        worksheet.Cells["L" + j].Value = servicio.OBSERVACIONES;
                        worksheet.Cells["M" + j].Value = servicio.TELEFONO;
                        worksheet.Cells["N" + j].Value = servicio.TIPO_COMERCIO;
                        worksheet.Cells["O" + j].Value = servicio.NIVEL;
                        worksheet.Cells["P" + j].Value = servicio.TIPO_SERVICIO;
                        worksheet.Cells["Q" + j].Value = servicio.SUB_TIPO_SERVICIO;
                        worksheet.Cells["R" + j].Value = servicio.CRITERIO_CAMBIO;
                        worksheet.Cells["S" + j].Value = servicio.ID_TECNICO;
                        worksheet.Cells["T" + j].Value = servicio.PROVEEDOR;
                        worksheet.Cells["U" + j].Value = servicio.ESTATUS_SERVICIO;
                        worksheet.Cells["V" + j].Style.Numberformat.Format = "dd/mm/yyyy hh:mm:ss";
                        worksheet.Cells["V" + j].Value = servicio.FECHA_ATENCION_PROVEEDOR;
                        worksheet.Cells["W" + j].Style.Numberformat.Format = "dd/mm/yyyy hh:mm:ss";
                        worksheet.Cells["W" + j].Value = servicio.FECHA_CIERRE_SISTEMA;
                        worksheet.Cells["X" + j].Style.Numberformat.Format = "dd/mm/yyyy hh:mm:ss";
                        worksheet.Cells["X" + j].Value  = servicio.FECHA_ALTA_SISTEMA;
                        worksheet.Cells["Y" + j].Value  = servicio.CODIGO_POSTAL;
                        worksheet.Cells["Z" + j].Value  = servicio.CONCLUSIONES;
                        worksheet.Cells["AA" + j].Value = servicio.CONECTIVIDAD;
                        worksheet.Cells["AB" + j].Value = servicio.MODELO;
                        worksheet.Cells["AC" + j].Value = servicio.EQUIPO;
                        worksheet.Cells["AD" + j].Value = servicio.CAJA;
                        worksheet.Cells["AE" + j].Value = servicio.RFC;
                        worksheet.Cells["AF" + j].Value = servicio.RAZON_SOCIAL;
                        worksheet.Cells["AG" + j].Value = servicio.HORAS_VENCIDAS;
                        worksheet.Cells["AH" + j].Value = servicio.TIEMPO_EN_ATENDER;
                        worksheet.Cells["AI" + j].Value = servicio.SLA_FIJO;
                        worksheet.Cells["AJ" + j].Value = servicio.NIVEL;
                        worksheet.Cells["AK" + j].Value = servicio.TELEFONOS_EN_CAMPO;
                        worksheet.Cells["AL" + j].Value = servicio.TIPO_COMERCIO;
                        worksheet.Cells["AM" + j].Value = servicio.AFILIACION_AMEX;
                        worksheet.Cells["AN" + j].Value = servicio.IDAMEX;
                        worksheet.Cells["AO" + j].Value = servicio.PRODUCTO;
                        worksheet.Cells["AP" + j].Value = servicio.MOTIVO_CANCELACION;
                        worksheet.Cells["AQ" + j].Value = servicio.MOTIVO_RECHAZO;
                        worksheet.Cells["AR" + j].Value = servicio.EMAIL;
                        worksheet.Cells["AS" + j].Value = servicio.ROLLOS_A_INSTALAR;
                        worksheet.Cells["AT" + j].Value = servicio.NUM_SERIE_TERMINAL_ENTRA;
                        worksheet.Cells["AU" + j].Value = servicio.NUM_SERIE_TERMINAL_SALE;
                        worksheet.Cells["AV" + j].Value = servicio.NUM_SERIE_TERMINAL_MTO;
                        worksheet.Cells["AW" + j].Value = servicio.NUM_SERIE_SIM_SALE;
                        worksheet.Cells["AX" + j].Value = servicio.NUM_SERIE_SIM_ENTRA;
                        worksheet.Cells["AY" + j].Value = servicio.VERSIONSW;
                        worksheet.Cells["AZ" + j].Value = servicio.CARGADOR;
                        worksheet.Cells["BA" + j].Value = servicio.BASE;
                        worksheet.Cells["BB" + j].Value = servicio.ROLLO_ENTREGADOS;
                        worksheet.Cells["BC" + j].Value = servicio.CABLE_CORRIENTE;
                        worksheet.Cells["BD" + j].Value = servicio.ZONA;
                        worksheet.Cells["BE" + j].Value = servicio.MODELO_INSTALADO;
                        worksheet.Cells["BF" + j].Value = servicio.MODELO_TERMINAL_SALE;
                        worksheet.Cells["BG" + j].Value = servicio.CORREO_EJECUTIVO;
                        worksheet.Cells["BH" + j].Value = servicio.RECHAZO;
                        worksheet.Cells["BI" + j].Value = servicio.CONTACTO1;
                        worksheet.Cells["BJ" + j].Value = servicio.ATIENDE_EN_COMERCIO;
                        worksheet.Cells["BK" + j].Value = servicio.TID_AMEX_CIERRE;
                        worksheet.Cells["BL" + j].Value = servicio.AFILIACION_AMEX_CIERRE;
                        worksheet.Cells["BM" + j].Value = servicio.CODIGO;
                        worksheet.Cells["BN" + j].Value = servicio.TIENE_AMEX;
                        worksheet.Cells["BO" + j].Value = servicio.ACT_REFERENCIAS;
                        worksheet.Cells["BP" + j].Value = servicio.TIPO_A_B;
                        worksheet.Cells["BQ" + j].Value = servicio.DIRECCION_ALTERNA_COMERCIO;
                        worksheet.Cells["BR" + j].Value = servicio.CANTIDAD_ARCHIVOS;
                        worksheet.Cells["BS" + j].Value = servicio.AREA_CARGA;
                        worksheet.Cells["BT" + j].Value = servicio.ALTA_POR;
                        worksheet.Cells["BU" + j].Value = servicio.TIPO_CARGA;
                        worksheet.Cells["BV" + j].Value = servicio.CERRADO_POR;
                        worksheet.Cells["BW" + j].Value = servicio.SERIE;

                        j++;
                    }
                    worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
                    package.Save();
                }
                return(Ok(name));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }