Пример #1
0
        /// <summary>
        /// Prepare user attribute model
        /// </summary>
        /// <param name="model">User attribute model</param>
        /// <param name="userAttribute">User attribute</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>User attribute model</returns>
        public virtual UserAttributeModel PrepareUserAttributeModel(UserAttributeModel model,
                                                                    UserAttribute userAttribute, bool excludeProperties = false)
        {
            Action <UserAttributeLocalizedModel, int> localizedModelConfiguration = null;

            if (userAttribute != null)
            {
                //fill in model values from the entity
                model = model ?? userAttribute.ToModel <UserAttributeModel>();

                //prepare nested search model
                PrepareUserAttributeValueSearchModel(model.UserAttributeValueSearchModel, userAttribute);

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name = _localizationService.GetLocalized(userAttribute, entity => entity.Name, languageId, false, false);
                };
            }

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

            return(model);
        }