コード例 #1
0
ファイル: CityEntry.aspx.cs プロジェクト: chayan01/project-01
        protected void saveButton_Click(object sender, EventArgs e)
        {
            Message message = new Message();

            try
            {
                string name = cityNameTextBox.Text.Trim();
                string about = aboutTextBox.Text.Trim();
                int dwellers = Convert.ToInt32(dwellersTextBox.Text);
                string location = locationTextBox.Text.Trim();
                string weather = weatherTextBox.Text.Trim();
                int countryId = Convert.ToInt32(countryDropDownList.SelectedItem.Value);
                City aCity = new City(name, about, dwellers, location, weather, countryId);
                message = aCityManager.Save(aCity);
            }
            catch (Exception ex)
            {
                message.Status = "alert alert-danger";
                message.Details = ex.Message;
            }
            finally
            {
                messageLabel.CssClass = message.Status;
                messageLabel.Text = message.Details;

                if (message.Status == "alert alert-success")
                {
                    ClearFormData();
                }
                LoadCityList();
            }
        }
コード例 #2
0
ファイル: CityManager.cs プロジェクト: chayan01/project-01
        public Message Save(City newCity)
        {
            Message message = new Message();
            if (newCity.Name.Length == 0)
            {
                message.Status = "alert alert-warning";
                message.Details = "City name is required.";
                return message;
            }
            bool isCityExists = IsCityExists(newCity);

            if (isCityExists)
            {
                message.Status = "alert alert-danger";
                message.Details = "City name [" + newCity.Name + "] is already exists.";
                return message;
            }

            if (newCity.About.Length == 0)
            {
                message.Status = "alert alert-warning";
                message.Details = "About field name is required.";
                return message;
            }

            if (newCity.Location.Length == 0)
            {
                message.Status = "alert alert-warning";
                message.Details = "Location field name is required.";
                return message;
            }

            if (newCity.Weather.Length == 0)
            {
                message.Status = "alert alert-warning";
                message.Details = "Weather field name is required.";
                return message;
            }

            if (newCity.CountryId == 0)
            {
                message.Status = "alert alert-warning";
                message.Details = "Select a CountryDropDown of the city.";
                return message;
            }

            try
            {
                aCityGateway.AddCity(newCity);
                message.Status = "alert alert-success";
                message.Details = "City Added Successfully";
            }
            catch (SqlException ex)
            {
                message.Status = "alert alert-danger";
                message.Details = ex.Message;
            }

            return message;
        }
コード例 #3
0
        protected void saveCountryButton_Click(object sender, EventArgs e)
        {
            Message message = new Message();

            try
            {
                string name = nameCountryTextBox.Text.Trim();
                string about = aboutCountryTextBox.Text.Trim();
                Country newCountry = new Country(name, about);
                message = aCountryManager.Save(newCountry);
            }
            catch (Exception ex)
            {
                message.Status = "alert alert-danger";
                message.Details = ex.Message;
            }
            finally
            {
                messageLabel.CssClass = message.Status;
                messageLabel.Text = message.Details;

                if (message.Status == "alert alert-success")
                {
                    ClearText();
                }
                LoadAllCountries();
            }
        }
コード例 #4
0
ファイル: CountryManager.cs プロジェクト: chayan01/project-01
        public Message Save(Country newCountry)
        {
            Message message = new Message();

            if (newCountry.CountryName.Length == 0)
            {
                message.Status = "alert alert-warning";
                message.Details = "Name is Blank.";
                return message;
            }

            bool alreadyExists = aCountryGateway.SearchCountryByName(newCountry.CountryName);

            if (alreadyExists)
            {
                message.Status = "alert alert-danger";
                message.Details = "Country name [" + newCountry.CountryName + "] is already exists.";
                return message;
            }

            if (newCountry.CountryAbout.Length == 0)
            {
                message.Status = "alert alert-warning";
                message.Details = "About field is required.";
                return message;
            }

            try
            {
                aCountryGateway.Save(newCountry);
                message.Status = "alert alert-success";
                message.Details = "Country Added Successfully";
            }
            catch (SqlException ex)
            {
                message.Status = "alert alert-danger";
                message.Details = ex.Message;
            }

            return message;
        }