public ActionResult Find(RecProdFindViewModel model) { //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindRecProd 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 = _serviceRecProd.FindPagedByFilter(filtros, null, 1, model.PageSize, model.OrderBy, "Asc", null, null); model.Paginate(pagedResult, ""); //var RecProdDetails = _serviceAlim.Query( // new RecProdQuery().Withfilter(filtros)) // .OrderBy(n => n.OrderBy("Id", "Asc")) // .SelectPage(1, model.PageSize, out totalCount); //var pagelist = new { total = totalCount, rows = RecProdDetails.ToList() }; //var pagedResult = _serviceRecProd.FindPagedByFilter(expression, includes, 1, model.PageSize, "Id", model.OrderBy, model.Ascendent, null, null); //model.Paginate(pagedResult, expression.SerializedExpression); TempData.Clear(); TempData.Add("FilterRecProd", model); //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindRecProd Controller End")); return(PartialView("_RecProdFindPartialView", model)); } } catch (Exception ex) { //LoggerFactory.CreateLog().Error(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindRecProd Controller ERROR"), ex); } ModelState.AddModelError("", PresentationResources.Error); return(View("RecProdFindView", new RecProdFindViewModel(_serviceRecProd, _serviceAlim, _serviceReceta))); }
// GET public ActionResult Find(int?page = 1, string sort = "Id", string sortDir = "ASC") { //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindRecProd Controller Begin")); try { // Add find logic here RecProdFindViewModel model; if (Request.IsAjaxRequest() && TempData.ContainsKey("FilterRecProd")) { model = (RecProdFindViewModel)TempData.Peek("FilterRecProd"); var filtros = GenerateExpression(model); var pagedResult = _serviceRecProd.FindPagedByFilter(filtros, null, page != null ? (int)page : model.PageIndex, model.PageSize, sort, sortDir, null, null); model.Paginate(pagedResult, ""); //var pagedResult = _serviceRecProd.FindPagedByFilter(new CustomQuery<RecProd> { 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 - FindPagedRecProd Controller End")); return(PartialView("_RecProdFindPartialView", model)); } else { TempData.Remove("FilterRecProd"); model = new RecProdFindViewModel(_serviceRecProd, _serviceAlim, _serviceReceta); //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindRecProd Controller End")); return(View("RecProdFindView", model)); } } catch (Exception ex) { //LoggerFactory.CreateLog().Error(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindRecProd Controller ERROR"), ex); } return(RedirectToAction("Index", "Home")); }
//private static QueryObject<RecProd> GenerateExpression(RecProdFindViewModel model) private static IEnumerable <filterRule> GenerateExpression(RecProdFindViewModel 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.RecProd.Id.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "Id", value = model.RecProd.Id.Value.ToString() }); } //And(d => d.Id == model.RecProd.Id.Value); if (model.RecProd.IdReceta.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "IdReceta", value = model.RecProd.IdReceta.Value.ToString() }); } //And(d => d.IdReceta == model.RecProd.IdReceta.Value); if (model.RecProd.IdProducto.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "IdProducto", value = model.RecProd.IdProducto.Value.ToString() }); } //And(d => d.IdProducto == model.RecProd.IdProducto.Value); if (model.RecProd.IdProveedor.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "IdProveedor", value = model.RecProd.IdProveedor.Value.ToString() }); } //And(d => d.IdProveedor == model.RecProd.IdProveedor.Value); if (model.RecProd.Gramos.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "Gramos", value = model.RecProd.Gramos.Value.ToString() }); } //And(d => d.Gramos == model.RecProd.Gramos.Value); if (model.RecProd.FechaRegistro.HasValue) { filtros.Add(new filterRule() { op = "equal", field = "FechaRegistro", value = model.RecProd.FechaRegistro.Value.ToString() }); } //And(d => d.FechaRegistro == model.RecProd.FechaRegistro.Value); } return(filtros); //return new QueryObject<RecProd>(expression ?? (d => true)); }