Пример #1
0
        /// <summary>
        /// Prepare paged never sold report list model
        /// </summary>
        /// <param name="searchModel">Never sold report search model</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the never sold report list model
        /// </returns>
        public virtual async Task <NeverSoldReportListModel> PrepareNeverSoldListModelAsync(NeverSoldReportSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter neverSoldReports
            var currentVendor = await _workContext.GetCurrentVendorAsync();

            if (currentVendor != null)
            {
                searchModel.SearchVendorId = currentVendor.Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync());
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1);

            //get report items
            var items = await _orderReportService.ProductsNeverSoldAsync(showHidden : true,
                                                                         vendorId : searchModel.SearchVendorId,
                                                                         storeId : searchModel.SearchStoreId,
                                                                         categoryId : searchModel.SearchCategoryId,
                                                                         manufacturerId : searchModel.SearchManufacturerId,
                                                                         createdFromUtc : startDateValue,
                                                                         createdToUtc : endDateValue,
                                                                         pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize);

            //prepare list model
            var model = new NeverSoldReportListModel().PrepareToGrid(searchModel, items, () =>
            {
                //fill in model values from the entity
                return(items.Select(item => new NeverSoldReportModel
                {
                    ProductId = item.Id,
                    ProductName = item.Name
                }));
            });

            return(model);
        }