Esempio n. 1
0
        internal void OrderByMF <M, F>(Expression <Func <M, F> > propertyFunc, OrderByEnum orderBy)
            where M : class
        {
            var keyDic = DC.XE.FuncMFExpression(propertyFunc);

            AddOrderByParam(keyDic, orderBy);
        }
Esempio n. 2
0
        public async Task <PageResult <EventLogModel> > FindByParams(
            string entityType,
            int?entityId,
            string entityName,
            EventEnum?eventEnum,
            int?userId,
            DateTime?startDate,
            DateTime?endDate,
            string fieldName,
            string fieldValue,
            bool onlyProject,
            OrderByEnum orderBy,
            int?page,
            int?pageSize)
        {
            var dataResult = await _eventLogRepository.FindByParamsAsync(
                entityType,
                entityId,
                entityName,
                eventEnum,
                userId,
                startDate,
                endDate,
                fieldName,
                fieldValue,
                onlyProject,
                orderBy,
                page,
                pageSize);

            var result = MapToModel <EventLogModel>(dataResult);

            return(result);
        }
        /// <summary>
        /// Get best customers
        /// </summary>
        /// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
        /// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
        /// <param name="os">Order status; null to load all records</param>
        /// <param name="ps">Order payment status; null to load all records</param>
        /// <param name="ss">Order shipment status; null to load all records</param>
        /// <param name="orderBy">1 - order by order total, 2 - order by number of orders</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <returns>Report</returns>
        public virtual IPagedList <BestCustomerReportLine> GetBestCustomersReport(DateTime?createdFromUtc,
                                                                                  DateTime?createdToUtc, OrderStatus?os, PaymentStatus?ps, ShippingStatus?ss, OrderByEnum orderBy,
                                                                                  int pageIndex = 0, int pageSize = 214748364)
        {
            int?orderStatusId = null;

            if (os.HasValue)
            {
                orderStatusId = (int)os.Value;
            }

            int?paymentStatusId = null;

            if (ps.HasValue)
            {
                paymentStatusId = (int)ps.Value;
            }

            int?shippingStatusId = null;

            if (ss.HasValue)
            {
                shippingStatusId = (int)ss.Value;
            }
            var query1 = from c in _customerRepository.Table
                         join o in _orderRepository.Table on c.Id equals o.CustomerId
                         where (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) &&
                         (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) &&
                         (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) &&
                         (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) &&
                         (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) &&
                         !o.Deleted &&
                         !c.Deleted
                         select new { c, o };

            var query2 = from co in query1
                         group co by co.c.Id into g
                         select new
            {
                CustomerId = g.Key,
                OrderTotal = g.Sum(x => x.o.OrderTotal),
                OrderCount = g.Count()
            };

            query2 = orderBy switch
            {
                OrderByEnum.OrderByQuantity => query2.OrderByDescending(x => x.OrderTotal),
                OrderByEnum.OrderByTotalAmount => query2.OrderByDescending(x => x.OrderCount),
                _ => throw new ArgumentException("Wrong orderBy parameter", nameof(orderBy)),
            };
            var tmp = new PagedList <dynamic>(query2, pageIndex, pageSize);

            return(new PagedList <BestCustomerReportLine>(tmp.Select(x => new BestCustomerReportLine
            {
                CustomerId = x.CustomerId,
                OrderTotal = x.OrderTotal,
                OrderCount = x.OrderCount
            }),
                                                          tmp.PageIndex, tmp.PageSize, tmp.TotalCount));
        }
Esempio n. 4
0
        public static (string, OrderByPacket) FromJson(string Json)
        {
            JObject obj        = JObject.Parse(Json);
            string  ColumnName = obj["OrderByName"].Value <string>();

            obj.Remove("OrderByName");
            OrderByEnum param = OrderByEnum.None;

            if (!obj.ContainsKey("OrderByParam"))
            {
                return(obj.ToString(), new OrderByPacket()
                {
                    ColumnName = ColumnName, Param = OrderByEnum.ASC
                });
            }
            else
            {
                int p = obj["OrderByParam"].Value <int>();
                obj.Remove("OrderByParam");
                if (p > -1 & p < 3)
                {
                    param = (OrderByEnum)p;
                }
                else
                {
                    param = OrderByEnum.ASC;
                }
                return(obj.ToString(), new OrderByPacket()
                {
                    ColumnName = ColumnName, Param = param
                });
            }
        }
Esempio n. 5
0
        public async Task <ActionResult <PageResult <EventLogModel> > > GetAll(
            string entityType   = null,
            int?entityId        = null,
            string entityName   = null,
            EventEnum?eventEnum = null,
            int?userId          = null,
            DateTime?startDate  = null,
            DateTime?endDate    = null,
            string fieldName    = null,
            string fieldValue   = null,
            int?page            = null,
            int?pageSize        = null,
            bool onlyProject    = false,
            OrderByEnum orderBy = OrderByEnum.Desc)
        {
            var result = await _eventLogService.FindByParams(
                entityType,
                entityId,
                entityName,
                eventEnum,
                userId,
                startDate,
                endDate,
                fieldName,
                fieldValue,
                onlyProject,
                orderBy,
                page,
                pageSize);

            return(result);
        }
Esempio n. 6
0
        public async Task <IActionResult> GetPdf(
            string plateNumber        = null,
            string routeName          = null,
            int?carType               = null,
            int?project               = null,
            int?carBrand              = null,
            int?provider              = null,
            int?yearRelease           = null,
            string blockNumber        = null,
            int?blockType             = null,
            bool?active               = null,
            string sortBy             = "lastTime",
            OrderByEnum orderBy       = OrderByEnum.Desc,
            FileFormatEnum fileFormat = FileFormatEnum.Pdf)
        {
            var fileModel = await _objectService.GetVehiclesFileAsync(
                User,
                plateNumber,
                routeName,
                carType,
                project,
                active,
                carBrand,
                provider,
                yearRelease,
                blockNumber,
                blockType,
                sortBy,
                orderBy,
                fileFormat);

            return(CreateFileResponse(fileModel));
        }
Esempio n. 7
0
        public Task <PageResult <EventLog> > FindByParamsAsync(
            string entityType,
            int?entityId,
            string entityName,
            EventEnum?eventEnum,
            int?userId,
            DateTime?startDate,
            DateTime?endDate,
            string fieldName,
            string fieldValue,
            bool onlyProject,
            OrderByEnum orderBy,
            int?page,
            int?pageSize)
        {
            Expression <Func <EventLog, bool> > filter = x =>
                                                         (string.IsNullOrEmpty(entityType) || x.EntityType == entityType) &&
                                                         (string.IsNullOrEmpty(entityName) || x.EntityName == entityName) &&
                                                         (!entityId.HasValue || x.EntityId == entityId.Value) &&
                                                         (!eventEnum.HasValue || x.Event == eventEnum.Value) &&
                                                         (!userId.HasValue || x.UserId == userId.Value) &&
                                                         (!startDate.HasValue || x.TimeStamp >= startDate.Value) &&
                                                         (!endDate.HasValue || x.TimeStamp <= endDate.Value) &&
                                                         (string.IsNullOrEmpty(fieldName) || x.EventLogFields.Any(y => y.FieldName == fieldName)) &&
                                                         (string.IsNullOrEmpty(fieldValue) || x.EventLogFields.Any(y => y.OldFieldValue == fieldValue || y.NewFieldValue == fieldValue)) &&
                                                         (!onlyProject || x.User.ProjectId > 0);

            return(FindPagedAsync(
                       filter,
                       x => x.TimeStamp,
                       orderBy,
                       page,
                       pageSize,
                       _includes));
        }
        public async Task <IActionResult> GetAsync(OrderByEnum orderByEnum)
        {
            IEnumerable <President> presidents = orderByEnum == OrderByEnum.Ascending ?
                                                 await context.Presidents.OrderBy(x => x.Name).ToListAsync() :
                                                 await context.Presidents.OrderByDescending(x => x.Name).ToListAsync();

            return(Ok(presidents));
        }
Esempio n. 9
0
 /// <summary>
 /// 设置排序,用于select ,pagelist
 /// </summary>
 /// <param name="filedName"></param>
 /// <param name="order"></param>
 /// <returns></returns>
 public DataBaseAction SqlOrderBy(string filedName, OrderByEnum order)
 {
     _orderValues.Add(new OrderField()
     {
         FiledName = filedName,
         Order     = order
     });
     return(this);
 }
Esempio n. 10
0
        /// <summary>
        /// order by
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="selectAction"></param>
        /// <param name="iExpression"></param>
        /// <param name="eByEnum"></param>
        /// <returns></returns>
        public static LinqQueryAction <T> OrderBy <T>(
            this LinqQueryAction <T> selectAction,
            Expression <Func <T, object> > iExpression, OrderByEnum eByEnum)
        {
            ConditionBuilder conditionBuilder = new ConditionBuilder();

            conditionBuilder.Build(iExpression.Body);
            selectAction.CAction.SqlOrderBy(conditionBuilder.Condition, eByEnum);
            return(selectAction);
        }
Esempio n. 11
0
        public Task <PageResult <Objects> > FindByParamsAsync(
            string plateNumber,
            string routeName,
            int?carTypeId,
            int?projectId,
            ModelFormatsEnum format,
            bool?active,
            UserAvailableRoutes userRoutesModel,
            int?carBrandId,
            int?providerId,
            int?yearRelease,
            string blockNumber,
            int?blockTypeId,
            string sortBy,
            OrderByEnum orderBy,
            int?page,
            int?pageSize)
        {
            var includes = _includesPure;

            if (format == ModelFormatsEnum.Light)
            {
                includes = _includesLight;
            }
            else if (format == ModelFormatsEnum.Full)
            {
                includes = _includesFull;
            }

            var filter = GetSearchFilter(
                plateNumber,
                routeName,
                carTypeId,
                projectId,
                active,
                userRoutesModel,
                carBrandId,
                providerId,
                yearRelease,
                blockNumber,
                blockTypeId,
                sortBy,
                orderBy);

            var sortByFilter = GetSortExpression(sortBy);

            return(FindPagedAsync(
                       filter,
                       sortByFilter,
                       orderBy,
                       page,
                       pageSize,
                       includes));
        }
Esempio n. 12
0
        public void AddOrderBy(Column column, OrderByEnum type)
        {
            switch (type)
            {
            case OrderByEnum.Asc:
                Provider.AddOrderBy(column.DbName, column.DbTable.GetTableNameShortcut(), true);
                break;

            default:
                Provider.AddOrderBy(column.DbName, column.DbTable.GetTableNameShortcut(), false);
                break;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Converts a OrderByEnum value to a corresponding string value
        /// </summary>
        /// <param name="enumValue">The OrderByEnum value to convert</param>
        /// <returns>The representative string value</returns>
        public static string ToValue(OrderByEnum enumValue)
        {
            switch (enumValue)
            {
            //only valid enum elements can be used
            //this is necessary to avoid errors
            case OrderByEnum.ASC:
            case OrderByEnum.DESC:
                return(stringValues[(int)enumValue]);

            //an invalid enum value was requested
            default:
                return(null);
            }
        }
Esempio n. 14
0
        protected Task <List <TEntity> > FindOrderedAsync(
            Expression <Func <TEntity, bool> > filter,
            Expression <Func <TEntity, object> > orderBySelector,
            OrderByEnum orderByEnum,
            params string[] includes)
        {
            var orderByAsc = orderByEnum == OrderByEnum.Asc;
            var query      = Prepare(filter, includes);

            query = orderByAsc
                ? query.OrderBy(orderBySelector)
                : query.OrderByDescending(orderBySelector);

            return(query.ToListAsync());
        }
Esempio n. 15
0
        private void AddOrderByParam(DicParam keyDic, OrderByEnum orderBy)
        {
            switch (orderBy)
            {
            case OrderByEnum.Asc:
                DC.Option = OptionEnum.Asc;
                break;

            case OrderByEnum.Desc:
                DC.Option = OptionEnum.Desc;
                break;
            }

            DC.DPH.AddParameter(DC.DPH.OrderbyDic(keyDic.TbMType, keyDic.TbCol, keyDic.TbAlias));
        }
Esempio n. 16
0
        private Expression <Func <Objects, bool> > GetSearchFilter(
            string plateNumber,
            string routeName,
            int?carTypeId,
            int?projectId,
            bool?active,
            UserAvailableRoutes userRoutesModel,
            int?carBrandId,
            int?providerId,
            int?yearRelease,
            string blockNumber,
            int?blockTypeId,
            string sortBy,
            OrderByEnum orderBy)
        {
            var locked = !active;

            if (userRoutesModel.ProjectId.HasValue)
            {
                projectId = userRoutesModel.ProjectId;
            }

            if (!string.IsNullOrEmpty(plateNumber))
            {
                plateNumber = plateNumber.ToUpper();
            }

            if (!string.IsNullOrEmpty(routeName))
            {
                routeName = routeName.PrepareRouteName();
            }

            Expression <Func <Objects, bool> > filter = x => (string.IsNullOrEmpty(plateNumber) || x.Name.Contains(plateNumber)) &&
                                                        (!projectId.HasValue || x.ProjectId == projectId) &&
                                                        (!carBrandId.HasValue || x.CarBrandId == carBrandId) &&
                                                        (!providerId.HasValue || x.ProviderId == providerId) &&
                                                        (string.IsNullOrEmpty(routeName) || x.Route.Name.Equals(routeName)) &&
                                                        (!carTypeId.HasValue || x.CarBrand.CarTypeId == carTypeId) &&
                                                        (!locked.HasValue || x.ObjectOutput == locked.Value) &&
                                                        (!yearRelease.HasValue || x.YearRelease == yearRelease) &&
                                                        (string.IsNullOrEmpty(blockNumber) || x.Phone.ToString().Contains(blockNumber) || x.Block.BlockNumber.ToString().Contains(blockNumber)) &&
                                                        (!blockTypeId.HasValue || x.Block.BlockTypeId == blockTypeId) &&
                                                        (userRoutesModel.RouteIds == null || (x.LastRouteId.HasValue && userRoutesModel.RouteIds.Contains(x.LastRouteId.Value)));

            return(filter);
        }
Esempio n. 17
0
        public CollectionResponse <Reservation> OrderBy(OrderByEnum order, PageResult input = null)
        {
            var entities = this.repository.GetAll();

            var result = new List <Reservation>();

            switch (order)
            {
            case RanKing:
                result = entities.OrderByDescending(t => t.RanKing).ToList();
                break;

            case DateAscending:
                result = entities.OrderBy(t => t.CreateDate).ToList();
                break;

            case AlphabeticAscending:
                result = entities.OrderBy(t => t.Contact.Name).ToList();
                break;

            case AlphabeticDescending:
                result = entities.OrderByDescending(t => t.Contact.Name).ToList();
                break;

            case DateDescending:
                result = entities.OrderByDescending(t => t.CreateDate).ToList();
                break;
            }

            CollectionResponse <Reservation> response;

            if (input == null)
            {
                response = new CollectionResponse <Reservation> {
                    SourceTotal = entities.Count()
                };
                response.Items.AddRange(result);
            }
            else
            {
                response = GetPageReservation(result, input);
            }

            return(response);
        }
Esempio n. 18
0
        private List <ReservationViewModel> ReservationDetoList(int page, string sort)
        {
            const int maxPage   = 5;
            var       skipCount = (page - 1) * maxPage;

            OrderByEnum.TryParse(sort, out OrderByEnum sortBy);

            var response =
                this._reservationService.OrderBy(sortBy, new PageResult(skipCount, maxPage));

            var reservationDetoList = Mapper.Map <List <Reservation>, List <ReservationViewModel> >(response.Items);

            this.ViewBag.PageCount = (int)Math.Ceiling((double)response.SourceTotal / maxPage);
            this.ViewBag.page      = page;
            this.ViewBag.sort      = sort;
            this.ViewBag.listSorts = Helper.EnumHelper.ToLocalizationListSelectListItem <OrderByEnum>();
            return(reservationDetoList);
        }
Esempio n. 19
0
        public async Task <PageResult <ObjectModel> > FindByParamsAsync(
            ClaimsPrincipal userPrincipal,
            string plateNumber,
            string routeName,
            int?carTypeId,
            int?projectId,
            ModelFormatsEnum format,
            bool?active,
            int?carBrandId,
            int?providerId,
            int?yearRelease,
            string blockNumber,
            int?blockTypeId,
            string sortBy,
            OrderByEnum orderBy,
            int?page,
            int?pageSize)
        {
            var userRoutesModel = await _userManager.GetAvailableRoutesModel(userPrincipal);

            var result = await _objectRepository.FindByParamsAsync(
                plateNumber,
                routeName,
                carTypeId,
                projectId,
                format,
                active,
                userRoutesModel,
                carBrandId,
                providerId,
                yearRelease,
                blockNumber,
                blockTypeId,
                sortBy,
                orderBy,
                page,
                pageSize);

            return(MapToModel <ObjectModel>(result));
        }
        /// <summary>
        /// Get best sellers report
        /// </summary>
        /// <param name="storeId">Store identifier (orders placed in a specific store); 0 to load all records</param>
        /// <param name="vendorId">Vendor identifier; 0 to load all records</param>
        /// <param name="categoryId">Category identifier; 0 to load all records</param>
        /// <param name="manufacturerId">Manufacturer identifier; 0 to load all records</param>
        /// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
        /// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
        /// <param name="os">Order status; null to load all records</param>
        /// <param name="ps">Order payment status; null to load all records</param>
        /// <param name="ss">Shipping status; null to load all records</param>
        /// <param name="billingCountryId">Billing country identifier; 0 to load all records</param>
        /// <param name="orderBy">1 - order by quantity, 2 - order by total amount</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Result</returns>
        public virtual IPagedList <BestsellersReportLine> BestSellersReport(
            int categoryId          = 0,
            int manufacturerId      = 0,
            int storeId             = 0,
            int vendorId            = 0,
            DateTime?createdFromUtc = null,
            DateTime?createdToUtc   = null,
            OrderStatus?os          = null,
            PaymentStatus?ps        = null,
            ShippingStatus?ss       = null,
            int billingCountryId    = 0,
            OrderByEnum orderBy     = OrderByEnum.OrderByQuantity,
            int pageIndex           = 0,
            int pageSize            = int.MaxValue,
            bool showHidden         = false)
        {
            var bestSellers = SearchOrderItems(categoryId, manufacturerId, storeId, vendorId, createdFromUtc, createdToUtc, os, ps, ss, billingCountryId, pageIndex, pageSize, showHidden);

            var bsReport =
                //group by products
                from orderItem in bestSellers
                group orderItem by orderItem.ProductId into g
                select new BestsellersReportLine
            {
                ProductId     = g.Key,
                TotalAmount   = g.Sum(x => x.PriceExclTax),
                TotalQuantity = g.Sum(x => x.Quantity)
            };

            bsReport = orderBy switch
            {
                OrderByEnum.OrderByQuantity => bsReport.OrderByDescending(x => x.TotalQuantity),
                OrderByEnum.OrderByTotalAmount => bsReport.OrderByDescending(x => x.TotalAmount),
                _ => throw new ArgumentException("Wrong orderBy parameter", nameof(orderBy)),
            };
            var result = new PagedList <BestsellersReportLine>(bsReport, pageIndex, pageSize);

            return(result);
        }
Esempio n. 21
0
        public Task <List <Objects> > FindAllForFileAsync(
            string plateNumber,
            string routeName,
            int?carTypeId,
            int?projectId,
            bool?active,
            UserAvailableRoutes userRoutesModel,
            int?carBrandId,
            int?providerId,
            int?yearRelease,
            string blockNumber,
            int?blockTypeId,
            string sortBy,
            OrderByEnum orderBy)
        {
            var filter = GetSearchFilter(
                plateNumber,
                routeName,
                carTypeId,
                projectId,
                active,
                userRoutesModel,
                carBrandId,
                providerId,
                yearRelease,
                blockNumber,
                blockTypeId,
                sortBy,
                orderBy);

            var sortByFilter = GetSortExpression(sortBy);

            return(FindOrderedAsync(
                       filter,
                       sortByFilter,
                       orderBy,
                       _includesForPrint));
        }
Esempio n. 22
0
        public async Task <ActionResult <PageResult <ObjectModel> > > GetAll(
            string plateNumber      = null,
            string routeName        = null,
            int?carType             = null,
            int?project             = null,
            int?page                = null,
            int?pageSize            = null,
            int?carBrand            = null,
            int?provider            = null,
            int?yearRelease         = null,
            string blockNumber      = null,
            int?blockType           = null,
            ModelFormatsEnum format = ModelFormatsEnum.Pure,
            bool?active             = null,
            string sortBy           = "lastTime",
            OrderByEnum orderBy     = OrderByEnum.Desc)
        {
            var result = await _objectService.FindByParamsAsync(
                User,
                plateNumber,
                routeName,
                carType,
                project,
                format,
                active,
                carBrand,
                provider,
                yearRelease,
                blockNumber,
                blockType,
                sortBy,
                orderBy,
                page,
                pageSize);

            return(result);
        }
Esempio n. 23
0
        protected async Task <PageResult <TEntity> > FindPagedAsync(
            Expression <Func <TEntity, bool> > filter,
            Expression <Func <TEntity, object> > orderBySelector,
            OrderByEnum orderByEnum,
            int?page,
            int?pageSize,
            params string[] includes)
        {
            var orderByAsc = orderByEnum == OrderByEnum.Asc;
            var query      = Prepare(filter, includes);

            query = orderByAsc
                ? query.OrderBy(orderBySelector)
                : query.OrderByDescending(orderBySelector);

            var actualPage     = page ?? 1;
            var actualPageSize = pageSize.HasValue && (pageSize > 0 && pageSize <= 50)
                ? pageSize.Value
                : 50;

            var skipAmount = (actualPage - 1) * actualPageSize;

            var list = await query
                       .AsNoTracking()
                       .Skip(skipAmount)
                       .Take(actualPageSize)
                       .ToListAsync();

            var totalCount = filter != null
                ? await EntitySet.Where(filter).CountAsync()
                : await EntitySet.CountAsync();

            var result = new PageResult <TEntity>(list, totalCount);

            return(result);
        }
Esempio n. 24
0
 public CarPriceOrderBy(OrderByEnum orderBy)
 {
     this.OrderByType = orderBy;
 }
Esempio n. 25
0
 public DateOrderByClause(OrderByEnum orderBy)
 {
     this.orderBy = orderBy;
 }
 public static ThenOrderByQ <M> ThenOrderBy <M, F>(this OrderByQ <M> orderByQ, Expression <Func <M, F> > func, OrderByEnum orderBy = OrderByEnum.Desc)
 {
     orderByQ.DC.OP.OrderByHandle(func, orderBy);
     return(new ThenOrderByQ <M>(orderByQ.DC));
 }
        /**************************************************************************************************************/

        public static OrderByQ <M> OrderBy <M, F>(this WhereQ <M> where, Expression <Func <M, F> > func, OrderByEnum orderBy = OrderByEnum.Desc)
        {
            where.DC.OP.OrderByHandle(func, orderBy);
            return(new OrderByQ <M>(where.DC));
        }
Esempio n. 28
0
 /// <summary>
 /// 添加字段排序
 /// </summary>
 /// <param name="field">字段表达式</param>
 /// <param name="orderByEnum">排序规则</param>
 public void Add(Expression <Func <T, object> > field, OrderByEnum orderByEnum)
 {
     orderList.Add(field, orderByEnum);
 }
Esempio n. 29
0
        /// <summary>
        /// Get best sellers report
        /// </summary>
        /// <param name="storeId">Store identifier (orders placed in a specific store); 0 to load all records</param>
        /// <param name="vendorId">Vendor identifier; 0 to load all records</param>
        /// <param name="categoryId">Category identifier; 0 to load all records</param>
        /// <param name="manufacturerId">Manufacturer identifier; 0 to load all records</param>
        /// <param name="createdFromUtc">Order created date from (UTC); null to load all records</param>
        /// <param name="createdToUtc">Order created date to (UTC); null to load all records</param>
        /// <param name="os">Order status; null to load all records</param>
        /// <param name="ps">Order payment status; null to load all records</param>
        /// <param name="ss">Shipping status; null to load all records</param>
        /// <param name="billingCountryId">Billing country identifier; 0 to load all records</param>
        /// <param name="orderBy">1 - order by quantity, 2 - order by total amount</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Result</returns>
        public virtual IPagedList <BestsellersReportLine> BestSellersReport(
            int categoryId          = 0, int manufacturerId = 0,
            int storeId             = 0, int vendorId       = 0,
            DateTime?createdFromUtc = null, DateTime?createdToUtc = null,
            OrderStatus?os          = null, PaymentStatus?ps = null, ShippingStatus?ss = null,
            int billingCountryId    = 0,
            OrderByEnum orderBy     = OrderByEnum.OrderByQuantity,
            int pageIndex           = 0, int pageSize = int.MaxValue,
            bool showHidden         = false)
        {
            int?orderStatusId = null;

            if (os.HasValue)
            {
                orderStatusId = (int)os.Value;
            }

            int?paymentStatusId = null;

            if (ps.HasValue)
            {
                paymentStatusId = (int)ps.Value;
            }

            int?shippingStatusId = null;

            if (ss.HasValue)
            {
                shippingStatusId = (int)ss.Value;
            }

            var query1 = from orderItem in _orderItemRepository.Table
                         join o in _orderRepository.Table on orderItem.OrderId equals o.Id
                         join p in _productRepository.Table on orderItem.ProductId equals p.Id
                         join oba in _addressRepository.Table on o.BillingAddressId equals oba.Id
                         where (storeId == 0 || storeId == o.StoreId) &&
                         (!createdFromUtc.HasValue || createdFromUtc.Value <= o.CreatedOnUtc) &&
                         (!createdToUtc.HasValue || createdToUtc.Value >= o.CreatedOnUtc) &&
                         (!orderStatusId.HasValue || orderStatusId == o.OrderStatusId) &&
                         (!paymentStatusId.HasValue || paymentStatusId == o.PaymentStatusId) &&
                         (!shippingStatusId.HasValue || shippingStatusId == o.ShippingStatusId) &&
                         //(categoryId == 0 || p.ProductCategories.Count(pc => pc.CategoryId == categoryId) > 0) &&
                         //(manufacturerId == 0 || p.ProductManufacturers.Count(pm => pm.ManufacturerId == manufacturerId) >
                         //0) &&
                         !o.Deleted &&
                         !p.Deleted &&
                         (vendorId == 0 || p.VendorId == vendorId) &&
                         (billingCountryId == 0 || oba.CountryId == billingCountryId) &&
                         (showHidden || p.Published)
                         select orderItem;

            if (categoryId > 0)
            {
                query1 = from orderItem in query1
                         join p in _productRepository.Table on orderItem.ProductId equals p.Id
                         join pc in _productCategoryRepository.Table on p.Id equals pc.ProductId
                         into p_pc
                         from pc in p_pc.DefaultIfEmpty()
                         where pc.CategoryId == categoryId
                         select orderItem;
            }

            if (manufacturerId > 0)
            {
                query1 = from orderItem in query1
                         join p in _productRepository.Table on orderItem.ProductId equals p.Id
                         join pm in _productManufacturerRepository.Table on p.Id equals pm.ProductId
                         into p_pm
                         from pm in p_pm.DefaultIfEmpty()
                         where pm.ManufacturerId == manufacturerId
                         select orderItem;
            }

            var query2 =
                //group by products
                from orderItem in query1
                group orderItem by orderItem.ProductId into g
                select new BestsellersReportLine
            {
                ProductId     = g.Key,
                TotalAmount   = g.Sum(x => x.PriceExclTax),
                TotalQuantity = g.Sum(x => x.Quantity)
            };

            query2 = orderBy switch
            {
                OrderByEnum.OrderByQuantity => query2.OrderByDescending(x => x.TotalQuantity),
                OrderByEnum.OrderByTotalAmount => query2.OrderByDescending(x => x.TotalAmount),
                _ => throw new ArgumentException("Wrong orderBy parameter", nameof(orderBy)),
            };
            var result = new PagedList <BestsellersReportLine>(query2, pageIndex, pageSize);

            return(result);
        }
Esempio n. 30
0
        internal void OrderByF <F>(Expression <Func <F> > func, OrderByEnum orderBy)
        {
            var keyDic = DC.XE.FuncTExpression(func);

            AddOrderByParam(keyDic, orderBy);
        }