コード例 #1
0
        public ActionResult List(DiscountListModel model, DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            DiscountType?discountType = null;

            if (model.SearchDiscountTypeId > 0)
            {
                discountType = (DiscountType)model.SearchDiscountTypeId;
            }
            var discounts = _discountService.GetAllDiscounts(discountType,
                                                             model.SearchDiscountCouponCode,
                                                             model.SearchDiscountName,
                                                             true);

            var gridModel = new DataSourceResult
            {
                Data = discounts.PagedForCommand(command).Select(x =>
                {
                    var discountModel = x.ToModel();
                    discountModel.DiscountTypeName         = x.DiscountType.GetLocalizedEnum(_localizationService, _workContext);
                    discountModel.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
                    discountModel.TimesUsed = _discountService.GetAllDiscountUsageHistory(x.Id, pageSize: 1).TotalCount;
                    return(discountModel);
                }),
                Total = discounts.Count
            };

            return(Json(gridModel));
        }
コード例 #2
0
        public virtual IActionResult List(DiscountListModel model, DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedKendoGridJson());
            }

            var discountType = model.SearchDiscountTypeId > 0 ? (DiscountType?)model.SearchDiscountTypeId : null;
            var startDateUtc = model.SearchStartDate.HasValue ?
                               (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.SearchStartDate.Value, _dateTimeHelper.CurrentTimeZone) : null;
            var endDateUtc = model.SearchEndDate.HasValue ?
                             (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.SearchEndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1) : null;

            var discounts = _discountService.GetAllDiscounts(discountType, model.SearchDiscountCouponCode,
                                                             model.SearchDiscountName, true, startDateUtc, endDateUtc);

            var gridModel = new DataSourceResult
            {
                Data = discounts.PagedForCommand(command).Select(discount =>
                {
                    var discountModel = discount.ToModel();

                    discountModel.DiscountTypeName         = discount.DiscountType.GetLocalizedEnum(_localizationService, _workContext);
                    discountModel.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)?.CurrencyCode;
                    discountModel.TimesUsed = _discountService.GetAllDiscountUsageHistory(discount.Id, pageSize: 1).TotalCount;

                    return(discountModel);
                }),
                Total = discounts.Count
            };

            return(Json(gridModel));
        }
コード例 #3
0
        public ActionResult List(DiscountListModel model, DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            DiscountType?discountType = null;

            if (model.SearchDiscountTypeId > 0)
            {
                discountType = (DiscountType)model.SearchDiscountTypeId;
            }
            var couponCode = !String.IsNullOrEmpty(model.SearchDiscountCouponCode) ? model.SearchDiscountCouponCode.Trim() : null;
            var discounts  = _discountService.GetAllDiscounts(discountType, couponCode, true);
            var gridModel  = new DataSourceResult
            {
                Data = discounts.PagedForCommand(command).Select(x =>
                {
                    var discountModel = x.ToModel();
                    discountModel.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
                    return(discountModel);
                }),
                Total = discounts.Count
            };

            return(Json(gridModel));
        }
コード例 #4
0
        public virtual DiscountListModel PrepareDiscountListModel()
        {
            var model = new DiscountListModel {
                AvailableDiscountTypes = DiscountType.AssignedToOrderTotal.ToSelectList(_localizationService, _workContext, false).ToList()
            };

            model.AvailableDiscountTypes.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = ""
            });
            return(model);
        }
コード例 #5
0
        public IActionResult List(DiscountListModel model, DataSourceRequest command)
        {
            var discounts = _discountViewModelService.PrepareDiscountModel(model, command.Page, command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data  = discounts.discountModel.ToList(),
                Total = discounts.totalCount
            };

            return(Json(gridModel));
        }
コード例 #6
0
        public async Task <IActionResult> List(DiscountListModel model, DataSourceRequest command)
        {
            var(discountModel, totalCount) = await _discountViewModelService.PrepareDiscountModel(model, command.Page, command.PageSize);

            var gridModel = new DataSourceResult {
                Data  = discountModel.ToList(),
                Total = totalCount
            };

            return(Json(gridModel));
        }
コード例 #7
0
        public ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var model = new DiscountListModel();

            model.AvailableDiscountTypes = DiscountType.AssignedToOrderTotal.ToSelectList(false).ToList();
            model.AvailableDiscountTypes.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            return(View(model));
        }
コード例 #8
0
        /// <summary>
        /// Prepare paged discount list model
        /// </summary>
        /// <param name="searchModel">Discount search model</param>
        /// <returns>Discount list model</returns>
        public virtual DiscountListModel PrepareDiscountListModel(DiscountSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter discounts
            var discountType = searchModel.SearchDiscountTypeId > 0 ? (DiscountType?)searchModel.SearchDiscountTypeId : null;
            var startDateUtc = searchModel.SearchStartDate.HasValue ?
                               (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.SearchStartDate.Value, _dateTimeHelper.CurrentTimeZone) : null;
            var endDateUtc = searchModel.SearchEndDate.HasValue ?
                             (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.SearchEndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1) : null;

            //get discounts
            var discounts = _discountService.GetAllDiscounts(showHidden: true,
                                                             discountType: discountType,
                                                             couponCode: searchModel.SearchDiscountCouponCode,
                                                             discountName: searchModel.SearchDiscountName,
                                                             startDateUtc: startDateUtc,
                                                             endDateUtc: endDateUtc);

            //prepare list model
            var model = new DiscountListModel
            {
                Data = discounts.PaginationByRequestModel(searchModel).Select(discount =>
                {
                    //fill in model values from the entity
                    var discountModel = discount.ToModel <DiscountModel>();

                    //fill in additional values (not existing in the entity)
                    discountModel.DiscountTypeName         = _localizationService.GetLocalizedEnum(discount.DiscountType);
                    discountModel.PrimaryStoreCurrencyCode = _currencyService
                                                             .GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)?.CurrencyCode;
                    discountModel.TimesUsed = _discountService.GetAllDiscountUsageHistory(discount.Id, pageSize: 1).TotalCount;

                    return(discountModel);
                }),
                Total = discounts.Count
            };

            return(model);
        }
コード例 #9
0
        public virtual IActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
            {
                return(AccessDeniedView());
            }

            var model = new DiscountListModel();

            model.AvailableDiscountTypes = DiscountType.AssignedToOrderTotal.ToSelectList(false).ToList();
            model.AvailableDiscountTypes.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            if (_catalogSettings.IgnoreDiscounts)
            {
                WarningNotification(_localizationService.GetResource("Admin.Promotions.Discounts.IgnoreDiscounts.Warning"));
            }

            return(View(model));
        }
コード例 #10
0
        public virtual (IEnumerable <DiscountModel> discountModel, int totalCount) PrepareDiscountModel(DiscountListModel model, int pageIndex, int pageSize)
        {
            DiscountType?discountType = null;

            if (model.SearchDiscountTypeId > 0)
            {
                discountType = (DiscountType)model.SearchDiscountTypeId;
            }
            var discounts = _discountService.GetAllDiscounts(discountType,
                                                             model.SearchDiscountCouponCode,
                                                             model.SearchDiscountName,
                                                             true);

            return(discounts.Skip((pageIndex - 1) * pageSize).Take(pageSize).Select(x =>
            {
                var discountModel = x.ToModel();
                discountModel.DiscountTypeName = x.DiscountType.GetLocalizedEnum(_localizationService, _workContext);
                discountModel.PrimaryStoreCurrencyCode = x.CalculateByPlugin ? "" : _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode;
                discountModel.TimesUsed = _discountService.GetAllDiscountUsageHistory(x.Id, pageSize: 1).TotalCount;
                return discountModel;
            }), discounts.Count);
        }
コード例 #11
0
        public virtual async Task <(IEnumerable <DiscountModel> discountModel, int totalCount)> PrepareDiscountModel(DiscountListModel model, int pageIndex, int pageSize)
        {
            DiscountType?discountType = null;

            if (model.SearchDiscountTypeId > 0)
            {
                discountType = (DiscountType)model.SearchDiscountTypeId;
            }
            var discounts = await _discountService.GetAllDiscounts(discountType, _workContext.CurrentCustomer.StaffStoreId,
                                                                   model.SearchDiscountCouponCode,
                                                                   model.SearchDiscountName,
                                                                   true);

            var items = new List <DiscountModel>();

            foreach (var x in discounts.Skip((pageIndex - 1) * pageSize).Take(pageSize))
            {
                var discountModel = x.ToModel(_dateTimeHelper);
                discountModel.DiscountTypeName         = x.DiscountType.GetLocalizedEnum(_localizationService, _workContext);
                discountModel.PrimaryStoreCurrencyCode = x.CalculateByPlugin ? "" : (await _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)).CurrencyCode;
                discountModel.TimesUsed = (await _discountService.GetAllDiscountUsageHistory(x.Id, pageSize: 1)).TotalCount;
                items.Add(discountModel);
            }
            ;
            return(items, discounts.Count);
        }
コード例 #12
0
        public virtual async Task <(IEnumerable <DiscountModel> discountModel, int totalCount)> PrepareDiscountModel(DiscountListModel model, int pageIndex, int pageSize)
        {
            DiscountType?discountType = null;

            if (model.SearchDiscountTypeId > 0)
            {
                discountType = (DiscountType)model.SearchDiscountTypeId;
            }
            var discounts = await _discountService.GetAllDiscounts(discountType, _workContext.CurrentCustomer.StaffStoreId,
                                                                   null,
                                                                   model.SearchDiscountCouponCode,
                                                                   model.SearchDiscountName,
                                                                   true);

            var items = new List <DiscountModel>();

            foreach (var x in discounts.Skip((pageIndex - 1) * pageSize).Take(pageSize))
            {
                var discountModel = x.ToModel(_dateTimeService);
                discountModel.DiscountTypeName = x.DiscountTypeId.GetTranslationEnum(_translationService, _workContext);
                discountModel.TimesUsed        = (await _discountService.GetAllDiscountUsageHistory(x.Id, pageSize: 1)).TotalCount;
                items.Add(discountModel);
            }
            ;
            return(items, discounts.Count);
        }