public JsonResult GetAvailableCategories(int?course, int?formId, int?paymentId, int?termId, int?nameId)
        {
            if (selectedUnits == null)
            {
                return(Json(Enumerable.Empty <object>(), JsonRequestBehavior.AllowGet));
            }
            var specialties = new Querier().GetAvailableSpecialties(selectedUnits, course, formId, paymentId, termId, nameId);

            if (specialties == null)
            {
                return(Json(Enumerable.Empty <object>(), JsonRequestBehavior.AllowGet));
            }

            Func <DirectEnrolmentUnit, object> propertySelector = null;
            Func <object, object> newObjectSelector             = (o) => new
            {
                fullName  = ((dynamic)o).FullName,
                shortName = ((dynamic)o).ShortName,
                id        = ((dynamic)o).Id
            };

            if (course == null || course == 0)
            {
                return(GetCourses());
            }
            else if (formId == null || formId == 0)
            {
                propertySelector = (u) => u.EducationForm;
            }
            else if (termId == null || termId == 0)
            {
                propertySelector = (u) => u.EducationTerm;
            }
            else if (paymentId == null || paymentId == 0)
            {
                propertySelector = (u) => u.EducationPayment;
            }
            else if (nameId == null || nameId == 0)
            {
                propertySelector  = (u) => u.GovernmentSpecialty;
                newObjectSelector = (n) => new
                {
                    fullName      = ((GovernmentSpecialty)n).FullName,
                    shortName     = ((GovernmentSpecialty)n).ShortName,
                    id            = ((GovernmentSpecialty)n).Id,
                    qualification = ((GovernmentSpecialty)n).Qualification
                };
            }
            else
            {
                return(Json(specialties.Select(selector), JsonRequestBehavior.AllowGet));
            }

            var categories = specialties.Select(propertySelector).Distinct();

            return(Json(categories.Select(newObjectSelector), JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetGroupedSpecialties(int groupId)
        {
            var specialties = new Querier().GetGroupedSpecialties(groupId);

            return(Json(specialties == null ? Enumerable.Empty <object>() : specialties.Select(selector), JsonRequestBehavior.AllowGet));
        }