public async Task <IDataResult <StudentUpdateDto> > UpdateStudentWithAddressAsync(StudentUpdateDto studentUpdateDto)
        {
            if (studentUpdateDto == null)
            {
                return(new ErrorDataResult <StudentUpdateDto>(studentUpdateDto, HttpStatusCode.NotAcceptable));
            }

            var existingAddress = await _addressService.GetAddressByStudentId(studentUpdateDto.Id);

            if (existingAddress == null)
            {
                return(new ErrorDataResult <StudentUpdateDto>(studentUpdateDto, HttpStatusCode.NotFound));
            }

            var newStudent = _mapper.Map <Student>(studentUpdateDto);

            await UpdateStudentAsync(newStudent);

            await UpdateAddress(studentUpdateDto, existingAddress);

            return(new SuccessfulDataResult <StudentUpdateDto>(studentUpdateDto, HttpStatusCode.OK));
        }
Exemple #2
0
        public virtual async Task UpdateAsync(StudentUpdateDto input)
        {
            var student = await _studentRepository.GetAsync(input.Id);

            ObjectMapper.Map(input, student);
        }
 public async Task <StudentDto> Update([FromBody] StudentUpdateDto student)
 {
     return(await this.studentServices.Update(student));
 }
        public async Task <IActionResult> Update(StudentUpdateDto studentUpdateDto)
        {
            var result = await _studentService.UpdateStudentWithAddressAsync(studentUpdateDto);

            return(StatusCode(result.HttpStatusCode, result.Data));
        }