Пример #1
0
        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));
        }
Пример #2
0
 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();
 }
Пример #3
0
 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));
     }
 }
Пример #4
0
        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));
        }