public async Task <IActionResult> OnPost() { if (!ModelState.IsValid) { return(Page()); } if (Department.DepartmentId > 0) { await _departmentData.UpdateDepartment(Department); } else { var id = await _departmentData.InsertDepartment(Department); Department.DepartmentId = id; } TempData["Message"] = $"{Department.Name} has been saved."; return(RedirectToPage("./List")); }
private void btnUpdate_Click(object sender, EventArgs e) { if (IsValidForm()) { try { _department.DepartmentName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(txtName.Text.Trim()); if (txtAddress.Text.Trim() == string.Empty) { _department.Address = null; } else { _department.Address = txtAddress.Text.Trim().ToLower(); } if (txtEmail.Text.Trim() == null) { _department.Email = null; } else { _department.Email = txtEmail.Text.Trim(); } //Update department records. department.UpdateDepartment(_department); Logger.WriteToFile(Logger.FullName, "successfully modified a department"); MessageBox.Show($"Record has been successfully updated", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information); //Trigger gridview event for DepartmentList UpdateGrid(); this.Close(); } catch (Exception ex) { MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }