public async Task <Image> Delete(int id) { var img = await _dbContext.Images.FirstOrDefaultAsync(x => x.Id == id); if (img != null) { _dbContext.Remove(img); _dbContext.SaveChanges(); } return(img); }
public async Task RemoveAsync(int id) { try { Seller s = await FindByIdAsync(id); _context.Remove(s); await _context.SaveChangesAsync(); } catch (DbUpdateException e) { throw new IntegrityException(e.Message); } }
private void buttonDelete_Click(object sender, EventArgs e) { int userID = 0; if (userView.Rows.Count > 0) { userView.Rows[userView.CurrentCell.RowIndex].Selected = true; if (userView.SelectedRows[0].Cells[0].Value != DBNull.Value) { userID = (Int32)userView.SelectedRows[0].Cells[0].Value; } stx.Remove(stx.Customers.Single(u => u.Id == userID)); stx.SaveChanges(); getUsers(); } else { MessageBox.Show("to delete a user please search then select a row"); } }
private void RemoveFromList_Click(object sender, EventArgs e) { if (DataVeiwOutput.Rows.GetRowCount(DataGridViewElementStates.Selected) == 1) { //int RowIDToRemove = DataVeiwOutput. string userFirst = (string)DataVeiwOutput.SelectedRows[0].Cells[0].Value; string userCity = (string)DataVeiwOutput.SelectedRows[0].Cells[2].Value; string userCountry = (string)DataVeiwOutput.SelectedRows[0].Cells[3].Value; string userPhone = (string)DataVeiwOutput.SelectedRows[0].Cells[4].Value; int FindRows = ctx.Customers.Where(f => f.LastName == LastNameToBeRemoved.Text && f.FirstName == userFirst && f.City == userCity && f.Country == userCountry && f.Phone == userPhone).Select(i => i.Id).FirstOrDefault(); //int RemovedId = ctx.Customers.Where(a => a.LastName) ctx.Remove(ctx.Customers.Find(FindRows)); ctx.SaveChanges(); RemoveFromList.Enabled = false; LastNameToBeRemoved.Text = ""; FullListReturn(); } }