Пример #1
0
        // GET: PersonasDeContacto
        public ActionResult Index(string idPartner)
        {
            ViewBag.PartnerId = idPartner;
            var personasDeContacto = _personaDeContactoRepository.ObetenerPersonasDeContactoPorIdPartner(idPartner);

            return(PartialView("Index", personasDeContacto.ToList()));
        }
Пример #2
0
        public ActionResult CargarProveedoresInternos(JQueryDataTableParamModel param)
        {
            var listInternos = _partnerRepository.ObtenerPartnersInternos().Where(m => m.FechaBaja == null).ToList();

            foreach (var interno in listInternos)
            {
                var dire = _direccionRepository.ObtenerDireccionPorIdPartner(interno.Id.ToString());
                var contactoPrincipal =
                    _personaDeContactoRepository.ObetenerPersonasDeContactoPorIdPartner(interno.Id.ToString()).Where(m => m.Principal == true);

                interno.PersonasDeContacto = contactoPrincipal.ToList();
                interno.DireccionPrincipal = (DireccionPrincipal)dire;
            }

            IEnumerable <PartnerInterno> filteredCompanies;

            if (!string.IsNullOrEmpty(param.sSearch))
            {
                //Used if particulare columns are filtered
                var nombreFilter   = Convert.ToString(Request["sSearch_1"]);
                var contactoFilter = Convert.ToString(Request["sSearch_2"]);

                //Optionally check whether the columns are searchable at all
                var isNombreSearchable   = Convert.ToBoolean(Request["bSearchable_1"]);
                var isContactoSearchable = Convert.ToBoolean(Request["bSearchable_2"]);


                filteredCompanies = listInternos?.ToList()
                                    .Where(c => isNombreSearchable && c.Nombre.ToLower().Contains(param.sSearch.ToLower())
                                           ||
                                           isContactoSearchable && c.Cif.ToLower().Contains(param.sSearch.ToLower()));
            }
            else
            {
                filteredCompanies = listInternos;
            }

            var isNombreSortable   = Convert.ToBoolean(Request["bSortable_1"]);
            var isContactoSortable = Convert.ToBoolean(Request["bSortable_2"]);

            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
            Func <PartnerInterno, string> orderingFunction = (c => sortColumnIndex == 1 && isNombreSortable
                ? c.Nombre
                : sortColumnIndex == 2 && isContactoSortable
                    ? c.DireccionPrincipal.Calle: "");

            var sortDirection = Request["sSortDir_0"]; // asc or desc

            filteredCompanies = sortDirection == "asc" ? filteredCompanies.OrderBy(orderingFunction) : filteredCompanies.OrderByDescending(orderingFunction);

            var displayedCompanies = filteredCompanies.Skip(param.iDisplayStart).Take(param.iDisplayLength);

            var result = from c in displayedCompanies
                         select new[]
            {
                Convert.ToString(c.Id),
                c.Nombre,
                c.PersonasDeContacto.First().Nombre,
                c.PersonasDeContacto.First().Telefono,
                c.ActividadProfesional,
                c.FechaAlta
            };

            return(Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = listInternos.Count(),
                iTotalDisplayRecords = filteredCompanies.Count(),
                aaData = result
            },
                        JsonRequestBehavior.AllowGet));
        }