public ActionResult Edit(Student editMe) { if (ModelState.IsValid == false) { return(View(editMe)); } _dbContext.Students.Attach(editMe); _dbContext.Entry(editMe).State = EntityState.Modified; _dbContext.SaveChanges(); return(RedirectToAction(nameof(Details), new { id = editMe.Id })); }
private void ChangeAirplaneData() { try { if (string.IsNullOrEmpty(textBoxNameAir.Text) && string.IsNullOrEmpty(textBoxMaxDistance.Text) && string.IsNullOrEmpty(textBoxCarrying.Text)) { return; } var airplane = GetSelectedAirplane(); if (airplane == null) { return; } var newAirplane = new Airplane(); if (!string.IsNullOrEmpty(textBoxNameAir.Text)) { newAirplane.Name = textBoxNameAir.Text; } else { newAirplane.Name = airplane.Name; } if (!string.IsNullOrEmpty(textBoxMaxDistance.Text)) { newAirplane.MaxDistance = Int32.Parse(textBoxMaxDistance.Text); } else { newAirplane.MaxDistance = airplane.MaxDistance; } if (!string.IsNullOrEmpty(textBoxCarrying.Text)) { newAirplane.Carrying = Int32.Parse(textBoxCarrying.Text); } else { newAirplane.Carrying = airplane.Carrying; } if (airplane.Equals(newAirplane)) { return; } airplane.Name = newAirplane.Name; airplane.MaxDistance = newAirplane.MaxDistance; airplane.Carrying = newAirplane.Carrying; ClearFieldsInput(); db.Entry(airplane).State = EntityState.Modified; db.SaveChanges(); dataGridAirplanes.Refresh(); ShowInfo("Объект изменен!"); } catch (Exception ex) { MainFormService.ShowError(ex.Message); } }