private void button2_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dataGridView1.Rows) { var cpr = Convert.ToString(row.Cells[0].Value); if (row.Cells[8].Value.GetType() == typeof(System.DBNull)) { row.Cells[8].Value = false; } if (row.Cells[9].Value.GetType() == typeof(System.DBNull)) { row.Cells[9].Value = false; } if (Convert.ToBoolean(row.Cells[8].Value) == true) { var app = proxy.GetAllApplications().SingleOrDefault(x => x.Cpr == cpr); string generPassword = Membership.GeneratePassword(10, 0); var salt = Encoding.ASCII.GetString(Guid.NewGuid().ToByteArray()); SenderModel courier = new SenderModel(app.Cpr, app.FirstName, app.LastName, app.PhoneNumber, app.Email, app.Address, app.ZipCode, app.City) { AccountType = 2, Points = 0 }; proxy.AddCourier(new SenderResource { AccountType = courier.AccountType, Address = courier.Address, City = courier.City, ZipCode = courier.ZipCode, Cpr = courier.Cpr, Email = courier.Email, FirstName = courier.FirstName, LastName = courier.LastName, PhoneNumber = courier.PhoneNumber, Points = courier.Points, Username = courier.Email, Password = generPassword, PassSalt = salt }); ApplicationResource appToDelete = new ApplicationResource { Cpr = app.Cpr }; proxy.DeleteApplication(appToDelete, false); } else if (Convert.ToBoolean(row.Cells[9].Value) == true) { ApplicationResource appToDelete = new ApplicationResource { Cpr = cpr }; proxy.DeleteApplication(appToDelete, true); } } this.InitializeTable(); this.Bind_DataGridView_Using_DataTable_Load(sender, e); }