public async Task <ActionResult> Add(LecturerViewModel model) { if (model == null || !ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _lecturerService.Add(model.ToLecturer()); return(Ok(result)); }
private void btnAddLecturer_Click(object sender, EventArgs e) { _lecturerService.Add(new Lecturer { IdentityNumber = tbxAddLecturerIdentityNo.Text, Firstname = tbxAddLecturerFirstname.Text, Lastname = tbxAddLecturerLastname.Text, DepartmentCode = cbxAddLecturerDepartment.Text.Split(' ')[0] }); LoadLecturers(); }
public IActionResult Add([FromBody] LecturerDto Lecturer) { try { if (lecturerService.Add(Lecturer)) { return(Ok("Successfully Added")); } else { return(BadRequest("Failed To Add")); } } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <LecturerViewModel> > PostLecturer(LecturerViewModel lecturer) { if (lecturer != null) { try { await Task.Run(() => { _lecturerService.Add(lecturer); _lecturerService.SaveChanges(); return(Ok("Thêm giáo viên thành công!")); }); } catch { throw new Exception(string.Format("Lỗi khi thêm dữ liệu")); } } return(CreatedAtAction("GetLecturer()", new { id = lecturer.Id }, lecturer)); }