//public bool IsValidName(string name)
        //{
        //    using (LoanPriceEntities context = new LoanPriceEntities())
        //    {
        //        int count = context.CreditRatings.Where(s => s. == name).Count();
        //        if (count == 0)
        //            return true;
        //        else
        //            return false;
        //    }
        //}
        public string SaveRating(CreditRating rating)
        {
            using (LoanPriceEntities context = new LoanPriceEntities())
            {
                if (rating.ID <= 0)
                {

                    //if (context.CreditRatings.Where(s => s.CreditAgency == rating.CreditAgency).Count() == 0)
                    //{
                        context.AddToCreditRatings(rating);
                        context.SaveChanges();
                        return "Credit Rating is added successfully";
                    //}
                    //else
                    //    return "Entry of the same Currency is already exists.";
                }
                else
                {
                    //if (context.Currencies.Where(s => s.Currancy == currency.Currancy && s.ID != currency.ID).Count() == 0)
                    //{
                    context.CreditRatings.Attach(rating);
                    context.ObjectStateManager.ChangeObjectState(rating, System.Data.EntityState.Modified);
                        context.SaveChanges();
                        return "Credit Rating is Updated successfully";
                    //}
                    //else
                    //    return "Entry of the same Currency is already exists.";
                }
            }
        }
 /// <summary>
 /// Create a new CreditRating object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 public static CreditRating CreateCreditRating(global::System.Int32 id)
 {
     CreditRating creditRating = new CreditRating();
     creditRating.ID = id;
     return creditRating;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the CreditRatings EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCreditRatings(CreditRating creditRating)
 {
     base.AddObject("CreditRatings", creditRating);
 }
        protected void btnSaveRating_Click(object sender, EventArgs e)
        {
            CreditRating model = new CreditRating();
            CreditRatingsBL bl = new CreditRatingsBL();
            if (txtRatings.Text.Trim() == string.Empty)
            {
                RadWindowManager1.RadAlert("Rating is required", 330, 180, "realedge associates", "alertCallBackFn"); return;
            }
            else
            {
                model.CreditAgencyID = Convert.ToInt16(ddlAgency.SelectedValue);
                model.Rating = txtRatings.Text.Trim();
                if (!string.IsNullOrEmpty(hdnCreditRatings.Value))
                {
                    model.ID = Convert.ToInt32(hdnCreditRatings.Value);
                    LogActivity("Rating Updated", "Currency has been updated", string.Empty);
                }
                else
                {
                    LogActivity("Rating Created", "Currency has been created", string.Empty);
                }

                string str = bl.SaveRating(model);
                BindCreditRatings();
                if (str != "Entry of the same Agency Name is already exists.")
                {
                    hdnCreditRatings.Value = string.Empty;
                }

                RadWindowManager1.RadAlert(str, 330, 180, "realedge associates", "alertCallBackFn");
            }
        }