コード例 #1
0
        public JsonResult GetEmpresa()
        {
            const int idLogin = 6;

            /*Obtener inforamcion del login y las empresas que tiene asociadas*/

            LoginEmpresaBL            loginEmpresaBL      = new LoginEmpresaBL();
            GetLoginEmpresaRequestDTO loginEmpresaRequest = new GetLoginEmpresaRequestDTO();

            loginEmpresaRequest.IdLogin = idLogin;

            GetLoginEmpresaResponseDTO loginEmpresaResponse = new GetLoginEmpresaResponseDTO();

            loginEmpresaResponse = loginEmpresaBL.GetLoginEmpresa(loginEmpresaRequest);

            List <LoginEmpresa> listaLoginEmpresa = new List <LoginEmpresa>();

            if (loginEmpresaResponse.Mensaje == "OK")
            {
                listaLoginEmpresa = loginEmpresaResponse.ListaLoginEmpresa;
            }

            /*Obtiene todas las empresas*/
            EmpresaBL empresaBL = new EmpresaBL();

            GetEmpresaRequestDTO empresaRequest = new GetEmpresaRequestDTO();

            GetEmpresaResponseDTO empresaResponse = new GetEmpresaResponseDTO();

            empresaResponse = empresaBL.GetEmpresa(empresaRequest);

            List <Empresa> listaEmpresa = new List <Empresa>();

            if (empresaResponse.Mensaje == "OK")
            {
                listaEmpresa = empresaResponse.ListaEmpresa;
            }

            listaEmpresa = empresaResponse.ListaEmpresa;

            /*Realiza un cruce para obtenre las empresas con el login asociado*/

            List <Empresa> ListaEmpresaActual = new List <Empresa>();

            ListaEmpresaActual = (from loginEmpresa in listaLoginEmpresa
                                  join empresa in listaEmpresa on loginEmpresa.idEmpresa equals empresa.idEmpresa
                                  select empresa).ToList();

            ViewBag.ListaEmpresaActual = ListaEmpresaActual;

            return(Json(ListaEmpresaActual, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public GetEmpresaResponseDTO GetEmpresa(GetEmpresaRequestDTO empresaRequest)
        {
            GetEmpresaResponseDTO empresaResponse = new GetEmpresaResponseDTO();
            List <Empresa>        listaEmpresa    = new List <Empresa>();

            EmpresaDal empresaDal = new EmpresaDal();
            DataTable  dtDatos    = new DataTable();

            try
            {
                dtDatos = empresaDal.GetEmpresa(empresaRequest.IdEmpresa, empresaRequest.Empresa);

                listaEmpresa = dtDatos.AsEnumerable()
                               .Select(row => new Empresa
                {
                    idEmpresa         = row.Field <int?>("idEmpresa").GetValueOrDefault(),
                    empresa1          = string.IsNullOrEmpty(row.Field <string>("empresa")) ? "" : row.Field <string>("empresa"),
                    puestoContacto    = string.IsNullOrEmpty(row.Field <string>("puestoContacto")) ? "" : row.Field <string>("puestoContacto"),
                    apellidoPContacto = string.IsNullOrEmpty(row.Field <string>("apellidoPContacto")) ? "" : row.Field <string>("apellidoPContacto"),
                    apellidoMContacto = string.IsNullOrEmpty(row.Field <string>("apellidoMContacto")) ? "" : row.Field <string>("apellidoMContacto"),
                    nombreContacto    = string.IsNullOrEmpty(row.Field <string>("nombreContacto")) ? "" : row.Field <string>("nombreContacto"),
                    correoContacto    = string.IsNullOrEmpty(row.Field <string>("correoContacto")) ? "" : row.Field <string>("correoContacto"),
                    telefonoContacto  = string.IsNullOrEmpty(row.Field <string>("telefonoContacto")) ? "" : row.Field <string>("telefonoContacto"),
                    telefono2Contacto = string.IsNullOrEmpty(row.Field <string>("telefono2Contacto")) ? "" : row.Field <string>("telefono2Contacto"),
                    estatus           = row.Field <bool?>("estatus").GetValueOrDefault(),
                    usuarioInsert     = string.IsNullOrEmpty(row.Field <string>("usuarioInsert")) ? "" : row.Field <string>("usuarioInsert"),
                    fechaInsert       = row.Field <DateTime?>("fechaInsert").GetValueOrDefault(),
                    usuarioUpdate     = string.IsNullOrEmpty(row.Field <string>("usuarioUpdate")) ? "" : row.Field <string>("usuarioUpdate"),
                    fechaUpdate       = row.Field <DateTime?>("fechaUpdate").GetValueOrDefault(),
                }).ToList();

                empresaResponse.ListaEmpresa = listaEmpresa;
                empresaResponse.Mensaje      = "OK";
            }
            catch (Exception ex)
            {
                empresaResponse.ListaEmpresa = new List <Empresa>();
                empresaResponse.Mensaje      = "ERROR: " + ex.Message;
            }

            return(empresaResponse);
        }