public async Task <IActionResult> OnPostSearch()
        {
            try
            {
                if (SearchDataInputModel.DateEntered != null)
                {
                    if (!ValidateDate())
                    {
                        ModelState.AddModelError("CustomError", "Please check the format of your date");
                        SearchDataInputModel = new Msd3SearchInputModel();
                    }
                }

                Msd3SummarySearchResultList = _msd3SubmissionSearch.GenerateMsd3ViewModelFilteredOnSearchCriteria(SearchDataInputModel, false);
                await PopulateDropDowns();

                if (Msd3SummarySearchResultList.Count == 0)
                {
                    ModelState.AddModelError("CustomError", "No records have been found matching the above criteria");
                }
            }
            catch (Exception e)
            {
                ModelState.AddModelError("CustomError", e.Message);
                _logger.LogError(e.Message);
            }

            TempData.Put(FindSubKey, SearchDataInputModel);
            return(Page());
        }
        public async Task <IActionResult> OnGetAsync(string message)
        {
            try
            {
                SearchDataInputModel = new Msd3SearchInputModel();
                if (TempData.NotNullOrEmpty() && TempData.Peek(FindSubKey) != null)
                {
                    SearchDataInputModel = TempData.Get <Msd3SearchInputModel>(FindSubKey);
                    TempData.Keep(FindSubKey);
                }
                await PopulateDropDowns();

                SuccessMessage = TempData.Get <string>("EditSuccess") ?? TempData.Get <string>("DeleteSuccess") ?? string.Empty;
                Msd3SummarySearchResultList = _msd3SubmissionSearch.GenerateMsd3ViewModelFilteredOnSearchCriteria(SearchDataInputModel, false);
            }
            catch (NullReferenceException)
            {
                SearchDataInputModel = new Msd3SearchInputModel();
            }
            catch (Exception e)
            {
                ModelState.AddModelError("CustomError", "There has been an error connecting to the database");
                _logger.LogError(e.Message);
            }
            return(Page());
        }
        public async Task <IActionResult> OnGetExport(Msd3SearchInputModel searchInput)
        {
            var msd3SummarySearchResultList = _msd3SubmissionSearch.GenerateMsd3ViewModelFilteredOnSearchCriteria(searchInput, true);

            await PopulateDropDowns();

            if (msd3SummarySearchResultList.Count == 0)
            {
                ModelState.AddModelError("CustomError", "No records have been found matching the above criteria");
                return(Page());
            }
            var byteArrayCsvData    = _csvExtractor.GenerateMsd3CsvExtract(msd3SummarySearchResultList);
            var csvDownloadFileName = "MSD3SearchResults" + DateTime.Now.ToShortDateString() + ".csv";

            return(File(byteArrayCsvData, "text/csv", csvDownloadFileName));
        }
 private void CreateMsd3SearchDictionary(Msd3SearchInputModel searchModel)
 {
     if (!string.IsNullOrWhiteSpace(searchModel.SenderId))
     {
         _searchFilterDictionary.Add("SenderId", searchModel.SenderId);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.UniqueRef))
     {
         _searchFilterDictionary.Add("UniqueRef", searchModel.UniqueRef);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.ReportingPort))
     {
         _searchFilterDictionary.Add("ReportingPort", searchModel.ReportingPort);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.Year))
     {
         _searchFilterDictionary.Add("Year", searchModel.Year);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.Quarter))
     {
         _searchFilterDictionary.Add("Quarter", searchModel.Quarter);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.DateEntered))
     {
         _searchFilterDictionary.Add("DateEntered", searchModel.DateEntered);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.Agent))
     {
         _searchFilterDictionary.Add("Agent", searchModel.Agent);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.LastUpdatedBy))
     {
         _searchFilterDictionary.Add("LastUpdatedBy", searchModel.LastUpdatedBy);
     }
     if (!string.IsNullOrWhiteSpace(searchModel.Source))
     {
         _searchFilterDictionary.Add("Source", searchModel.Source);
     }
 }
        public List <Msd3SummaryViewModel> GenerateMsd3ViewModelFilteredOnSearchCriteria(Msd3SearchInputModel searchInputModel, bool resultToBeExported)
        {
            _searchFilterDictionary.Clear();
            CreateMsd3SearchDictionary(searchInputModel);

            if (_searchFilterDictionary.Count == 0)
            {
                return(new List <Msd3SummaryViewModel>());
            }

            CreateMsd1List(_searchFilterDictionary, MSDData.MSD3);
            if (_msd3Queryable == null)
            {
                return(new List <Msd3SummaryViewModel>());
            }

            AddToMsd3SummaryViewModel();
            return(_msd3SummarySearchResultList);
        }