public void NavigationItemsPropertyTest()
        {
            var item = new NavigationGroupInfo(new NavigationGroupDTO());
            Assert.AreEqual(0, item.NavigationItems.Count);

            var navDTO = new NavigationGroupDTO();
            navDTO.NavigationItems.Add(new NavigationItemDTO { Id = 1, Name = "name", ProcessId = 2 });

            item = new NavigationGroupInfo(navDTO);
            Assert.AreEqual(1, item.NavigationItems.Count);
        }
Example #2
0
        private static List<NavigationGroupDTO> FetchNavigationGroupsOnly(bool isAdmin, IEnumerable<int> personRoles)
        {
            var result = new List<NavigationGroupDTO>();
            var roles = new List<int> { Constants.AllRolesId };
            var where = GetNavigationGroupsFilter(isAdmin, personRoles, roles, false);
            int locId = GetLocIdByCultureName(Thread.CurrentThread.CurrentUICulture.Name);
            const string SqlTemplate = @"
SELECT ng.[Id]
      ,ng.[LastModifiedOn]
      ,ISNULL(ngl.[Name], ng.[Name])
      ,[Sequence]
      ,Icons.[Icon]
      ,ng.[IconId]
      ,SystemName
FROM   [NavigationGroups] ng
       LEFT OUTER JOIN Icons ON  ng.IconId = Icons.Id
       LEFT OUTER JOIN [NavigationGroupLocalizations] ngl ON ngl.NavigationGroupId = ng.Id AND ngl.LocalizationId = {1}
    {0}
ORDER BY Sequence";

            var sql = string.Format(CultureInfo.InvariantCulture, SqlTemplate, where, locId);
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;
                if (cn.State != ConnectionState.Open)
                {
                    cn.Open();
                }

                using (var cmd = new SqlCommand(sql, cn))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var group = new NavigationGroupDTO();
                            group.Name = reader.GetString(2);
                            group.Icon = AdoHelper.ReadImage(reader, 4);
                            group.Id = reader.GetInt32(0);
                            group.SystemName = reader.GetString(6, null);
                            result.Add(group);
                        }
                    }
                }
            }

            return result;
        }
Example #3
0
        /// <summary>
        /// Adds the navigation item.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="currentGroup">The current group.</param>
        private static void AddNavigationItem(SafeDataReader reader, NavigationGroupDTO currentGroup)
        {
            var navItemDto = new NavigationItemDTO
                                 {
                                     Id = reader.GetInt32(5),
                                     Name = reader.GetString(6),
                                     SystemName = reader.GetString(7),
                                     IconId = reader.GetNullableInt(8),
                                     IconUrl = reader.GetString(9),
                                     AssemblyName = reader.GetString(10),
                                     ProcessId = reader.GetNullableInt(11),
                                     ProcessSystemName = reader.GetString(13),
                                     Description = reader.GetString(17)
                                 };
            navItemDto.Description = navItemDto.ProcessId == null ? reader.GetString("HelpText") : reader.GetString(reader.GetOrdinal("Description"));
            navItemDto.BackgroundColor = reader.GetInt64(reader.GetOrdinal("BackgroundColor"));
            navItemDto.ProcessViewGuid = reader.GetNullableGuid(reader.GetOrdinal("ProcessViewGuid"));
            navItemDto.IsSystem = reader.GetNullableBool(reader.GetOrdinal("IsSystem"));
            navItemDto.IsBeta = reader.GetBoolean(reader.GetOrdinal("IsBeta"));
            var processName = reader.GetString(12);

            if (!string.IsNullOrEmpty(processName))
                navItemDto.Name = processName;

            currentGroup.NavigationItems.Add(navItemDto);
        }
Example #4
0
        /// <summary>
        /// Fetches the navigation groups with items.
        /// </summary>
        /// <param name="isAdmin">if set to <c>true</c> [is admin].</param>
        /// <param name="personRoles">The person roles.</param>
        /// <returns>List{NavigationGroupDTO}.</returns>
        private static List<NavigationGroupDTO> FetchNavigationGroupsWithItems(bool isAdmin, IEnumerable<int> personRoles)
        {
            var result = new List<NavigationGroupDTO>();

            var licenseInfo = LicenseInfo.GetLicenseInfo();

            var roles = new List<int> { Constants.AllRolesId };

            var whereString = GetNavigationGroupsFilter(isAdmin, personRoles, roles);

            int locId = GetLocIdByCultureName(Thread.CurrentThread.CurrentUICulture.Name);

            const string SqlTemplate = @"
--Admin menu
SELECT
     ng.[Id] AS GroupId
    ,ng.[Name] AS GroupName
    ,ng.[SystemName] AS GroupSystemName
    ,ng.[IconId] AS GroupIconId
    ,ng.[IconURL] AS GroupIconURL
    ,ni.[Id] AS ItemId
    ,ni.[Name] AS ItemName
    ,ni.[SystemName] AS ItemSystemName
    ,NULL AS ItemIconId
    ,ni.[IconURL] AS ItemIconURL
    ,NULL AS AssemblyName
    ,NULL AS ProcessId
    ,NULL
    ,NULL AS SystemName
    ,NULL AS Icon
    ,NULL AS Description
    ,NULL AS BackgroundColor
    ,Description AS HelpText
    ,NULL AS ProcessViewGuid
    ,ng.[Sequence]
    ,ni.[Sequence]
    ,NULL AS IsSystem
    ,ni.[IsBeta]
FROM
    [dbo].[NavigationGroups] ng
    INNER JOIN [dbo].[NavigationItems] ni ON ng.[Id] = ni.[NavigationGroupId]    
WHERE ng.[SystemName] = '{3}'
UNION ALL
--Navigation
SELECT TOP {2}
     ng.[Id] AS GroupId
    ,ISNULL(ngl.[Name], ng.[Name]) AS GroupName
    ,ng.[SystemName] AS GroupSystemName
    ,ng.[IconId] AS GroupIconId
    ,ng.[IconURL] AS GroupIconURL
    ,ni.[Id] AS ItemId
    ,ni.[Name] AS ItemName
    ,ni.[SystemName] AS ItemSystemName
    ,p.[IconId] AS ItemIconId
    ,ni.[IconURL] AS ItemIconURL
    ,pp.[AssemblyName]
    ,pp.[ProcessId]
    ,CASE WHEN (pl.LocalizationId = l.Id AND LEN(pl.ProcessName) > 0) THEN pl.ProcessName ELSE p.[Name] END + 
	 CASE WHEN pv.Name IS NULL THEN '' ELSE ' - ' + 
		CASE WHEN (pvl.LocalizationId = l.Id AND LEN(pvl.Name) > 0) THEN pvl.Name ELSE pv.Name END
     END
    ,p.[SystemName]
    ,i.[Icon]
    ,p.[Description]
    ,c.[Color] AS BackgroundColor
    ,ni.Description AS HelpText
    ,ni.[ProcessViewGuid]
    ,ng.[Sequence]
    ,ni.[Sequence]
    ,p.[IsSystem]
    ,ni.[IsBeta]
FROM
    [dbo].[NavigationGroups] ng
    INNER JOIN [dbo].[NavigationItems] ni ON ng.[Id] = ni.[NavigationGroupId]
    LEFT OUTER JOIN [dbo].[PublishedProcesses] pp ON pp.[Id] = ni.[PublishedProcessId]
    LEFT OUTER JOIN [dbo].[Processes] p ON p.[Id] = pp.[ProcessId]
    LEFT OUTER JOIN [dbo].[Processes] p1 ON p.SystemName = p1.[SystemName] AND p1.IsPublishedCopy = 0 AND p1.IsRemoved = 0
	LEFT OUTER JOIN dbo.Localizations l ON l.CultureName = '{4}'
	LEFT OUTER JOIN dbo.ProcessLocalizations pl ON pl.LocalizationId = l.Id AND p1.Id = pl.ProcessId
    LEFT OUTER JOIN Icons i ON  i.Id = ng.IconId
    LEFT OUTER JOIN Colors c ON c.Id = p.ColorId
    LEFT JOIN [dbo].[ProcessViews] pv ON pv.[Guid] = ni.ProcessViewGuid AND pv.ProcessId = p.Id
    LEFT JOIN [dbo].[ProcessViews] pv1 ON pv1.[Guid] = pv.Guid AND pv1.ProcessId = p1.Id
	LEFT OUTER JOIN dbo.ProcessViewLocalizations pvl ON pv1.Id = pvl.ProcessViewId
	LEFT JOIN [dbo].[NavigationGroupSecurityConfigurations] ngsc ON (ngsc.NavigationGroupId = ng.Id AND ngsc.RoleId = {0})
	LEFT JOIN [dbo].[NavigationItemSecurityConfigurations] nisc ON (nisc.NavigationItemId = ni.Id AND nisc.RoleId = {0})
	LEFT OUTER JOIN dbo.NavigationGroupLocalizations ngl ON ngl.NavigationGroupId = ng.Id AND ngl.LocalizationId = {5}
{1}
ORDER BY
     ng.[Sequence]
    ,ni.[Sequence]";

            var sql = string.Format(
                CultureInfo.InvariantCulture, 
                SqlTemplate,
                roles.Count > 1 ? roles[1] : roles[0], 
                whereString, 
                licenseInfo == null ? 0 : licenseInfo.Processes, 
                Constants.AdminMenu, 
                Thread.CurrentThread.CurrentUICulture.Name,
                locId);

            Database.GetDataReader(
                sql, 
                reader =>
                {
                    if (reader == null) return;
                    
                    var groupId = -1;
                    NavigationGroupDTO currentGroup = null;

                    using (var safeReader = new SafeDataReader(reader))
                    {
                        while (safeReader.Read())
                        {
                            var newGroupId = safeReader.GetInt32(0);
                            if (newGroupId == groupId && currentGroup != null)
                            {
                                AddNavigationItem(safeReader, currentGroup);
                            }
                            else // Make New group
                            {
                                var group = result.FirstOrDefault(g => g.Id == newGroupId);

                                if (group == null)
                                {
                                    group = new NavigationGroupDTO
                                    {
                                        Id = newGroupId,
                                        Name = safeReader.GetString(1),
                                        SystemName = safeReader.GetString(2),
                                        IconId = safeReader.GetNullableInt(3),
                                        IconURL = safeReader.GetString(4),
                                        Icon = AdoHelper.ReadImage(reader, 14)
                                    };
                                    
                                    result.Add(group);
                                }
                                
                                currentGroup = group;
                                AddNavigationItem(safeReader, currentGroup);
                                
                                groupId = newGroupId;
                            }
                        }
                    }
                });

            return result;
        }
            public IEnumerable<NavigationGroupDTO> FetchNavigationGroups(bool withItems)
            {
                var result = new List<NavigationGroupDTO>();
                var dto = new NavigationGroupDTO() {Id = 2, Name = "GroupTest", Icon = new byte[] {}};
                if (withItems)
                {
                    dto.NavigationItems.Add(new NavigationItemDTO(1, "test", 0));
                    dto.NavigationItems.Add(new NavigationItemDTO(1, "test", 0));
                    dto.NavigationItems.Add(new Mock<INavigationItemDTO>().Object);
                }

                result.Add(dto);
                return result;
            }