Ejemplo n.º 1
0
        private SelectListGroup GetGroup(object container, HashSet <string> disabledGroups)
        {
            if (_groups == null)
            {
                return(null);
            }

            string groupName = Eval(container, DataGroupField);

            if (String.IsNullOrEmpty(groupName))
            {
                return(null);
            }

            // We use StringComparison.CurrentCulture because the group name is used to display as the value of
            // optgroup HTML tag's label attribute.
            SelectListGroup group = _groups.FirstOrDefault(
                g => String.Equals(g.Name, groupName, StringComparison.CurrentCulture)
                );

            if (group == null)
            {
                group = new SelectListGroup()
                {
                    Name     = groupName,
                    Disabled = disabledGroups.Contains(groupName)
                };
                _groups.Add(group);
            }

            return(group);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Extension method for generating <see cref="SelectListItem"/>s out of all the
        ///     passed countries' provinces
        /// </summary>
        /// <param name="countries">
        ///     The <see cref="IEnumerable{T}"/> of <see cref="Country"/> to generate province
        ///     SelectListItems for
        /// </param>
        /// <returns>
        ///     <see cref="IEnumerable{T}"/> of <see cref="SelectListItem"/> for all the provinces
        /// </returns>
        public static IEnumerable<SelectListItem> GetProvinceItems(this IEnumerable<Country> countries)
        {
            foreach (Country country in countries)
            {
                var currentGroup = new SelectListGroup
                {
                    Name = country.CountryName
                };

                foreach (var province in country.Provinces)
                {
                    yield return new SelectListItem
                    {
                        Text = province.Name,
                        Value = province.ProvinceCode,
                        Group = currentGroup
                    };
                }
            }
        }
Ejemplo n.º 3
0
        public static IEnumerable<SelectListItem> ProductFileListForModel(this HtmlHelper htmlHelper, string searchPattern = "*.*", bool filterForImages = false, bool filterForAudio = false)
        {
            string selectedFileName = (htmlHelper.ViewData.Model as string ?? "").ToLower();

            StoreFront storeFront = htmlHelper.CurrentStoreFront(true);
            Client client = storeFront.Client;

            HttpContextBase http = htmlHelper.ViewContext.RequestContext.HttpContext;

            string storeFrontVirtualPath = storeFront.CatalogProductContentVirtualDirectoryToMap(http.Request.ApplicationPath);
            string storeFrontFolderPath = http.Server.MapPath(storeFrontVirtualPath);
            List<SelectListItem> storeFrontListItems = new List<SelectListItem>();
            if (System.IO.Directory.Exists(storeFrontFolderPath))
            {
                DirectoryInfo storeFrontFolder = new System.IO.DirectoryInfo(storeFrontFolderPath);
                List<FileInfo> storeFrontFiles = storeFrontFolder.GetFiles(searchPattern).ToList();
                if (filterForImages && filterForAudio)
                {
                    storeFrontFiles = storeFrontFiles.Where(f => f.Name.FileExtensionIsImage() || f.Name.FileExtensionIsAudio()).ToList();
                }
                else if (filterForImages)
                {
                    storeFrontFiles = storeFrontFiles.Where(f => f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForAudio)
                {
                    storeFrontFiles = storeFrontFiles.Where(f => f.Name.FileExtensionIsAudio()).ToList();
                }

                SelectListGroup storeFrontGroup = new SelectListGroup() { Name = "Store Front" };
                storeFrontListItems = storeFrontFiles.Select(fil =>
                    new SelectListItem()
                    {
                        Value = fil.Name,
                        Text = fil.Name + (fil.Name.ToLower() == selectedFileName ? " [SELECTED]" : "") + " " + fil.Length.ToByteString(),
                        Selected = fil.Name.ToLower() == selectedFileName,
                        Group = storeFrontGroup
                    }).ToList();
            }

            string clientVirtualPath = client.CatalogProductContentVirtualDirectoryToMap(http.Request.ApplicationPath);
            string clientFolderPath = http.Server.MapPath(clientVirtualPath);
            List<SelectListItem> clientListItems = new List<SelectListItem>();
            if (System.IO.Directory.Exists(clientFolderPath))
            {
                DirectoryInfo clientFolder = new System.IO.DirectoryInfo(clientFolderPath);
                List<FileInfo> clientFiles = clientFolder.EnumerateFiles(searchPattern).ToList();
                if (filterForAudio && filterForImages)
                {
                    clientFiles = clientFiles.Where(f => f.Name.FileExtensionIsAudio() || f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForImages)
                {
                    clientFiles = clientFiles.Where(f => f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForAudio)
                {
                    clientFiles = clientFiles.Where(f => f.Name.FileExtensionIsAudio()).ToList();
                }

                SelectListGroup clientGroup = new SelectListGroup() { Name = "Client" };
                clientListItems = clientFiles.Select(fil =>
                    new SelectListItem()
                    {
                        Value = fil.Name,
                        Text = fil.Name + (fil.Name.ToLower() == selectedFileName ? " [SELECTED]" : "") + " " + fil.Length.ToByteString(),
                        Selected = fil.Name.ToLower() == selectedFileName,
                        Group = clientGroup
                    }).ToList();
            }

            string serverVirtualPath = "~/Content/Server/CatalogContent/Products";
            string serverFolderPath = http.Server.MapPath(serverVirtualPath);
            List<SelectListItem> serverListItems = new List<SelectListItem>();
            if (System.IO.Directory.Exists(serverFolderPath))
            {
                DirectoryInfo serverFolder = new System.IO.DirectoryInfo(serverFolderPath);
                List<FileInfo> serverFiles = serverFolder.EnumerateFiles(searchPattern).ToList();
                if (filterForAudio && filterForImages)
                {
                    serverFiles = serverFiles.Where(f => f.Name.FileExtensionIsAudio() || f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForImages)
                {
                    serverFiles = serverFiles.Where(f => f.Name.FileExtensionIsImage()).ToList();
                }
                else if (filterForAudio)
                {
                    serverFiles = serverFiles.Where(f => f.Name.FileExtensionIsAudio()).ToList();
                }

                SelectListGroup serverGroup = new SelectListGroup() { Name = "GStore Files" };
                serverListItems = serverFiles.Select(fil =>
                    new SelectListItem()
                    {
                        Value = fil.Name,
                        Text = fil.Name + (fil.Name.ToLower() == selectedFileName ? " [SELECTED]" : "") + " " + fil.Length.ToByteString(),
                        Selected = fil.Name.ToLower() == selectedFileName,
                        Group = serverGroup
                    }).ToList();
            }

            return storeFrontListItems.Concat(clientListItems).Concat(serverListItems);
        }
		/// <summary>
		///    Erzeugt die Auswahlliste für die Besitzer. Da in #83 auch Gruppen auswählbar sein sollen, werden diese kombiniert.
		///    Einzelnbenutzer sind durch einen positiven Wert gekennzeichnet. Dies ist die UserID. Gruppen werden durch einen
		///    negativen Wert beschrieben, der die negierte Sitzungstypus-ID ist. Werte von 0 sind für beide IDs ungültig und
		///    sollten daher nie vorkommen. Die Unterscheidung innerhelb der GUI erfolgt über die Gruppen in dem Dropdown Menü.
		/// </summary>
		/// <returns>Eine Liste, in der Einzelbenutzer und Benutzergruppen enthalten sind.</returns>
		private List<SelectListItem> CreateOwnerSelectListitems()
		{
			var usergroup = new SelectListGroup {Name = "Benutzer"};
			var groupsgroup = new SelectListGroup {Name = "Gruppen"};

			var listitems = db.GetUserOrdered(GetCurrentUser()).Select(u => new SelectListItem
			{
				Text = u.ShortName,
				Value = u.ID.ToString(),
				Group = usergroup
			}).Concat(db.GetActiveSessionTypes().Select(x => new SelectListItem
			{
				Text = x.Name,
				Value = (-x.ID).ToString(),
				Group = groupsgroup
			})).ToList();
			return listitems;
		}