LibiadaWeb.Helpers.ViewDataHelper.GetCharacteristicTypes C# (CSharp) Method

GetCharacteristicTypes() public method

Gets characteristics types.
public GetCharacteristicTypes ( bool>.Func filter ) : List
filter bool>.Func /// The filter. ///
return List
        public List<CharacteristicData> GetCharacteristicTypes(Func<CharacteristicType, bool> filter)
        {
            var characteristicTypes = db.CharacteristicType.Include(c => c.CharacteristicTypeLink).Where(filter).OrderBy(c => c.Name)
                .Select(c => new CharacteristicData(c.Id, c.Name, c.CharacteristicTypeLink.OrderBy(ctl => ctl.LinkId).Select(ctl => new CharacteristicLinkData(ctl.Id)).ToList())).ToList();

            var links = UserHelper.IsAdmin() ? EnumExtensions.ToArray<Link>() : new[] { Link.NotApplied, Link.Start, Link.Cycle };

            var characteristicTypeLinks = characteristicTypeLinkRepository.CharacteristicTypeLinks;

            var linksData = links.Select(l => new
                                                {
                                                    Value = (int)l,
                                                    Text = l.GetDisplayValue(),
                                                    CharacteristicTypeLink = characteristicTypeLinks.Where(ctl => ctl.LinkId == (int)l).Select(ctl => ctl.Id)
                                                });

            foreach (var characteristicType in characteristicTypes)
            {
                for (int i = 0; i < characteristicType.CharacteristicLinks.Count; i++)
                {
                    var characteristicLink = characteristicType.CharacteristicLinks[i];
                    foreach (var link in linksData)
                    {
                        if (link.CharacteristicTypeLink.Contains(characteristicLink.CharacteristicTypeLinkId))
                        {
                            characteristicLink.Value = link.Value.ToString();
                            characteristicLink.Text = link.Text;
                            break;
                        }
                    }

                    if (string.IsNullOrEmpty(characteristicLink.Value))
                    {
                        characteristicType.CharacteristicLinks.Remove(characteristicLink);
                        i--;
                    }
                }
            }

            return characteristicTypes;
        }

Usage Example

        /// <summary>
        /// The index.
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Index()
        {
            var db = new LibiadaWebEntities();
            var viewDataHelper = new ViewDataHelper(db);

            Func<CharacteristicType, bool> filter;
            if (UserHelper.IsAdmin())
            {
                filter = c => c.FullSequenceApplicable;
            }
            else
            {
                filter = c => c.FullSequenceApplicable && Aliases.UserAvailableCharacteristics.Contains((Aliases.CharacteristicType)c.Id);
            }

            var data = new Dictionary<string, object>
                {
                    { "characteristicTypes", viewDataHelper.GetCharacteristicTypes(filter) }
                };

            var transformationLinks = new[] { Link.Start, Link.End, Link.CycleStart, Link.CycleEnd };
            transformationLinks = transformationLinks.OrderBy(n => (int)n).ToArray();
            data.Add("transformationLinks", transformationLinks.ToSelectList());

            var operations = new List<SelectListItem> { new SelectListItem { Text = "Dissimilar", Value = 1.ToString() }, new SelectListItem { Text = "Higher order", Value = 2.ToString() } };
            data.Add("operations", operations);

            ViewBag.data = JsonConvert.SerializeObject(data);
            return View();
        }
All Usage Examples Of LibiadaWeb.Helpers.ViewDataHelper::GetCharacteristicTypes