示例#1
0
        private void buttonFilter_Click(object sender, EventArgs e)
        {
            _tableBindingSource.DataSource = _countryRepository.Filter(countries, comboBoxRegions.Text, textBoxName.Text, textBoxCapital.Text, Convert.ToInt32(numericUpDownPopulationMin.Value), Convert.ToInt32(numericUpDownPopulationMax.Value));
            string filterMessage = "Odabrali ste filtriranje po: ";

            if (!String.IsNullOrWhiteSpace(comboBoxRegions.Text))
            {
                filterMessage = filterMessage + "regiji;";
            }
            if (!String.IsNullOrWhiteSpace(textBoxName.Text))
            {
                filterMessage = filterMessage + "imenu drzave;";
            }
            if (!String.IsNullOrWhiteSpace(textBoxCapital.Text))
            {
                filterMessage = filterMessage + "imenu glavnog grada;";
            }
            if (numericUpDownPopulationMin.Value >= 0)
            {
                filterMessage = filterMessage + "minimalnoj populaciji;";
            }
            if (numericUpDownPopulationMax.Value != 0)
            {
                filterMessage = filterMessage + "maksimalnoj populaciji;";
            }
            MessageBox.Show(filterMessage, "Filtriranje", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public IActionResult Filter(string name)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var filtercountryfilter = _countryRepository.Filter(name);

            if (filtercountryfilter == null)
            {
                return(Content("The country is not found!"));
            }

            try
            {
                return(Ok(filtercountryfilter));
            }
            catch
            {
                return(BadRequest(ModelState)); //or can throw new Exception
            }
        }