コード例 #1
0
    public static IQueryable <T> BuildQuery <T>(IQueryable <T> query, DTParameterModel dtParameters)
    {
        IQueryable <T> q = query;
        //I skiped regex search
        var searchColumns = dtParameters.Columns.Where(c => c.Searchable).Select(c => c.Name).ToArray();

        if (searchColumns.Length > 0)
        {
            if (!string.IsNullOrEmpty(dtParameters.Search.Value) && !string.IsNullOrWhiteSpace(dtParameters.Search.Value))
            {
                int        i   = 0;
                var        par = Expression.Parameter(typeof(T), "x");
                Expression exp = Expression.Constant(false);
                //we need to bind search expressions with 'OR'
                while (i < searchColumns.Length)
                {
                    var expNext   = GetSearchExpression <T>(searchColumns[i], dtParameters.Search.Value, par);
                    var expInvoke = Expression.Invoke(expNext, par);
                    exp = Expression.OrElse(exp, expNext.Body);
                    i++;
                }
                var ex = Expression.Lambda <Func <T, bool> >(exp, par);
                q = q.Where(ex);
            }
        }
        // order by
        DTColumn[] columns = dtParameters.Columns.ToArray();
        foreach (var order in dtParameters.Order)
        {
            var orderColumn = columns[order.Column].Name;
            var dir         = order.Dir;
            q = OrderByQuery(q, orderColumn, dir);
        }
        return(q);
    }
コード例 #2
0
        public async Task <DataTableResultModel <OrderViewModel> > GetOrderList(DTParameterModel criteria, string mobileNumber = "")
        {
            try
            {
                DataTableResultModel <OrderViewModel> orderlist = new DataTableResultModel <OrderViewModel>();
                int totalCount             = 0;
                List <OrderViewModel> list = (this.unitOfWork.Shop_Order_DetailsRepository.GetAllList(out totalCount, this.OrderBuildWhereFilter(criteria), this.OrderBuildOrderByFilter(criteria), true, criteria.Start != 0 ? criteria.Start / criteria.Length : 0, criteria.Length, "")).Where(x => x.retailer_mobile == mobileNumber).Select <Shop_Order_Details, OrderViewModel>((Func <Shop_Order_Details, OrderViewModel>)(x =>
                {
                    OrderViewModel orderViewModel  = new OrderViewModel();
                    orderViewModel.Order_Id        = x.order_id == 0 ? 0 : x.order_id;
                    orderViewModel.retailer_mobile = x.retailer_mobile;
                    orderViewModel.Totalprice      = x.Totalprice;
                    orderViewModel.payment_mode    = x.payment_mode;
                    orderViewModel.order_status    = x.order_status;
                    orderViewModel.orderDate       = x.orderDate.ToString();
                    //orderViewModel.IsActive = Convert.ToBoolean(x.IsActive);
                    //orderViewModel.ResourceKey = Resource.LegalResource_Common_Edit + " " + Resource.LegalResource_Common_State;

                    return(orderViewModel);
                })).ToList <OrderViewModel>();
                orderlist.recordsTotal    = totalCount;
                orderlist.recordsFiltered = totalCount;
                orderlist.sEcho           = Convert.ToInt32(criteria.Draw);
                orderlist.data            = list;
                return(orderlist);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        /// <summary>
        /// sort filter for state
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        private Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> > OrderBuildOrderByFilter(
            DTParameterModel criteria)
        {
            Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> > func = (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)null;

            if (criteria.Order != null && criteria.Order.Count <DTOrder>() > 0)
            {
                string   dir      = criteria.Order.FirstOrDefault <DTOrder>().Dir;
                int      column   = criteria.Order.FirstOrDefault <DTOrder>().Column;
                DTColumn dtColumn = criteria.Columns.ToList <DTColumn>().ElementAt <DTColumn>(column);
                if (dtColumn.Name == "Order_id")
                {
                    func = !dir.Equals("asc") ? (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderByDescending <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.order_id.ToString()))) : (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderBy <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.order_id.ToString())));
                }
                if (dtColumn.Name == "Totalprice")
                {
                    func = !dir.Equals("asc") ? (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderByDescending <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.Totalprice))) : (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderBy <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.Totalprice)));
                }
                if (dtColumn.Name == "payment_mode")
                {
                    func = !dir.Equals("asc") ? (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderByDescending <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.payment_mode))) : (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderBy <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.payment_mode)));
                }

                if (dtColumn.Name == "Status")
                {
                    func = !dir.Equals("asc") ? (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderByDescending <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.order_status))) : (Func <IQueryable <Shop_Order_Details>, IOrderedQueryable <Shop_Order_Details> >)(p => p.OrderBy <Shop_Order_Details, string>((Expression <Func <Shop_Order_Details, string> >)(t => t.order_status)));
                }
            }
            return(func);
        }
コード例 #4
0
        public List <ProductMasterViewModel> GetAllProductList(int take, int skip, string categoryid, string stateid, string searchtext, string CompanyName = "", string sort = "", string CropName = "", int MinPrice = 0, int MaxPrice = 0)
        {
            try
            {
                int totalCount       = 0;
                var DTParameterModel = new DTParameterModel();
                List <ProductMasterViewModel> data = unitOfWork.Shop_Product_MasterRepository.GetAllList(out totalCount, ProductFilter(
                                                                                                             take, skip, categoryid, stateid, searchtext, CompanyName, sort, CropName, MinPrice, MaxPrice)).OrderByDescending(y => y.SkuCreatedDate).Select <Shop_Product_Master, ProductMasterViewModel>((Func <Shop_Product_Master, ProductMasterViewModel>)(x =>
                {
                    //string currentLangugae = Thread.CurrentThread.CurrentCulture.ToString();

                    ProductMasterViewModel productMasterViewModel = new ProductMasterViewModel();
                    productMasterViewModel.pkSkuId         = x.pkSkuId;
                    productMasterViewModel.SkuName         = x.SkuName;
                    productMasterViewModel.Price           = x.Price;
                    productMasterViewModel.IntPrice        = x.IntPrice;
                    productMasterViewModel.packingSize     = x.packingSize;
                    productMasterViewModel.CurrentQuantity = x.CurrentQuantity;
                    productMasterViewModel.SkuCreatedDate  = x.SkuCreatedDate;
                    productMasterViewModel.imageUrl        = x.imageUrl;
                    productMasterViewModel.ProductStatus   = x.CurrentQuantity != null ?  x.CurrentQuantity != "0" ? "Available" : "Out of Stock": "Out of Stock";
                    productMasterViewModel.prd_State       = x.prd_State;
                    productMasterViewModel.Status          = x.Status;
                    productMasterViewModel.isApprove       = x.isApprove;
                    productMasterViewModel.crp_catagory    = x.crp_catagory;
                    productMasterViewModel.crop            = x.crop;
                    productMasterViewModel.Description     = x.Description;
                    productMasterViewModel.ProductPriority = x.ProductPriority.ToString();
                    productMasterViewModel.SkuCreatedDate  = x.SkuCreatedDate;

                    return(productMasterViewModel);
                })).OrderBy(z => z.ProductPriority == "1").OrderBy(x => x.ProductPriority == "2")
                                                     .OrderBy(x => x.ProductPriority == "0").OrderByDescending(x => x.SkuCreatedDate).OrderBy(x => x.ProductStatus).ToList();



                if (sort.Trim() != "N/A")
                {
                    if (sort == "Asc")
                    {
                        return(data.OrderBy(x => x.IntPrice).Skip(skip).Take(take).ToList());
                    }
                    else if (sort == "Desc")
                    {
                        return(data.OrderByDescending(x => x.IntPrice).Skip(skip).Take(take).ToList());
                    }
                    else
                    {
                        return(data.Skip(skip).Take(take).ToList());
                    }
                }
                return(data.Skip(skip).Take(take).ToList());
            }
            catch (Exception ex)

            {
                throw ex;
            }
        }
コード例 #5
0
        /// <summary>
        /// search filter for state
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        private Expression <Func <Shop_Order_Details, bool> > OrderBuildWhereFilter(
            DTParameterModel criteria)
        {
            Expression <Func <Shop_Order_Details, bool> > expression = PredicateBuilder.New <Shop_Order_Details>(true);

            if (criteria.Search.Value != null)
            {
                expression = expression.And <Shop_Order_Details>((Expression <Func <Shop_Order_Details, bool> >)(p => p.orderDate.ToString().Contains(criteria.Search.Value) || p.payment_mode.Contains(criteria.Search.Value) || p.order_status.Contains(criteria.Search.Value)));
            }
            return(expression.Expand <Func <Shop_Order_Details, bool> >());
        }
コード例 #6
0
        public List <ProductMasterViewModel> GetSubCategoryProductList(int take, int skip, string categoryid, string stateid, string searchtext, string sort = "")
        {
            try
            {
                int totalCount       = 0;
                var DTParameterModel = new DTParameterModel();
                List <ProductMasterViewModel> data = unitOfWork.Shop_cropsRepository.GetAllList(out totalCount, GetSubCategoryProductListFilter(
                                                                                                    take, skip, categoryid, stateid, searchtext, sort)).Select <shop_crops, ProductMasterViewModel>((Func <shop_crops, ProductMasterViewModel>)(x =>
                {
                    //string currentLangugae = Thread.CurrentThread.CurrentCulture.ToString();
                    ProductMasterViewModel productMasterViewModel = new ProductMasterViewModel();
                    productMasterViewModel.tr_id                = x.tr_id;
                    productMasterViewModel.crp_Type             = x.crp_Type;
                    productMasterViewModel.crp_catagary         = x.crp_catagary;
                    productMasterViewModel.status               = x.status;
                    productMasterViewModel.imgurl               = x.imgurl;
                    productMasterViewModel.prd_State            = GetStateForSubCategory(x.tr_id);
                    productMasterViewModel.CropRank             = GetCropRank(x.tr_id);
                    productMasterViewModel.CropStatusForDisplay = GetCropStatusFromProduct(stateid, x.crp_Type);

                    return(productMasterViewModel);
                })).ToList();

                // var test = data;

                var filter = data.Where(x => x.CropStatusForDisplay == "In Stock").ToList();
                var result = filter.Skip(skip).Take(take);
                return(result.ToList());
                //if (sort.Trim() != "N/A")
                //{
                //    if (sort == "name")
                //    {

                //        return data.OrderBy(x => x.SkuName).ToList();
                //    }
                //    else if (sort == "price")
                //    {
                //        return data.OrderBy(x => x.Price).ToList();
                //    }
                //    else
                //    {
                //        return data;
                //    }


                //}
            }
            catch (Exception ex)

            {
                throw ex;
            }
        }
コード例 #7
0
        public async Task <JsonResult> GetOrderList(DTParameterModel criteria, string mobileNumber = "")
        {
            try
            {
                string mobileNum = LoggedInUser.MobileNumber;
                var    list      = ObjIUserService.GetOrderList(criteria, mobileNum);

                return(Json(new { list.Result.sEcho, recordsFiltered = list.Result.recordsTotal, list.Result.recordsTotal, list.Result.data }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
    public static object GetDTResult <T>(DTParameterModel dtParameters, IQueryable <T> query, Expression <Func <T, object> > func = null)
    {
        var totalRecords = query.Count();

        query = query.Skip(dtParameters.Start).Take(dtParameters.Length);
        object data   = func == null ? (object)query.ToArray() : query.Select(func).ToArray();
        var    result = new
        {
            draw            = dtParameters.Draw,
            recordsFiltered = totalRecords,
            recordsTotal    = totalRecords,
            data            = data
        };

        return(result);
    }
コード例 #9
0
        public JsonResult CustomerList(DTParameterModel model)
        {
            var repo      = new CustomerRepository();
            var customers = repo.GetCustomers();

            var pdto = new DTResponse
            {
                recordsTotal    = customers.Count(),
                recordsFiltered = customers.Count(),
                data            = customers,
                draw            = model.Draw,
                error           = ""
            };

            return(new JsonResult {
                Data = pdto, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #10
0
        public JsonResult ProductList(DTParameterModel model)
        {
            var repo     = new ProductRepository();
            var products = repo.GetProducts();

            var pdto = new DTResponse
            {
                recordsTotal    = products.Count(),
                recordsFiltered = products.Count(),
                data            = products,
                draw            = model.Draw,
                error           = ""
            };

            return(new JsonResult {
                Data = pdto, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #11
0
        public JsonResult SalesList(DTParameterModel model, DateTime?startDate, DateTime?endDate)
        {
            var repo  = new SalesRepository();
            var sales = repo.GetSales(startDate, endDate);

            var pdto = new DTResponse
            {
                recordsTotal    = sales.Count(),
                recordsFiltered = sales.Count(),
                data            = sales,
                draw            = model.Draw,
                error           = ""
            };

            return(new JsonResult {
                Data = pdto, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #12
0
        public JsonResult QuarterlyCommissionList(DTParameterModel model, int year)
        {
            var repo           = new SalesRepository();
            var commissionList = repo.GetQuarterlyCommission(year);

            var pdto = new DTResponse
            {
                recordsTotal    = commissionList.Count(),
                recordsFiltered = commissionList.Count(),
                data            = commissionList,
                draw            = model.Draw,
                error           = ""
            };

            return(new JsonResult {
                Data = pdto, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
コード例 #13
0
 public Task <DataTableResultModel <OrderViewModel> > GetOrderList(
     DTParameterModel criteria, string mobileNumber = "")
 {
     return(this.objIUser.GetOrderList(criteria, mobileNumber));
 }
コード例 #14
0
        public DataTableResponse <EntretenimientoGridView> GetTodosPaginados([FromBody] DTParameterModel model)
        {
            var data = _entretenimientoService.PeliculasConPaginacion(model);

            return(data.Result);
        }
コード例 #15
0
        public DataTableResponse <CategoriaGridView> GetTodosPaginados([FromBody] DTParameterModel model)
        {
            var data = _categoriaService.CategoriasConPaginacion(model);

            return(data.Result);
        }
コード例 #16
0
        public ResponseHelper <DataTableResponse <CategoriaGridView> > CategoriasConPaginacion(DTParameterModel model)
        {
            var rh = new ResponseHelper <DataTableResponse <CategoriaGridView> >();

            try
            {
                int filteredResultsCount;
                int totalResultsCount;

                var sortedColumns = model.Columns;
                var orderByString = String.Empty;

                orderByString = (sortedColumns[model.Order.FirstOrDefault().Column].Data) + (model.Order.FirstOrDefault().Dir == "asc" ? " asc" : " desc");

                var data = (_unitOfWork._categoriaRepo.GetAll())
                           .Select(x => new CategoriaGridView()
                {
                    Id     = x.Id,
                    Nombre = x.Nombre
                })
                           .OrderBy(orderByString).AsQueryable();

                totalResultsCount = data.Count();

                if (!String.IsNullOrEmpty(model.Search.Value))
                {
                    data = data.Where(x =>
                                      x.Nombre.Contains(model.Search.Value) ||
                                      x.Nombre.EndsWith(model.Search.Value)
                                      );
                }

                filteredResultsCount = data.Count();

                var salida = data
                             .Skip(model.Start)
                             .Take(model.Length);

                rh.Result = new DataTableResponse <CategoriaGridView>()
                {
                    draw            = model.Draw,
                    data            = salida.ToList(),
                    recordsFiltered = filteredResultsCount,
                    recordsTotal    = totalResultsCount
                };
                rh.SetResponse(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                rh.SetResponse(false, m: e.Message);
            }

            return(rh);
        }
コード例 #17
0
        public ResponseHelper <DataTableResponse <EntretenimientoGridView> > PeliculasConPaginacion(DTParameterModel model)
        {
            var rh = new ResponseHelper <DataTableResponse <EntretenimientoGridView> >();

            try
            {
                int filteredResultsCount;
                int totalResultsCount;

                var sortedColumns = model.Columns;
                var orderByString = String.Empty;

                orderByString = (sortedColumns[model.Order.FirstOrDefault().Column].Data) + (model.Order.FirstOrDefault().Dir == "asc" ? " asc" : " desc");

                var data = (_unitOfWork._entretenimientoRepo.GetAll())
                           .Select(x => new EntretenimientoGridView
                {
                    Id         = x.Id,
                    Ano        = x.Ano,
                    Titulo     = x.Titulo,
                    Direccion  = x.Direccion,
                    Fotografia = x.Fotografia,
                    Musica     = x.Musica,
                    Pais       = x.Pais,
                    Productora = x.Productora,
                    Reparto    = x.Reparto,
                    Snopsis    = x.Snopsis,
                    Categorias = x.Categorias.Select(y => new CategoriaGridView()
                    {
                        Id     = y.CategoriaId,
                        Nombre = y.Categoria.Nombre
                    }),
                    ImagenUrl = x.ImagenUrl
                })
                           .OrderBy(orderByString).AsQueryable();

                totalResultsCount = data.Count();

                if (!String.IsNullOrEmpty(model.Search.Value))
                {
                    data = data.Where(x =>
                                      x.Titulo.ToLower().Contains(model.Search.Value.ToLower()) ||
                                      x.Titulo.ToLower().EndsWith(model.Search.Value.ToLower())

                                      || x.Ano.ToString().EndsWith(model.Search.Value.ToLower()) ||
                                      x.Ano.ToString().EndsWith(model.Search.Value.ToLower())

                                      || x.Direccion.ToLower().EndsWith(model.Search.Value.ToLower()) ||
                                      x.Direccion.ToLower().EndsWith(model.Search.Value.ToLower())

                                      || x.Pais.ToLower().EndsWith(model.Search.Value.ToLower()) ||
                                      x.Pais.ToLower().EndsWith(model.Search.Value.ToLower())
                                      );
                }

                filteredResultsCount = data.Count();

                var salida = data
                             .Skip(model.Start)
                             .Take(model.Length);

                rh.Result = new DataTableResponse <EntretenimientoGridView>()
                {
                    draw            = model.Draw,
                    data            = salida.ToList(),
                    recordsFiltered = filteredResultsCount,
                    recordsTotal    = totalResultsCount
                };
                rh.SetResponse(true);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message, e);
                rh.SetResponse(false, m: e.Message);
            }

            return(rh);
        }