Пример #1
0
        //private static QueryObject<FamRec> GenerateExpression(FamRecFindViewModel model)
        private static IEnumerable <filterRule> GenerateExpression(FamRecFindViewModel 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.FamRec.Id.HasValue)
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "Id", value = model.FamRec.Id.Value.ToString()
                    });
                }
                //And(d => d.Id == model.FamRec.Id.Value);
                if (!string.IsNullOrEmpty(model.FamRec.Nombre))
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "Nombre", value = model.FamRec.Nombre
                    });
                }
                //And(d => d.Nombre.Contains(model.FamRec.Nombre));
                if (!string.IsNullOrEmpty(model.FamRec.Descripcion))
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "Descripcion", value = model.FamRec.Descripcion
                    });
                }
                //And(d => d.Descripcion.Contains(model.FamRec.Descripcion));
                if (model.FamRec.Base.HasValue)
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "Base", value = model.FamRec.Base.Value.ToString()
                    });
                }
                //And(d => d.Base == model.FamRec.Base.Value);
                if (model.FamRec.FechaRegistro.HasValue)
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "FechaRegistro", value = model.FamRec.FechaRegistro.Value.ToString()
                    });
                }
                //And(d => d.FechaRegistro == model.FamRec.FechaRegistro.Value);
            }

            return(filtros);
            //return new QueryObject<FamRec>(expression ?? (d => true));
        }
Пример #2
0
        public ActionResult Find(FamRecFindViewModel model)
        {
            //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindFamRec 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 = _serviceFamRec.FindPagedByFilter(filtros, null, 1, model.PageSize, model.OrderBy, "Asc", null, null);
                    model.Paginate(pagedResult, "");

                    //var FamRecDetails = _serviceAlim.Query(
                    //    new FamRecQuery().Withfilter(filtros))
                    //    .OrderBy(n => n.OrderBy("Id", "Asc"))
                    //    .SelectPage(1, model.PageSize, out totalCount);
                    //var pagelist = new { total = totalCount, rows = FamRecDetails.ToList() };

                    //var pagedResult = _serviceFamRec.FindPagedByFilter(expression, includes, 1, model.PageSize, "Id", model.OrderBy, model.Ascendent, null, null);
                    //model.Paginate(pagedResult, expression.SerializedExpression);

                    TempData.Clear();
                    TempData.Add("FilterFamRec", model);

                    //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindFamRec Controller End"));
                    return(PartialView("_FamRecFindPartialView", model));
                }
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindFamRec Controller ERROR"), ex);
            }

            ModelState.AddModelError("", PresentationResources.Error);
            return(View("FamRecFindView", new FamRecFindViewModel(_serviceFamRec, _serviceReceta)));
        }
Пример #3
0
        // GET
        public ActionResult Find(int?page = 1, string sort = "Id", string sortDir = "ASC")
        {
            //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindFamRec Controller Begin"));

            try
            {
                // Add find logic here
                FamRecFindViewModel model;

                if (Request.IsAjaxRequest() && TempData.ContainsKey("FilterFamRec"))
                {
                    model = (FamRecFindViewModel)TempData.Peek("FilterFamRec");
                    var filtros     = GenerateExpression(model);
                    var pagedResult = _serviceFamRec.FindPagedByFilter(filtros, null, page != null ? (int)page : model.PageIndex, model.PageSize, sort, sortDir, null, null);
                    model.Paginate(pagedResult, "");

                    //var pagedResult = _serviceFamRec.FindPagedByFilter(new CustomQuery<FamRec> { 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 - FindPagedFamRec Controller End"));
                    return(PartialView("_FamRecFindPartialView", model));
                }
                else
                {
                    TempData.Remove("FilterFamRec");
                    model = new FamRecFindViewModel(_serviceFamRec, _serviceReceta);
                    //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindFamRec Controller End"));
                    return(View("FamRecFindView", model));
                }
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindFamRec Controller ERROR"), ex);
            }

            return(RedirectToAction("Index", "Home"));
        }