Exemplo n.º 1
0
    public static UserGroupDto BuildDto(IUserGroup entity)
    {
        var dto = new UserGroupDto
        {
            Alias = entity.Alias,
            DefaultPermissions = entity.Permissions == null ? string.Empty : string.Join(string.Empty, entity.Permissions),
            Name = entity.Name,
            UserGroup2AppDtos = new List <UserGroup2AppDto>(),
            CreateDate        = entity.CreateDate,
            UpdateDate        = entity.UpdateDate,
            Icon           = entity.Icon,
            StartMediaId   = entity.StartMediaId,
            StartContentId = entity.StartContentId,
        };

        foreach (var app in entity.AllowedSections)
        {
            var appDto = new UserGroup2AppDto {
                AppAlias = app
            };
            if (entity.HasIdentity)
            {
                appDto.UserGroupId = entity.Id;
            }

            dto.UserGroup2AppDtos.Add(appDto);
        }

        if (entity.HasIdentity)
        {
            dto.Id = short.Parse(entity.Id.ToString());
        }

        return(dto);
    }
        private void AddSection(UserGroup2AppDto section)
        {
            //this can be null since we are left joining
            if (section == null || section.AppAlias.IsNullOrWhiteSpace())
            {
                return;
            }

            var latestGroup = _currentUser.UserGroupDtos.Count > 0
                ? _currentUser.UserGroupDtos[_currentUser.UserGroupDtos.Count - 1]
                : null;

            if (latestGroup == null || latestGroup.Id != section.UserGroupId)
            {
                throw new InvalidOperationException("The user group and section info don't match");
            }

            if (latestGroup.UserGroup2AppDtos == null)
            {
                latestGroup.UserGroup2AppDtos = new List <UserGroup2AppDto>();
            }

            //add it if it doesn't exist
            if (latestGroup.UserGroup2AppDtos.TrueForAll(dto => dto.AppAlias != section.AppAlias))
            {
                latestGroup.UserGroup2AppDtos.Add(section);
            }
        }
        private void AddOrUpdateGroup(UserGroupDto group, UserGroup2AppDto section)
        {
            //I don't even think this situation can happen but if it could, we'd want the section added to the latest group check if this is a new group
            if (group == null && section != null)
            {
                AddSection(section);
            }

            //this can be null since we are doing a left join
            if (group == null || group.Alias.IsNullOrWhiteSpace())
            {
                return;
            }

            //check if this is a new group
            var latestGroup = _currentUser.UserGroupDtos.Count > 0
                ? _currentUser.UserGroupDtos[_currentUser.UserGroupDtos.Count - 1]
                : null;

            if (latestGroup == null || latestGroup.Id != group.Id)
            {
                //add the current (new) group
                _currentUser.UserGroupDtos.Add(group);
            }

            AddSection(section);
        }
        private void PersistAllowedSections(IUserGroup entity)
        {
            var userGroup = entity;

            // First delete all
            Database.Delete <UserGroup2AppDto>("WHERE UserGroupId = @UserGroupId", new { UserGroupId = userGroup.Id });

            // Then re-add any associated with the group
            foreach (var app in userGroup.AllowedSections)
            {
                var dto = new UserGroup2AppDto
                {
                    UserGroupId = userGroup.Id,
                    AppAlias    = app
                };
                Database.Insert(dto);
            }
        }
Exemplo n.º 5
0
        internal UserGroupDto Map(UserGroupDto a, UserGroup2AppDto p)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (a == null)
            {
                return(Current);
            }

            // Is this the same object as the current one we're processing
            if (Current != null && Current.Id == a.Id)
            {
                if (p.AppAlias.IsNullOrWhiteSpace() == false)
                {
                    // Yes, just add this to the current item's collection
                    Current.UserGroup2AppDtos.Add(p);
                }

                // Return null to indicate we're not done with this User yet
                return(null);
            }

            // This is a different object to the current one, or this is the
            // first time through and we don't have one yet

            // Save the current instance
            var prev = Current;

            // Setup the new current instance
            Current = a;
            Current.UserGroup2AppDtos = new List <UserGroup2AppDto>();
            //this can be null since we are doing a left join
            if (p.AppAlias.IsNullOrWhiteSpace() == false)
            {
                Current.UserGroup2AppDtos.Add(p);
            }

            // Return the now populated previous user group (or null if first time through)
            return(prev);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Ensures the Merchello database has been installed.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        internal bool EnsureDatabase()
        {
            var databaseSchemaCreation = new DatabaseSchemaCreation(_database, _logger, new DatabaseSchemaHelper(_database, _logger, _sqlSyntaxProvider), _sqlSyntaxProvider);
            var schemaResult           = databaseSchemaCreation.ValidateSchema();
            var databaseVersion        = schemaResult.DetermineInstalledVersion();

            if (databaseVersion != new Version("0.0.0"))
            {
                return(true);
            }

            // install the database
            var schemaHelper = new MerchelloDatabaseSchemaHelper(this._database, this._logger, this._sqlSyntaxProvider);

            schemaHelper.CreateDatabaseSchema();

            var baseDataCreation = new BaseDataCreation(this._database, this._logger);

            baseDataCreation.InitializeBaseData("merchTypeField");
            baseDataCreation.InitializeBaseData("merchInvoiceStatus");
            baseDataCreation.InitializeBaseData("merchOrderStatus");
            baseDataCreation.InitializeBaseData("merchWarehouse");
            baseDataCreation.InitializeBaseData("merchGatewayProviderSettings");
            baseDataCreation.InitializeBaseData("merchStoreSetting");
            baseDataCreation.InitializeBaseData("merchShipmentStatus");

            // Add 'merchello' to the admin group
            var ug = new UserGroup2AppDto {
                UserGroupId = 1, AppAlias = "merchello"
            };

            _database.Insert(ug);

            // TODO clear cache

            return(false);
        }
        internal UserDto Map(UserDto user, UserGroupDto group, UserGroup2AppDto section, UserStartNodeDto startNode)
        {
            // Terminating call.  Since we can return null from this function
            // we need to be ready for PetaPoco to callback later with null
            // parameters
            if (user == null)
            {
                return(_currentUser);
            }

            // Is this the same User as the current one we're processing
            if (_currentUser != null && _currentUser.Id == user.Id)
            {
                AddOrUpdateGroup(group, section);
                AddOrUpdateStartNode(startNode);

                // Return null to indicate we're not done with this object yet
                return(null);
            }

            // This is a different user to the current one, or this is the
            // first time through and we don't have one yet

            // Save the current user
            var prev = _currentUser;

            // Setup the new current user
            _currentUser = user;
            _currentUser.UserGroupDtos     = new List <UserGroupDto>();
            _currentUser.UserStartNodeDtos = new HashSet <UserStartNodeDto>();

            AddOrUpdateGroup(group, section);
            AddOrUpdateStartNode(startNode);

            // Return the now populated previous user (or null if first time through)
            return(prev);
        }