Пример #1
0
        protected async Task <DateTimeSettingsModel> PrepareDateTimeSettingsModel()
        {
            var tenantId         = _tenantContext.ActiveTenantScopeConfiguration;
            var dateTimeSettings = _settingService.LoadSetting <DateTimeSettings>(tenantId);

            var model = new DateTimeSettingsModel
            {
                AllowUsersToSetTimeZone = dateTimeSettings.AllowUsersToSetTimeZone,
                DefaultTimeZoneId       = _dateTimeHelper.DefaultStoreTimeZone.Id,
            };

            //prepare available time zones
            await _baseModelFactory.PrepareTimeZones(model.AvailableTimeZones, false);

            return(model);
        }
Пример #2
0
        /// <summary>
        /// Prepare user model
        /// </summary>
        /// <param name="model">User model</param>
        /// <param name="user">User</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns></returns>
        public async Task <UserModel> PrepareUserModel(UserModel model, User user, bool excludeProperties = false)
        {
            if (user != null)
            {
                model = model ?? new UserModel();

                model.Id = user.Id;
                //whether to fill in some of properties
                if (!excludeProperties)
                {
                    model.Email     = user.Email;
                    model.Username  = user.Username;
                    model.Barcode   = user.Barcode;
                    model.Active    = user.Active;
                    model.FirstName = await _genericAttributeService.GetAttributeAsync <string>(user, UserDefaults.FirstNameAttribute);

                    model.LastName = await _genericAttributeService.GetAttributeAsync <string>(user, UserDefaults.LastNameAttribute);

                    model.Gender = await _genericAttributeService.GetAttributeAsync <string>(user, UserDefaults.GenderAttribute);

                    model.DateOfBirth = await _genericAttributeService.GetAttributeAsync <DateTime?>(user, UserDefaults.DateOfBirthAttribute);

                    model.Phone = await _genericAttributeService.GetAttributeAsync <string>(user, UserDefaults.PhoneAttribute);

                    model.CreatedOn        = _dateTimeHelper.ConvertToUserTime(user.CreatedOnUtc, DateTimeKind.Utc);
                    model.LastActivityDate = _dateTimeHelper.ConvertToUserTime(user.LastActivityDateUtc, DateTimeKind.Utc);
                    model.LastIpAddress    = user.LastIpAddress;
                    model.LastVisitedPage  = await _genericAttributeService.GetAttributeAsync <string>(user, UserDefaults.LastVisitedPageAttribute);

                    model.SelectedRoleIds = user.UserRoles.Select(map => map.RoleId).ToList();
                }
                //prepare nested search models
                PrepareUserActivityLogSearchModel(model.UserActivityLogSearchModel, user);
            }
            else
            {
                //whether to fill in some of properties
                if (!excludeProperties)
                {
                    //precheck Registered Role
                    var registeredRole = _userService.GetRoleBySystemName(UserDefaults.RegisteredRoleName);
                    if (registeredRole != null)
                    {
                        model.SelectedRoleIds.Add(registeredRole.Id);
                    }
                }
            }

            model.UsernamesEnabled   = _userSettings.UsernamesEnabled;
            model.GenderEnabled      = _userSettings.GenderEnabled;
            model.DateOfBirthEnabled = _userSettings.DateOfBirthEnabled;
            model.PhoneEnabled       = _userSettings.PhoneEnabled;

            //set default values for the new model
            if (user == null)
            {
                model.Active = true;
            }

            //prepare model user roles
            _aclSupportedModelFactory.PrepareModelRoles(model);

            //prepare model user stores
            var availableStores = await _storeService.GetStores();

            _appliedStoreSupportedModelFactory.PrepareModelAppliedStores(model, user, availableStores, excludeProperties);

            //prepare available time zones
            await _baseModelFactory.PrepareTimeZones(model.AvailableTimeZones, false);

            return(model);
        }