public HttpResponseMessage PostNhanVien([FromBody] NhanVien nhanVien) { try { _repository.Add(nhanVien); return(Request.CreateResponse(HttpStatusCode.OK, nhanVien)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Lỗi không xác định", ex)); } }
private async void btnAddLecture_Click(object sender, EventArgs e) { try { var hopDong = new HopDong() { NgayKi = NgayKiDateEdit.DateTime, NgayKetThuc = NgayKetThucDateEdit.DateTime }; var newHopDong = await _hopDongRepository.Add(hopDong); var nhanVien = new NhanVien() { HoTen = HoTenTextEdit.Text, NgaySinh = NgaySinhDateEdit.DateTime, GioiTinh = Boolean.Parse(GioiTinhCheckEdit.Properties.Items[GioiTinhCheckEdit.SelectedIndex].Value.ToString()), DanToc = DanTocTextEdit.Text, TonGiao = TonGiaoTextEdit.Text, SoDienThoai = Convert.ToInt32(SoDienThoaiTextEdit.Text), Email = EmailTextEdit.Text, DiaChi = DiaChiTextEdit.Text, SoCMND = Convert.ToInt32(SoCMNDTextEdit.Text), Anh = AnhTextEdit.Text, DangVien = Boolean.Parse(DangVienCheckEdit.OldEditValue.ToString()), HocViId = Convert.ToInt32(comboBoxHocVi.SelectedValue.ToString()), DonViId = Convert.ToInt32(comboBoxDonVi.SelectedValue.ToString()), HopDongId = newHopDong.HopDongId, NgachId = Convert.ToInt32(comboBoxNgach.SelectedValue.ToString()) }; _nhanVienRepository.Add(nhanVien); XtraMessageBox.Show("Thêm nhân viên thành công"); } catch (Exception ex) { XtraMessageBox.Show($"Thêm nhân viên thất bại.... Lỗi {ex.ToString()}", "Lỗi ", MessageBoxButtons.OK, MessageBoxIcon.Error); } }