private void View_OnCountriesUpdateItem(object sender, CountriesManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(CountriesManagementEventArgs));
            }

            var country = this.countriesServices.GetCountry(e.Id);

            if (country == null)
            {
                this.View.ModelState.AddModelError(
                    ErrorMessages.MODEL_ERROR_KEY,
                    string.Format(ErrorMessages.MODEL_ERROR_MESSAGE, e.Id));

                return;
            }

            this.View.TryUpdateModel(country);

            if (this.View.ModelState.IsValid)
            {
                this.countriesServices.UpdateCountry(e.Id, country);
            }
        }
Exemplo n.º 2
0
        protected void CreateCountrytBtn_Click(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                this.OnCountriesGetData?.Invoke(sender, e);

                var doesAbbreviationExist = this.Model.Countries
                                            .Any(c => c.Abbreviation.ToLower() == this.AbbreviationNameTextBox.Text.ToLower());

                if (doesAbbreviationExist)
                {
                    this.AbbreviationNameTextBox.BorderColor = Color.Red;
                    return;
                }

                var countryEventArgs = new CountriesManagementEventArgs()
                {
                    Name         = this.CountryNameTextBox.Text,
                    Abbreviation = this.AbbreviationNameTextBox.Text.ToUpper()
                };

                this.OnCountriesAddItem?.Invoke(null, countryEventArgs);

                this.SuccessPanel.Visible       = true;
                this.AddedCountryIdLiteral.Text = countryEventArgs.Id.ToString();

                this.ClearFields();
            }
        }
        private void View_OnCountriesDeleteItem(object sender, CountriesManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(CountriesManagementEventArgs));
            }

            this.countriesServices.DeleteCountry(e.Id);
        }
        private void View_OnCountriesAddItem(object sender, CountriesManagementEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(CountriesManagementEventArgs));
            }

            var country = new Country()
            {
                Name         = e.Name,
                Abbreviation = e.Abbreviation
            };

            e.Id = this.countriesServices.AddCountry(country);
        }