public string SavecounterParty(CounterParty counterParty) { using (LoanPriceEntities context = new LoanPriceEntities()) { if (counterParty.ID <= 0) { if (context.CounterParties.Where(s => s.Name == counterParty.Name).Count() == 0) { context.AddToCounterParties(counterParty); context.SaveChanges(); return "CounterParty is added successfully"; } else return "Entry of the same Name is already exists."; } else { if (context.CounterParties.Where(s => s.Name == counterParty.Name && s.ID != counterParty.ID).Count() == 0) { context.CounterParties.Attach(counterParty); context.ObjectStateManager.ChangeObjectState(counterParty, System.Data.EntityState.Modified); context.SaveChanges(); return "CounterParty is Updated successfully"; } else return "Entry of the same Name is already exists."; } } }
/// <summary> /// Create a new CounterParty object. /// </summary> /// <param name="id">Initial value of the ID property.</param> public static CounterParty CreateCounterParty(global::System.Int32 id) { CounterParty counterParty = new CounterParty(); counterParty.ID = id; return counterParty; }
protected void btnCPSave_Click(object sender, EventArgs e) { CounterParty model = new CounterParty(); CounterPartyBL bl = new CounterPartyBL(); model.Type = txtCPType.SelectedValue.Trim(); model.Name = txtCPName.Text.Trim(); model.Region = txtCPRegion.SelectedValue; if (!string.IsNullOrEmpty(hfCPID.Value)) { model.ID = Convert.ToInt32(hfCPID.Value); LogActivity("CounterParty Updated", "Email has been updated", string.Empty); } else { LogActivity("CounterParty Created", "Email has been created", string.Empty); } string str = bl.SavecounterParty(model); BindCounterParties(); if (str != "Entry of the same Name is already exists.") { hfCPID.Value = string.Empty; } RadWindowManager1.RadAlert(str, 330, 180, "realedge associates", "alertCallBackFn"); }
/// <summary> /// Deprecated Method for adding a new object to the CounterParties EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCounterParties(CounterParty counterParty) { base.AddObject("CounterParties", counterParty); }
private static List<CounterParty> ExtractCounterPartyList(DataTable csvData, List<string> columnNames) { List<CounterParty> importedList = new List<CounterParty>(); foreach (DataRow row in csvData.Rows) { CounterParty model = new CounterParty(); // Get All properties PropertyInfo[] properties = model.GetType().GetProperties(); foreach (PropertyInfo pInfo in properties) { if (columnNames.Contains(pInfo.Name)) { object value = row[pInfo.Name]; TypeConverter typeConverter = TypeDescriptor.GetConverter(pInfo.PropertyType); object propValue = null; if (typeConverter.GetType().FullName == "System.ComponentModel.NullableConverter") { if (value.ToString().Trim() == "1") { propValue = typeConverter.ConvertFromString(("True")); } } else propValue = typeConverter.ConvertFromString((value.ToString())); // Set value on the property pInfo.SetValue(model, propValue, null); } } importedList.Add(model); } return importedList; }