/// <summary>
        /// Prepare paged never sold report list model
        /// </summary>
        /// <param name="searchModel">Never sold report search model</param>
        /// <returns>Never sold report list model</returns>
        public virtual NeverSoldReportListModel PrepareNeverSoldListModel(NeverSoldReportSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter neverSoldReports
            if (_workContext.CurrentVendor != null)
            {
                searchModel.SearchVendorId = _workContext.CurrentVendor.Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //get report items
            var items = _orderReportService.ProductsNeverSold(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
            {
                //fill in model values from the entity
                Data = items.Select(item => new NeverSoldReportModel
                {
                    ProductId   = item.Id,
                    ProductName = item.Name
                }),
                Total = items.TotalCount
            };

            return(model);
        }
Beispiel #2
0
        public async Task <IActionResult> NeverSoldReportList(DataSourceRequest command, NeverSoldReportModel model)
        {
            //a vendor should have access only to his products
            string vendorId = "";

            if (_workContext.CurrentVendor != null)
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            string storeId = "";

            if (_workContext.CurrentCustomer.IsStaff())
            {
                storeId = _workContext.CurrentCustomer.StaffStoreId;
            }

            var items = await _orderReportService.ProductsNeverSold(storeId, vendorId,
                                                                    startDateValue, endDateValue,
                                                                    command.Page - 1, command.PageSize, true);

            var gridModel = new DataSourceResult
            {
                Data = items.Select(x =>
                                    new NeverSoldReportLineModel
                {
                    ProductId   = x.Id,
                    ProductName = x.Name,
                }),
                Total = items.TotalCount
            };

            return(Json(gridModel));
        }
        public IActionResult NeverSoldReportList(DataSourceRequest command, NeverSoldReportModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageOrders))
            {
                return(Content(""));
            }

            //a vendor should have access only to his products
            string vendorId = "";

            if (_workContext.CurrentVendor != null)
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            DateTime?startDateValue = (model.StartDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.StartDate.Value, _dateTimeHelper.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            var items = _orderReportService.ProductsNeverSold(vendorId,
                                                              startDateValue, endDateValue,
                                                              command.Page - 1, command.PageSize, true);
            var gridModel = new DataSourceResult
            {
                Data = items.Select(x =>
                                    new NeverSoldReportLineModel
                {
                    ProductId   = x.Id,
                    ProductName = x.Name,
                }),
                Total = items.TotalCount
            };

            return(Json(gridModel));
        }