Beispiel #1
0
        private async Task <IEnumerable <SICDescription> > GetSICDescriptions(IndustryCodesContext context, string naicsCode)
        {
            var list = new Collection <SICDescription>();

            if (string.IsNullOrEmpty(naicsCode) && selectedNAICSDescription <= 0)
            {
                return(list);
            }

            var naicsCodeOrIndex = !string.IsNullOrEmpty(naicsCode) ? Assistant.GetNumberValue(naicsCode) : selectedNAICSDescription;

            list.Add(new SICDescription {
                Code = defaultSelectionValue, Description = defaultSelectionText
            });

            var results = await context.ClassificationCodes.Where(c => c.NORTH_AMERICAN_CODE == naicsCodeOrIndex)
                          .Select(c => new { code = c.STANDARD_CODE, description = c.STANDARD_DESCRIPTION })
                          .ToListAsync();

            foreach (var result in results)
            {
                if (result.code == null || result.description == null)
                {
                    continue;
                }

                var index   = Convert.ToInt32(result.code, CultureInfo.CurrentCulture);
                var element = result.code + " - " + result.description;

                list.Add(new SICDescription {
                    Code = index, Description = element
                });
            }
            return(list);
        }
Beispiel #2
0
        private async Task <IEnumerable <IndustrySubsector> > GetIndustrySubsectors(IndustryCodesContext context)
        {
            var list = new Collection <IndustrySubsector>();

            if (selectedIndustrySector < 1)
            {
                return(list);
            }

            list.Add(new IndustrySubsector {
                Code = defaultSelectionValue, Description = defaultSelectionText
            });

            var industrySector = await GetIndustrySector(context);

            var results = await context.ClassificationCodes
                          .Where(c => c.INDUSTRY_SECTOR == industrySector)
                          .Select(c => c.INDUSTRY_SUBSECTOR)
                          .Distinct()
                          .OrderBy(description => description)
                          .ToListAsync();

            var index = 0;

            foreach (var result in results)
            {
                list.Add(new IndustrySubsector {
                    Code = ++index, Description = result
                });
            }
            return(list);
        }
        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));
        }
Beispiel #4
0
        private async Task <string> GetNAICSDescription(IndustryCodesContext context, string naicsCode)
        {
            if (string.IsNullOrEmpty(naicsCode) && selectedNAICSDescription <= 0)
            {
                return(null);
            }

            var naicsCodeOrIndex = !string.IsNullOrEmpty(naicsCode) ? Assistant.GetNumberValue(naicsCode) : selectedNAICSDescription;

            var results = context.ClassificationCodes
                          .Where(c => c.NORTH_AMERICAN_CODE == naicsCodeOrIndex)
                          .Select(c => c.NORTH_AMERICAN_DESCRIPTION).Distinct();

            return(await results.CountAsync() == 1 ? results.Single() : null);
        }
Beispiel #5
0
        private async Task <string> GetIndustrySubsector(IndustryCodesContext context)
        {
            var industrySector = await GetIndustrySector(context);

            var results = await context.ClassificationCodes
                          .Where(c => c.INDUSTRY_SECTOR == industrySector)
                          .Select(c => c.INDUSTRY_SUBSECTOR)
                          .Distinct()
                          .OrderBy(description => description)
                          .ToListAsync();

            var index = 0;

            return(results.FirstOrDefault(description => selectedIndustrySubsector == ++index));
        }
        private static async Task <string> GetNAICSDescription(IndustryCodesContext context, string naicsCodeParameter)
        {
            if (string.IsNullOrEmpty(naicsCodeParameter))
            {
                return(null);
            }

            var naicsCode = Assistant.GetNumberValue(naicsCodeParameter);

            var results = await context.ClassificationCodes
                          .Where(c => c.NORTH_AMERICAN_CODE == naicsCode)
                          .Select(c => c.NORTH_AMERICAN_DESCRIPTION)
                          .Distinct()
                          .ToListAsync();

            return(results.Count() == 1 ? results.Single() : null);
        }
Beispiel #7
0
        private async Task <string> GetSICDescription(IndustryCodesContext context, string naicsCodeParameter)
        {
            if (selectedSICDescription < 1)
            {
                return(null);
            }

            var naicsCode = Assistant.GetNumberValue(naicsCodeParameter);

            var sicCode = selectedSICDescription;

            var results = context.ClassificationCodes
                          .Where(c => c.NORTH_AMERICAN_CODE == naicsCode && c.STANDARD_CODE == sicCode)
                          .Select(c => new { description = c.STANDARD_DESCRIPTION });

            return(await results.CountAsync() == 1 ? results.Single().description : null);
        }
        private static async Task <List <ClassificationCode> > FindByKeyword(IndustryCodesContext context, string keyword, bool searchNAICS)
        {
            if (searchNAICS)
            {
                var results = context.ClassificationCodes
                              .Where(c => c.NORTH_AMERICAN_DESCRIPTION.Contains(keyword))
                              .Select(c => c);

                return(await results.ToListAsync());
            }
            else
            {
                var results = context.ClassificationCodes
                              .Where(c => c.STANDARD_DESCRIPTION.Contains(keyword))
                              .Select(c => c);

                return(await results.ToListAsync());
            }
        }
Beispiel #9
0
        private async Task <string> GetIndustrySector(IndustryCodesContext context)
        {
            var results = await context.ClassificationCodes
                          .Select(c => c.INDUSTRY_SECTOR)
                          .Distinct()
                          .OrderBy(description => description)
                          .ToListAsync();

            var index = 0;

            foreach (var result in results)
            {
                if (selectedIndustrySector == ++index)
                {
                    return(result);
                }
            }
            return(null);
        }
        public async Task <ActionResult> SearchDetail(string id)
        {
            var model = new SearchDetailViewModel();

            using (var context = new IndustryCodesContext())
            {
                var classificationCode = await FindByIdentifier(context, id);

                if (classificationCode != null)
                {
                    model.NAICSCode        = string.Format(CultureInfo.CurrentCulture, "{000000}", Convert.ToString(classificationCode.NORTH_AMERICAN_CODE, CultureInfo.CurrentCulture));
                    model.NAICSDescription = classificationCode.NORTH_AMERICAN_DESCRIPTION;
                    model.SICCode          = string.Format(CultureInfo.CurrentCulture, "{0000}", classificationCode.STANDARD_CODE);
                    model.SICDescription   = classificationCode.STANDARD_DESCRIPTION;
                }
                else
                {
                    ModelState.AddModelError("ErrorMessage", string.Format(CultureInfo.CurrentCulture, "Unable to locate record for given identifier: {0}", id));
                }
            }

            return(View(model));
        }
Beispiel #11
0
        private async Task <IEnumerable <NAICSDescription> > GetNAICSDescriptions(IndustryCodesContext context)
        {
            var list = new Collection <NAICSDescription>();

            if (selectedIndustrySubsector < 1)
            {
                return(list);
            }

            list.Add(new NAICSDescription {
                Code = defaultSelectionValue, Description = defaultSelectionText
            });

            var industrySubsector = await GetIndustrySubsector(context);

            var results = await context.ClassificationCodes
                          .Where(c => c.INDUSTRY_SUBSECTOR == industrySubsector)
                          .Select(c => new { code = c.NORTH_AMERICAN_CODE, description = c.NORTH_AMERICAN_DESCRIPTION })
                          .Distinct()
                          .ToListAsync();

            foreach (var result in results)
            {
                if (result.code == null || result.description == null)
                {
                    continue;
                }

                var index = Convert.ToInt32(result.code, CultureInfo.CurrentCulture);
                var name  = result.code + " - " + result.description;

                list.Add(new NAICSDescription {
                    Code = index, Description = name
                });
            }
            return(list);
        }
        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));
        }
 public SearchDetailModel(IndustryCodesContext industryCodesContext)
 {
     context = industryCodesContext ?? throw new ArgumentNullException(nameof(industryCodesContext));
 }
        private static async Task <ClassificationCode> FindByIdentifier(IndustryCodesContext context, string identifier)
        {
            var id = Assistant.GetNumberValue(identifier);

            return(id < 1 ? null : await context.ClassificationCodes.FindAsync(id));
        }
Beispiel #15
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));
        }