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));
        }
        public async Task <ActionResult> SearchByKeyword(FormCollection collection, bool?useCache)
        {
            var model = new SearchByKeywordViewModel();

            var clear = FormCollectionHelper.IsFormButtonSelected("ClearButton", "Clear", collection);

            if (useCache != null && useCache == true)
            {
                GetSelectByKeywordSessionVariables(model);

                return(View(model));
            }

            RemoveSelectByKeywordSessionVariables();

            if (clear)
            {
                SetSearchedValues(model, collection, true);

                return(View(model));
            }

            using (var context = new IndustryCodesContext())
            {
                SetSearchedValues(model, collection, false);

                if (!string.IsNullOrEmpty(model.Keyword))
                {
                    model.SearchResults = await FindByKeyword(context, model.Keyword, model.SearchNAICS);
                }

                SetSelectByKeywordSessionVariables(model);
            }

            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> SearchBySelection(FormCollection collection)
        {
            var model = new SearchBySelectionViewModel();

            using (var context = new IndustryCodesContext())
            {
                if (FormCollectionHelper.IsFormButtonSelected("ClearButton", "Clear", collection))
                {
                    industrySectors = await GetIndustrySectors(context);

                    model.IndustrySectors        = new SelectList(industrySectors, "Code", "Description");
                    model.SelectedIndustrySector = 0;

                    model.IndustrySubsectors        = new SelectList(new Collection <IndustrySubsector>(), "Code", "Description");
                    model.SelectedIndustrySubsector = 0;

                    model.NAICSDescriptions        = new SelectList(new Collection <NAICSDescription>(), "Code", "Description");
                    model.SelectedNAICSDescription = 0;

                    sicDescriptions = await GetSICDescriptions(context, null);

                    model.SICDescriptions        = new SelectList(new Collection <SICDescription>(), "Code", "Description");
                    model.SelectedSICDescription = 0;

                    SetSelectionSessionVariables();

                    return(View(model));
                }

                GetSelectionSessionVariables();

                industrySectors = await GetIndustrySectors(context);

                selectedIndustrySector = FormCollectionHelper.GetFormNumberValue("SelectedIndustrySector", collection);

                model.IndustrySectors        = new SelectList(industrySectors, "Code", "Description");
                model.SelectedIndustrySector = selectedIndustrySector;

                if (selectedIndustrySector != previousSelectedIndustrySector)
                {
                    industrySubsectors = await GetIndustrySubsectors(context);

                    model.IndustrySubsectors        = new SelectList(industrySubsectors, "Code", "Description");
                    model.SelectedIndustrySubsector = selectedIndustrySubsector;

                    naicsDescriptions = await GetNAICSDescriptions(context);

                    model.NAICSDescriptions        = new SelectList(naicsDescriptions, "Code", "Description");
                    model.SelectedNAICSDescription = selectedNAICSDescription;

                    sicDescriptions = await GetSICDescriptions(context, null);

                    model.SICDescriptions        = new SelectList(sicDescriptions, "Code", "Description");
                    model.SelectedSICDescription = selectedSICDescription;

                    SetSelectionSessionVariables();

                    return(View(model));
                }

                industrySubsectors = await GetIndustrySubsectors(context);

                selectedIndustrySubsector = FormCollectionHelper.GetFormNumberValue("SelectedIndustrySubsector", collection);

                model.IndustrySubsectors        = new SelectList(industrySubsectors, "Code", "Description");
                model.SelectedIndustrySubsector = selectedIndustrySubsector;

                if (selectedIndustrySubsector != previousSelectedIndustrySubsector)
                {
                    naicsDescriptions = await GetNAICSDescriptions(context);

                    model.NAICSDescriptions        = new SelectList(naicsDescriptions, "Code", "Description");
                    model.SelectedNAICSDescription = selectedNAICSDescription;

                    sicDescriptions = await GetSICDescriptions(context, null);

                    model.SICDescriptions        = new SelectList(sicDescriptions, "Code", "Description");
                    model.SelectedSICDescription = selectedSICDescription;

                    SetSelectionSessionVariables();

                    return(View(model));
                }

                naicsDescriptions = await GetNAICSDescriptions(context);

                selectedNAICSDescription = FormCollectionHelper.GetFormNumberValue("SelectedNAICSDescription", collection);

                model.NAICSDescriptions        = new SelectList(naicsDescriptions, "Code", "Description");
                model.SelectedNAICSDescription = selectedNAICSDescription;

                if (selectedNAICSDescription != previousSelectedNAICSDescription)
                {
                    sicDescriptions = await GetSICDescriptions(context, null);

                    model.SICDescriptions        = new SelectList(sicDescriptions, "Code", "Description");
                    model.SelectedSICDescription = selectedSICDescription;

                    SetSelectionSessionVariables();

                    return(View(model));
                }

                sicDescriptions = await GetSICDescriptions(context, null);

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

                model.SICDescriptions        = new SelectList(sicDescriptions, "Code", "Description");
                model.SelectedSICDescription = selectedSICDescription;

                if (selectedNAICSDescription > 0 || selectedSICDescription > 0)
                {
                    model.NAICSCode        = string.Format(CultureInfo.CurrentCulture, "{000000}", selectedNAICSDescription);
                    model.NAICSDescription = await GetNAICSDescription(context, null);

                    model.SICCode        = string.Format(CultureInfo.CurrentCulture, "{0000}", selectedSICDescription);
                    model.SICDescription = await GetSICDescription(context, model.NAICSCode);
                }

                SetSelectionSessionVariables();
            }

            return(View(model));
        }