private void createEditButton_Click(object sender, EventArgs e) { if (_editMode) { if (_sectorService.EditIndustrialSector(_sector)) { int current = EasyCRMForm.getForm().sectorsBindingSource.Position; EasyCRMForm.getForm().sectorsBindingSource.List[current] = _sector; this.DialogResult = DialogResult.OK; this.Close(); } else { showValidationErrors(); //we clear the model state previous errors _modelState.Clear(); } } else//creating a new sector { if (_sectorService.CreateIndustrialSector(_sector)) { EasyCRMForm.getForm().sectorsBindingSource.Add(_sector); this.DialogResult = DialogResult.OK; this.Close(); } else { showValidationErrors(); _modelState.Clear(); //we clear the model state previous errors } } }
public ActionResult Edit(IndustrialSector industrialSector) { // normaly we should have those parameters : "Edit(int id, FormCollection values)" // Then we would retrieve the existing sector from db (by his id) and then update the // fields with the form posted values.But in this specific case we can directly // pass an "IndustrialSector" instance, the binder has automatically bound the "id" // field from the request(/Sector/Edit/{id}) and the "sector" field from the form. // ... if (!_sectorService.EditIndustrialSector(industrialSector)) { return(View(industrialSector)); } return(RedirectToAction("Index")); }