Ejemplo n.º 1
0
 public string SaveCountry(tblCountry country)
 {
     using (LoanPriceEntities context = new LoanPriceEntities())
     {
         if (country.ID <= 0)
         {
             if (context.tblCountry.Where(s => s.Name == country.Name).Count() == 0)
             {
                 context.AddTotblCountry(country);
                 context.SaveChanges();
                 return "Country is added successfully";
             }
             else
                 return "Entry of the same Name is already exists.";
         }
         else
         {
             context.tblCountry.Attach(country);
             context.ObjectStateManager.ChangeObjectState(country, System.Data.EntityState.Modified);
             context.SaveChanges();
             return "Country is Updates successfully";
         }
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the tblCountry EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotblCountry(tblCountry tblCountry)
 {
     base.AddObject("tblCountry", tblCountry);
 }
 /// <summary>
 /// Create a new tblCountry object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="code">Initial value of the Code property.</param>
 public static tblCountry CreatetblCountry(global::System.Int32 id, global::System.String name, global::System.String code)
 {
     tblCountry tblCountry = new tblCountry();
     tblCountry.ID = id;
     tblCountry.Name = name;
     tblCountry.Code = code;
     return tblCountry;
 }
        protected void btnCountrySave_Click(object sender, EventArgs e)
        {
            CountryBL countryBL = new CountryBL();
            if (txtCountryName.Text != "" || txtCountryCode.Text != "")
            {

                DAL.tblCountry country = new DAL.tblCountry();
                country.Name = txtCountryName.Text.Trim();
                country.Code = txtCountryCode.Text.Trim();

                if (!string.IsNullOrEmpty(hfCountryID.Value))
                {
                    country.ID = Convert.ToInt32(hfCountryID.Value);
                    LogActivity("Country Updated", "Country has been updated", string.Empty);
                }
                else
                {
                    LogActivity("Country Created", "Country has been created", string.Empty);
                }

                string result = countryBL.SaveCountry(country);

                lblCountryError.Visible = true;
                lblCountryError.Text = result;
                ShowMessage("Message", result);
                BindCountry();
                hfCountryID.Value = string.Empty;
                Clear();
            }
            else
            {
                lblCountryError.Visible = true;
                lblCountryError.Text = "Please Enter The Details First.";
            }
        }