private static void SetSearchedValues(SearchByKeywordViewModel model, FormCollection collection, bool optionOnly)
        {
            if (!optionOnly)
            {
                model.Keyword = FormCollectionHelper.GetFormStringValue("Keyword", collection);
            }

            var keywordOption = FormCollectionHelper.GetFormRadioButtonValue("KeywordOption", collection);

            if (!string.IsNullOrEmpty(keywordOption))
            {
                if (keywordOption.Equals("NAICS"))
                {
                    model.SearchNAICS = true;
                }
                if (keywordOption.Equals("SIC"))
                {
                    model.SearchSIC = true;
                }
            }

            if (model.SearchNAICS == false && model.SearchSIC == false)
            {
                model.SearchNAICS = true;
            }
        }
        public async Task <ActionResult> SearchByCode(FormCollection collection)
        {
            var model = new SearchByCodeViewModel();

            if (FormCollectionHelper.IsFormButtonSelected("ClearButton", "Clear", collection))
            {
                return(View(model));
            }

            model.NAICSCode        = FormCollectionHelper.GetFormStringValue("NAICSCode", collection);
            model.NAICSDescription = FormCollectionHelper.GetFormStringValue("NAICSDescription", collection);

            using (var context = new IndustryCodesContext())
            {
                if (FormCollectionHelper.IsFormButtonSelected("SearchButton", "Search", collection))
                {
                    model.NAICSDescription = await GetNAICSDescription(context, model.NAICSCode);

                    if (model.NAICSDescription == null)
                    {
                        ModelState.AddModelError("ErrorMessage", string.Format(CultureInfo.CurrentCulture, "Unable to locate description for given NAICS code: {0}", model.NAICSCode));

                        model.NAICSCode = null;

                        return(View(model));
                    }
                }

                sicDescriptions = await GetSICDescriptions(context, model.NAICSCode);

                selectedSICDescription = FormCollectionHelper.GetFormNumberValue("SelectedSICDescription", collection);

                if (sicDescriptions != null)
                {
                    model.SICDescriptions = new SelectList(sicDescriptions, "Code", "Description");
                }

                if (selectedSICDescription > 0)
                {
                    model.SelectedSICDescription = selectedSICDescription;
                }

                if (selectedSICDescription > 0)
                {
                    model.SICCode = string.Format(CultureInfo.CurrentCulture, "{0000}", selectedSICDescription);
                }

                if (selectedSICDescription > 0)
                {
                    model.SICDescription = GetSICDescription();
                }
            }

            return(View(model));
        }