Example #1
0
        public virtual IActionResult ManufacturerList(DiscountManufacturerSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts))
                return AccessDeniedKendoGridJson();

            //try to get a discount with the specified id
            var discount = _discountService.GetDiscountById(searchModel.DiscountId)
                ?? throw new ArgumentException("No discount found with the specified id");

            //prepare model
            var model = _discountModelFactory.PrepareDiscountManufacturerListModel(searchModel, discount);

            return Json(model);
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> ManufacturerList(DiscountManufacturerSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageDiscounts))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get a discount with the specified id
            var discount = await _discountService.GetDiscountByIdAsync(searchModel.DiscountId)
                           ?? throw new ArgumentException("No discount found with the specified id");

            //prepare model
            var model = await _discountModelFactory.PrepareDiscountManufacturerListModelAsync(searchModel, discount);

            return(Json(model));
        }
Example #3
0
        /// <summary>
        /// Prepare paged discount manufacturer list model
        /// </summary>
        /// <param name="searchModel">Discount manufacturer search model</param>
        /// <param name="discount">Discount</param>
        /// <returns>Discount manufacturer list model</returns>
        public virtual DiscountManufacturerListModel PrepareDiscountManufacturerListModel(DiscountManufacturerSearchModel searchModel,
                                                                                          Discount discount)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (discount == null)
            {
                throw new ArgumentNullException(nameof(discount));
            }

            //get manufacturers with applied discount
            var discountManufacturers = _manufacturerService.GetManufacturersWithAppliedDiscount(discountId: discount.Id,
                                                                                                 showHidden: false,
                                                                                                 pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new DiscountManufacturerListModel().PrepareToGrid(searchModel, discountManufacturers, () =>
            {
                //fill in model values from the entity
                return(discountManufacturers.Select(manufacturer =>
                {
                    var discountManufacturerModel = manufacturer.ToModel <DiscountManufacturerModel>();
                    discountManufacturerModel.ManufacturerId = manufacturer.Id;
                    discountManufacturerModel.ManufacturerName = manufacturer.Name;

                    return discountManufacturerModel;
                }));
            });

            return(model);
        }
Example #4
0
        /// <summary>
        /// Prepare discount manufacturer search model
        /// </summary>
        /// <param name="searchModel">Discount manufacturer search model</param>
        /// <param name="discount">Discount</param>
        /// <returns>Discount manufacturer search model</returns>
        protected virtual DiscountManufacturerSearchModel PrepareDiscountManufacturerSearchModel(DiscountManufacturerSearchModel searchModel,
                                                                                                 Discount discount)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (discount == null)
            {
                throw new ArgumentNullException(nameof(discount));
            }

            searchModel.DiscountId = discount.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Example #5
0
        /// <summary>
        /// Prepare paged discount manufacturer list model
        /// </summary>
        /// <param name="searchModel">Discount manufacturer search model</param>
        /// <param name="discount">Discount</param>
        /// <returns>Discount manufacturer list model</returns>
        public virtual DiscountManufacturerListModel PrepareDiscountManufacturerListModel(DiscountManufacturerSearchModel searchModel,
                                                                                          Discount discount)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (discount == null)
            {
                throw new ArgumentNullException(nameof(discount));
            }

            //get manufacturers with applied discount
            var discountManufacturers = _discountService.GetManufacturersWithAppliedDiscount(discountId: discount.Id,
                                                                                             showHidden: false,
                                                                                             pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new DiscountManufacturerListModel
            {
                //fill in model values from the entity
                Data = discountManufacturers.Select(manufacturer => new DiscountManufacturerModel
                {
                    ManufacturerId   = manufacturer.Id,
                    ManufacturerName = manufacturer.Name
                }),
                Total = discountManufacturers.TotalCount
            };

            return(model);
        }