private List <Activities> GetSortedList(int startSortingAt, List <Activities> activitiesList, SortType sortType)
        {
            var baseList = activitiesList;

            if (startSortingAt == 0)
            {
                if (sortType == SortType.Ascending)
                {
                    baseList = baseList.OrderBy(x => x.ActivityDescription).ToList();
                }
                if (sortType == SortType.Descending)
                {
                    baseList = baseList.OrderByDescending(x => x.ActivityDescription).ToList();
                }
                foreach (var child in baseList)
                {
                    SortList(sortType, child);
                }
            }
            else
            {
                var lookingFor = baseList.Select(item => Activities.Find(item, startSortingAt)).FirstOrDefault(activity => activity != null);
                SortList(sortType, lookingFor);
            }

            return(baseList);
        }
        private SelectList GetCategories(int currentId, out int parentActivityId)
        {
            var dbCtxt         = new ActivitiesDbCtxt();
            var activitiesList = CreateStructure(0, dbCtxt.Activities.ToList());
            var lookingFor     = activitiesList.Select(item => Activities.Find(item, currentId)).FirstOrDefault(activity => activity != null);
            var parent         = activitiesList.Select(item => Activities.Find(item, lookingFor.ParentActivityID)).FirstOrDefault(activity => activity != null);

            if (parent != null)
            {
                parent.ChildActivities.Remove(lookingFor);
            }
            else
            {
                activitiesList.Remove(lookingFor);
            }
            var childList  = GetAllChilds(activitiesList);
            var categories = childList.Select(x => new SelectListItem
            {
                Value = x.ActivityID.ToString(),
                Text  = x.DisplayAsCategory
            });

            var            list = categories.ToList();
            SelectListItem selected;

            if (parent != null)
            {
                selected = (from category in list
                            where category.Value == parent.ActivityID.ToString()
                            select category).First();
            }
            else
            {
                selected = null;
            }

            if (selected != null)
            {
                selected.Selected = true;
                list.Insert(0, new SelectListItem {
                    Value = "0", Text = "No parent category"
                });
                parentActivityId = int.Parse(selected.Value);
            }
            else
            {
                list.Insert(0, new SelectListItem {
                    Value = "0", Text = "No parent category", Selected = true
                });
                parentActivityId = 0;
            }

            return(new SelectList(list, "Value", "Text"));
        }