public ActionResult Put([FromForm] StudentAddDTO value) { var preStudent = Get(value.StudentId); if (preStudent != null) { string imagePath = preStudent.Value.PicturePath; if (value.Picture != null) { imagePath = FileUpload.UpdateFile(value.Picture, imagePath, "Images", _host.WebRootPath); } Student student = new Student { StudentId = value.StudentId, StudentName = value.StudentName, DateOfBirth = value.DateOfBirth, GenderId = value.GenderId, PicturePath = imagePath }; _repo.UpdateStudent(student); return(Ok(student)); } return(NotFound()); }
public async Task <int> AddStudent(StudentAddDTO studentAddDTO) { var student = _mapper.Map <StudentAddDTO, Student>(studentAddDTO); await _unitOfWork.Students.AddAsync(student); return(await _unitOfWork.SaveAsync()); }
public ActionResult Post([FromForm] StudentAddDTO value) { string imagePath = FileUpload.Upload(value.Picture, "Images", _host.WebRootPath); Student student = new Student { StudentName = value.StudentName, DateOfBirth = value.DateOfBirth, GenderId = value.GenderId, PicturePath = imagePath }; _repo.InsertStudent(student); return(Ok(student)); }
public async Task <ActionResult <string> > AddStudent(StudentAddDTO studentAddDTO) { var result = await _studentService.AddStudent(studentAddDTO); return(result > 0 ? StatusCode(StatusCodes.Status201Created) : BadRequest()); }