Esempio n. 1
0
        public ActionResult Find(Nt_FuncFindViewModel model)
        {
            //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindNt_Func 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 = _serviceNt_Func.FindPagedByFilter(filtros, null, 1, model.PageSize, model.OrderBy, "Asc", null, null);
                    model.Paginate(pagedResult, "");

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

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

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

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

            ModelState.AddModelError("", PresentationResources.Error);
            return(View("Nt_FuncFindView", new Nt_FuncFindViewModel(_serviceNt_Func, _serviceNutriente)));
        }
Esempio n. 2
0
        //private static QueryObject<Nt_Func> GenerateExpression(Nt_FuncFindViewModel model)
        private static IEnumerable <filterRule> GenerateExpression(Nt_FuncFindViewModel 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.Nt_Func.Id.HasValue)
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "Id", value = model.Nt_Func.Id.Value.ToString()
                    });
                }
                //And(d => d.Id == model.Nt_Func.Id.Value);
                if (!string.IsNullOrEmpty(model.Nt_Func.Nombre))
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "Nombre", value = model.Nt_Func.Nombre
                    });
                }
                //And(d => d.Nombre.Contains(model.Nt_Func.Nombre));
                if (!string.IsNullOrEmpty(model.Nt_Func.Descripcion))
                {
                    filtros.Add(new filterRule()
                    {
                        op = "equal", field = "Descripcion", value = model.Nt_Func.Descripcion
                    });
                }
                //And(d => d.Descripcion.Contains(model.Nt_Func.Descripcion));
            }

            return(filtros);
            //return new QueryObject<Nt_Func>(expression ?? (d => true));
        }
Esempio n. 3
0
        // GET
        public ActionResult Find(int?page = 1, string sort = "Id", string sortDir = "ASC")
        {
            //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindNt_Func Controller Begin"));

            try
            {
                // Add find logic here
                Nt_FuncFindViewModel model;

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

                    //var pagedResult = _serviceNt_Func.FindPagedByFilter(new CustomQuery<Nt_Func> { 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 - FindPagedNt_Func Controller End"));
                    return(PartialView("_Nt_FuncFindPartialView", model));
                }
                else
                {
                    TempData.Remove("FilterNt_Func");
                    model = new Nt_FuncFindViewModel(_serviceNt_Func, _serviceNutriente);
                    //LoggerFactory.CreateLog().Debug(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindNt_Func Controller End"));
                    return(View("Nt_FuncFindView", model));
                }
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(string.Format(CultureInfo.InvariantCulture, "Presentation Layer - FindNt_Func Controller ERROR"), ex);
            }

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