public ActionResult Find(Alim_FuenteFindViewModel model) { //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindAlim_Fuente Controller Begin")); //int totalCount = 0; try { // Add find logic here if (ModelState.IsValid) { if (model.OrderBy == null) { model.OrderBy = "Id"; } string sort = "Id"; var filtros = GenerateExpression(model); var pagedResult = _serviceAlim_Fuente.FindPagedByFilter(filtros, null, 1, model.PageSize, model.OrderBy, "Asc", null, null); model.Paginate(pagedResult, ""); //var Alim_FuenteDetails = _serviceAlim.Query( // new Alim_FuenteQuery().Withfilter(filtros)) // .OrderBy(n => n.OrderBy("Id", "Asc")) // .SelectPage(1, model.PageSize, out totalCount); //var pagelist = new { total = totalCount, rows = Alim_FuenteDetails.ToList() }; //var pagedResult = _serviceAlim_Fuente.FindPagedByFilter(expression, includes, 1, model.PageSize, "Id", model.OrderBy, model.Ascendent, null, null); //model.Paginate(pagedResult, expression.SerializedExpression); TempData.Clear(); TempData.Add("FilterAlim_Fuente", model); //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindAlim_Fuente Controller End")); return(PartialView("_Alim_FuenteFindPartialView", model)); } } catch (Exception ex) { //LoggerFactory.CreateLog().Error(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindAlim_Fuente Controller ERROR"), ex); } ModelState.AddModelError("", PresentationResources.Error); return(View("Alim_FuenteFindView", new Alim_FuenteFindViewModel(_serviceAlim_Fuente, _serviceAlim))); }
//private static QueryObject<Alim_Fuente> GenerateExpression(Alim_FuenteFindViewModel model) private static IEnumerable <filterRule> GenerateExpression(Alim_FuenteFindViewModel model) { //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindAlim Controller Begin")); //var filters = JsonConvert.DeserializeObject<IEnumerable<filterRule>>(filterRules); //return Json(pagelist, JsonRequestBehavior.AllowGet); IList <filterRule> filtros = new List <filterRule>(); if (model != null) { if (model.Alim_Fuente.Id.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "Id", value = model.Alim_Fuente.Id.Value.ToString() }); } //And(d => d.Id == model.Alim_Fuente.Id.Value); if (model.Alim_Fuente.Cod.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "Cod", value = model.Alim_Fuente.Cod.Value.ToString() }); } //And(d => d.Cod == model.Alim_Fuente.Cod.Value); if (!string.IsNullOrEmpty(model.Alim_Fuente.Nombre)) { filtros.Add(new filterRule() { op = "equal", field = "Nombre", value = model.Alim_Fuente.Nombre }); } //And(d => d.Nombre.Contains(model.Alim_Fuente.Nombre)); } return(filtros); //return new QueryObject<Alim_Fuente>(expression ?? (d => true)); }
// GET public ActionResult Find(int?page = 1, string sort = "Id", string sortDir = "ASC") { //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindAlim_Fuente Controller Begin")); try { // Add find logic here Alim_FuenteFindViewModel model; if (Request.IsAjaxRequest() && TempData.ContainsKey("FilterAlim_Fuente")) { model = (Alim_FuenteFindViewModel)TempData.Peek("FilterAlim_Fuente"); var filtros = GenerateExpression(model); var pagedResult = _serviceAlim_Fuente.FindPagedByFilter(filtros, null, page != null ? (int)page : model.PageIndex, model.PageSize, sort, sortDir, null, null); model.Paginate(pagedResult, ""); //var pagedResult = _serviceAlim_Fuente.FindPagedByFilter(new CustomQuery<Alim_Fuente> { SerializedExpression = model.Filter }, null, page != null ? (int)page : model.PageIndex, model.PageSize, sort, sortDir == "ASC", null); //model.Paginate(pagedResult, model.Filter); //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindPagedAlim_Fuente Controller End")); return(PartialView("_Alim_FuenteFindPartialView", model)); } else { TempData.Remove("FilterAlim_Fuente"); model = new Alim_FuenteFindViewModel(_serviceAlim_Fuente, _serviceAlim); //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindAlim_Fuente Controller End")); return(View("Alim_FuenteFindView", model)); } } catch (Exception ex) { //LoggerFactory.CreateLog().Error(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindAlim_Fuente Controller ERROR"), ex); } return(RedirectToAction("Index", "Home")); }