Example #1
0
        private void SaveAndUpdate()
        {
            try
            {
                if (string.IsNullOrEmpty(txtName.Text))
                {
                    Alert(AlertType.Warning, "Enter country name.");
                    txtName.Focus();
                }
                else
                {
                    string name = Convert.ToString(txtName.Text);
                    string countryCodeAlpha2 = Convert.ToString(txtCountryCodeAlpha2.Text);
                    string countryCodeAlpha3 = Convert.ToString(txtCountryCodeAlpha3.Text);
                    string description       = Convert.ToString(txtDescription.Text);

                    CountryBLL countryBLL = new CountryBLL();
                    if (this.ModelId > 0)
                    {
                        DataTable dt      = countryBLL.GetById(this.ModelId);
                        Countries country = new Countries();
                        country.CountryId         = Convert.ToInt32(Convert.ToString(dt.Rows[0]["CountryId"]));
                        country.CountryCode       = Convert.ToString(dt.Rows[0]["CountryCode"]);
                        country.Name              = Convert.ToString(dt.Rows[0]["Name"]);
                        country.CountryCodeAlpha2 = Convert.ToString(dt.Rows[0]["CountryCodeAlpha2"]);
                        country.CountryCodeAlpha3 = Convert.ToString(dt.Rows[0]["CountryCodeAlpha3"]);
                        country.Description       = Convert.ToString(dt.Rows[0]["Description"]);
                        country.IsActive          = Convert.ToBoolean(Convert.ToString(dt.Rows[0]["IsActive"]));
                        country.CreatedDate       = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["CreatedDate"]))) ? (DateTime?)null : Convert.ToDateTime(Convert.ToString(dt.Rows[0]["CreatedDate"]));
                        country.CreatedBy         = Convert.ToString(dt.Rows[0]["CreatedBy"]);
                        country.CreatedFrom       = Convert.ToString(dt.Rows[0]["CreatedFrom"]);

                        country.Name = name.Trim();
                        country.CountryCodeAlpha2 = countryCodeAlpha2;
                        country.CountryCodeAlpha3 = countryCodeAlpha3;
                        country.Description       = description;

                        country.UpdatedDate = DateTime.Now;
                        country.UpdatedBy   = this.UserInfo;
                        country.UpdatedFrom = this.StationInfo;

                        if (countryBLL.Update(country))
                        {
                            this.MultiEntryDisallow = true;
                            Alert(AlertType.Success, "Updated successfully.");
                            ClearFields();
                        }
                        else
                        {
                            Alert(AlertType.Error, "Failed to update.");
                        }
                    }
                    else
                    {
                        Countries country = new Countries();
                        country.CountryCode       = this.ModelCode;
                        country.Name              = name.Trim();
                        country.CountryCodeAlpha2 = countryCodeAlpha2;
                        country.CountryCodeAlpha3 = countryCodeAlpha3;
                        country.Description       = description;
                        country.IsActive          = true;
                        country.CreatedDate       = DateTime.Now;
                        country.CreatedBy         = this.UserInfo;
                        country.CreatedFrom       = this.StationInfo;

                        if (countryBLL.Save(country))
                        {
                            Alert(AlertType.Success, "Saved successfully.");
                            ClearFields();
                            GenerateCode();
                        }
                        else
                        {
                            Alert(AlertType.Error, "Failed to save.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Alert(AlertType.Error, ex.Message.ToString());
            }
        }