private void btnEditPower_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in DgvPowers.SelectedRows) { string PowerIndex = row.Cells["PowerIndex"].Value.ToString(); string PowerName = row.Cells["PowerName"].Value.ToString(); bool InActive = bool.Parse(row.Cells["InActive"].Value.ToString()); int PowerID = row.Cells["ID"].Value != null?int.Parse(row.Cells["ID"].Value.ToString()) : 0; int ParentID = row.Cells["ParentID"].Value != null?int.Parse(row.Cells["ParentID"].Value.ToString()) : 0; RossPowers model = null; if (PowerID == 0) { model = new RossPowers(); } else { model = RLD.GetPower(PowerID); } model.InActive = InActive; model.ParentID = ParentID; model.PowerIndex = PowerIndex; model.PowerName = PowerName; RLD.InsertOrUpdatePower(model); } buttonSet.Enabled = true; InitData(); }
private async void btnAddRow_Click(object sender, EventArgs e) { var PowerList = await RLD.GetPowers(); RossPowers obj = new RossPowers(); obj.ParentID = CurrPowerID; PowerList.Add(obj); DgvPowers.DataSource = Mapper.Map <List <POWERS> >(PowerList); DgvPowers.CurrentCell = DgvPowers.Rows[DgvPowers.Rows.Count - 1].Cells[2]; buttonSet.Enabled = false; }
public int InsertOrUpdatePower(RossPowers input) { int result = 0; try { if (input.ID.Equals(0)) { RLDB.RossPowers.Add(input); RLDB.SaveChanges(); result = input.ID; } else { RLDB.Entry(input).State = EntityState.Modified; RLDB.SaveChanges(); result = input.ID; } } catch { } return(result); }