public ActionResult RelatedCode(string text, int page, string code, string dependentValue, bool dominant, AdwOrderType orderType, AdwDisplayType displayType, IEnumerable <string> excludeValues)
        {
            var result = Enumerable.Empty <SelectListItem>();

            if (!string.IsNullOrEmpty(code))
            {
                result = AdwService.GetRelatedCodes(code, dependentValue, dominant).ToOrderedSelectListItem(orderType, displayType).Where(m => excludeValues == null || !excludeValues.Contains(m.Value));
            }

            return(AjaxSelectionView(text, page, result));
        }
        /// <summary>
        /// Returns the Adw codes as a <see cref="IEnumerable{SelectListItem}" />.
        /// </summary>
        /// <param name="container">The model this object is contained within.</param>
        /// <param name="selectedCodes">The code values that are selected.</param>
        /// <returns>A <see cref="IEnumerable{SelectListItem}" />.</returns>
        public IEnumerable <SelectListItem> GetSelectListItems(object container, object selectedCodes)
        {
#if DEBUG
            var step = MiniProfiler.Current.Step(string.Format("AdwSelection.GetSelectListItems ({0})", Code));

            try
            {
#endif
            if (AdwType == AdwType.RelatedCode)
            {
                IList <RelatedCodeModel> relatedCodes;

                if (!string.IsNullOrEmpty(DependentProperty))
                {
                    var dependentPropertyValue = HandleEnumerableSelectListItem(GetDependentPropertyValue(container));

                    if (dependentPropertyValue == null || string.IsNullOrEmpty(dependentPropertyValue.ToString()))
                    {
                        return(Enumerable.Empty <SelectListItem>());
                    }

                    relatedCodes = AdwService.GetRelatedCodes(Code, dependentPropertyValue.ToString(), Dominant, CurrentCodesOnly);
                }
                else
                {
                    relatedCodes = AdwService.GetRelatedCodes(Code, DependentValue, Dominant, CurrentCodesOnly);
                }

                return(relatedCodes.ToOrderedSelectListItem(OrderType, DisplayType, selectedCodes).Where(m => ExcludeValues == null || !ExcludeValues.Contains(m.Value)));
            }

            var listCodes = AdwService.GetListCodes(Code, CurrentCodesOnly);

            return(listCodes.ToOrderedSelectListItem(OrderType, DisplayType, selectedCodes).Where(m => ExcludeValues == null || !ExcludeValues.Contains(m.Value)));

#if DEBUG
        }

        finally
        {
            if (step != null)
            {
                step.Dispose();
            }
        }
#endif
        }
示例#3
0
        /// <summary>
        /// Validates that the text does not contain any blue words.
        /// </summary>
        /// <param name="displayName">The display name of the property to include in the error message.</param>
        /// <param name="text">The text to validate for blue words.</param>
        /// <returns>The validation result of success if no blue words were found; otherwise, a validation result with an error message.</returns>
        internal ValidationResult ValidateBlueWord(string displayName, string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                var blueWords = new List <string>();

                // Get unacceptable words
                var unacceptableWords = AdwService.GetRelatedCodes("OFTW", "UNA").ToCodeModelList().Select(a => Regex.Escape(a.Description)).ToList();

                // Get identified words that contain unacceptable words but are identified as being allowed
                var identifiedWords = AdwService.GetRelatedCodes("OFTW", "IDE").ToCodeModelList().Select(a => Regex.Escape(a.Description)).ToList();

                // Build word boundary pattern to match against identified words (the full word must match)
                var identifiedWordsPattern = string.Format(@"\b({0})\b", string.Join("|", identifiedWords));

                // Remove identified words from text so we can ignore them as they are allowed
                text = Regex.Replace(text, identifiedWordsPattern, " ", (RegexOptions.IgnoreCase | RegexOptions.Singleline));

                // Build word boundary pattern to match against unacceptable words (any words containing an unacceptable word will be matched)
                var unacceptableWordsPattern = string.Format("({0})", string.Join("|", unacceptableWords));

                // Get unacceptable word matches
                var matches = Regex.Matches(text, unacceptableWordsPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);

                foreach (Match match in matches)
                {
                    if (!blueWords.Contains(match.Value))
                    {
                        blueWords.Add(match.Value);
                    }
                }

                if (blueWords.Any())
                {
                    return(new ValidationResult(FormatErrorMessage(displayName, blueWords)));
                }
            }

            return(ValidationResult.Success);
        }
        public JsonResult GetOccupationLevel3(string text, int page, string occupationLevel2)
        {
            var result = AdwService.GetRelatedCodes("AZ24", occupationLevel2, true).ToCodeModelList().ToSelectList(m => m.Code, m => m.Description);

            return(AjaxSelectionView(text, page, result));
        }
        public JsonResult GetPostcode(string text, int page, string state)
        {
            var result = AdwService.GetRelatedCodes("STPC", state, true).ToCodeModelList().ToSelectList(m => m.Code, m => m.Description);

            return(AjaxSelectionView(text, page, result));
        }
        public JsonResult GetLocality(string text, int page, string postcode)
        {
            var result = AdwService.GetRelatedCodes("LPCC", postcode, true).ToCodeModelList().ToSelectList(m => m.Description, m => m.Description);

            return(AjaxSelectionView(text, page, result));
        }