Пример #1
0
        /// <summary>
        /// Prepare affiliate model
        /// </summary>
        /// <param name="model">Affiliate model</param>
        /// <param name="affiliate">Affiliate</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Affiliate model</returns>
        public virtual async Task <AffiliateModel> PrepareAffiliateModelAsync(AffiliateModel model, Affiliate affiliate, bool excludeProperties = false)
        {
            //fill in model values from the entity
            if (affiliate != null)
            {
                model ??= affiliate.ToModel <AffiliateModel>();
                model.Url = await _affiliateService.GenerateUrlAsync(affiliate);

                //prepare nested search models
                await PrepareAffiliatedOrderSearchModelAsync(model.AffiliatedOrderSearchModel, affiliate);

                PrepareAffiliatedCustomerSearchModel(model.AffiliatedCustomerSearchModel, affiliate);

                //prepare address model
                var address = await _addressService.GetAddressByIdAsync(affiliate.AddressId);

                model.Address = address.ToModel(model.Address);
                await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address, address);

                //whether to fill in some of properties
                if (!excludeProperties)
                {
                    model.AdminComment    = affiliate.AdminComment;
                    model.FriendlyUrlName = affiliate.FriendlyUrlName;
                    model.Active          = affiliate.Active;
                }
            }
            else
            {
                await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address);
            }

            return(model);
        }
Пример #2
0
        /// <summary>
        /// Prepare warehouse model
        /// </summary>
        /// <param name="model">Warehouse model</param>
        /// <param name="warehouse">Warehouse</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Warehouse model</returns>
        public virtual async Task <WarehouseModel> PrepareWarehouseModelAsync(WarehouseModel model, Warehouse warehouse, bool excludeProperties = false)
        {
            if (warehouse != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model = warehouse.ToModel <WarehouseModel>();
                }
            }

            //prepare address model
            var address = await _addressService.GetAddressByIdAsync(warehouse?.AddressId ?? 0);

            if (!excludeProperties && address != null)
            {
                model.Address = address.ToModel(model.Address);
            }
            await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address, address);

            return(model);
        }
Пример #3
0
        /// <summary>
        /// Prepare vendor model
        /// </summary>
        /// <param name="model">Vendor model</param>
        /// <param name="vendor">Vendor</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Vendor model</returns>
        public virtual async Task <VendorModel> PrepareVendorModelAsync(VendorModel model, Vendor vendor, bool excludeProperties = false)
        {
            Action <VendorLocalizedModel, int> localizedModelConfiguration = null;

            if (vendor != null)
            {
                //fill in model values from the entity
                if (model == null)
                {
                    model        = vendor.ToModel <VendorModel>();
                    model.SeName = await _urlRecordService.GetSeNameAsync(vendor, 0, true, false);
                }

                //define localized model configuration action
                localizedModelConfiguration = async(locale, languageId) =>
                {
                    locale.Name = await _localizationService.GetLocalizedAsync(vendor, entity => entity.Name, languageId, false, false);

                    locale.Description = await _localizationService.GetLocalizedAsync(vendor, entity => entity.Description, languageId, false, false);

                    locale.MetaKeywords = await _localizationService.GetLocalizedAsync(vendor, entity => entity.MetaKeywords, languageId, false, false);

                    locale.MetaDescription = await _localizationService.GetLocalizedAsync(vendor, entity => entity.MetaDescription, languageId, false, false);

                    locale.MetaTitle = await _localizationService.GetLocalizedAsync(vendor, entity => entity.MetaTitle, languageId, false, false);

                    locale.SeName = await _urlRecordService.GetSeNameAsync(vendor, languageId, false, false);
                };

                //prepare associated customers
                await PrepareAssociatedCustomerModelsAsync(model.AssociatedCustomers, vendor);

                //prepare nested search models
                PrepareVendorNoteSearchModel(model.VendorNoteSearchModel, vendor);
            }

            //set default values for the new model
            if (vendor == null)
            {
                model.PageSize = 6;
                model.Active   = true;
                model.AllowCustomersToSelectPageSize = true;
                model.PageSizeOptions     = _vendorSettings.DefaultVendorPageSizeOptions;
                model.PriceRangeFiltering = true;
                model.PriceFrom           = NopCatalogDefaults.DefaultPriceRangeFrom;
                model.PriceTo             = NopCatalogDefaults.DefaultPriceRangeTo;
            }

            model.PrimaryStoreCurrencyCode = (await _currencyService.GetCurrencyByIdAsync(_currencySettings.PrimaryStoreCurrencyId)).CurrencyCode;

            //prepare localized models
            if (!excludeProperties)
            {
                model.Locales = await _localizedModelFactory.PrepareLocalizedModelsAsync(localizedModelConfiguration);
            }

            //prepare model vendor attributes
            await PrepareVendorAttributeModelsAsync(model.VendorAttributes, vendor);

            //prepare address model
            var address = await _addressService.GetAddressByIdAsync(vendor?.AddressId ?? 0);

            if (!excludeProperties && address != null)
            {
                model.Address = address.ToModel(model.Address);
            }
            await _baseAdminModelFactory.PrepareAddressModelAsync(model.Address, address);

            return(model);
        }