/// <summary>
        /// Prepare paged checkout attribute value list model
        /// </summary>
        /// <param name="searchModel">Checkout attribute value search model</param>
        /// <param name="checkoutAttribute">Checkout attribute</param>
        /// <returns>Checkout attribute value list model</returns>
        public virtual CheckoutAttributeValueListModel PrepareCheckoutAttributeValueListModel(CheckoutAttributeValueSearchModel searchModel,
                                                                                              CheckoutAttribute checkoutAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get checkout attribute values
            var checkoutAttributeValues = _checkoutAttributeService.GetCheckoutAttributeValues(checkoutAttribute.Id);

            //prepare list model
            var model = new CheckoutAttributeValueListModel
            {
                Data = checkoutAttributeValues.PaginationByRequestModel(searchModel).Select(value =>
                {
                    //fill in model values from the entity
                    var checkoutAttributeValueModel = value.ToModel <CheckoutAttributeValueModel>();

                    //fill in additional values (not existing in the entity)
                    checkoutAttributeValueModel.Name = value.CheckoutAttribute.AttributeControlType != AttributeControlType.ColorSquares
                        ? value.Name : $"{value.Name} - {value.ColorSquaresRgb}";

                    return(checkoutAttributeValueModel);
                }),
                Total = checkoutAttributeValues.Count
            };

            return(model);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prepare paged checkout attribute value list model
        /// </summary>
        /// <param name="searchModel">Checkout attribute value search model</param>
        /// <param name="checkoutAttribute">Checkout attribute</param>
        /// <returns>Checkout attribute value list model</returns>
        public virtual CheckoutAttributeValueListModel PrepareCheckoutAttributeValueListModel(CheckoutAttributeValueSearchModel searchModel,
                                                                                              CheckoutAttribute checkoutAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get checkout attribute values
            var checkoutAttributeValues = _checkoutAttributeService.GetCheckoutAttributeValues(checkoutAttribute.Id);

            //prepare list model
            var model = new CheckoutAttributeValueListModel
            {
                //fill in model values from the entity
                Data = checkoutAttributeValues.PaginationByRequestModel(searchModel).Select(value => new CheckoutAttributeValueModel
                {
                    Id = value.Id,
                    CheckoutAttributeId = value.CheckoutAttributeId,
                    Name = value.CheckoutAttribute.AttributeControlType != AttributeControlType.ColorSquares
                        ? value.Name : $"{value.Name} - {value.ColorSquaresRgb}",
                    ColorSquaresRgb  = value.ColorSquaresRgb,
                    PriceAdjustment  = value.PriceAdjustment,
                    WeightAdjustment = value.WeightAdjustment,
                    IsPreSelected    = value.IsPreSelected,
                    DisplayOrder     = value.DisplayOrder
                }),
                Total = checkoutAttributeValues.Count
            };

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prepare paged checkout attribute value list model
        /// </summary>
        /// <param name="searchModel">Checkout attribute value search model</param>
        /// <param name="checkoutAttribute">Checkout attribute</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the checkout attribute value list model
        /// </returns>
        public virtual async Task <CheckoutAttributeValueListModel> PrepareCheckoutAttributeValueListModelAsync(CheckoutAttributeValueSearchModel searchModel,
                                                                                                                CheckoutAttribute checkoutAttribute)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get checkout attribute values
            var checkoutAttributeValues = (await _checkoutAttributeService
                                           .GetCheckoutAttributeValuesAsync(checkoutAttribute.Id)).ToPagedList(searchModel);

            //prepare list model
            var model = new CheckoutAttributeValueListModel().PrepareToGrid(searchModel, checkoutAttributeValues, () =>
            {
                return(checkoutAttributeValues.Select(value =>
                {
                    //fill in model values from the entity
                    var checkoutAttributeValueModel = value.ToModel <CheckoutAttributeValueModel>();

                    //fill in additional values (not existing in the entity)
                    checkoutAttributeValueModel.Name =
                        checkoutAttribute.AttributeControlType != AttributeControlType.ColorSquares
                            ? value.Name
                            : $"{value.Name} - {value.ColorSquaresRgb}";

                    return checkoutAttributeValueModel;
                }));
            });

            return(model);
        }