Example #1
0
        public async Task <IActionResult> PartiallyUpdateInstitute(
            string username,
            string password,
            JsonPatchDocument <AccountUpdateDto> patchDocument)
        {
            var accountEntity = await _accountRepository.GetAccountAsync(username, password);

            if (accountEntity == null)
            {
                return(NotFound());
            }

            var dtoToPatch = _mapper.Map <AccountUpdateDto>(accountEntity);

            //entity 转化为 updateDto
            //把传进来的account的值更新到updateDto
            //把updateDto映射回entity

            //需要处理验证错误
            patchDocument.ApplyTo(dtoToPatch);

            _mapper.Map(dtoToPatch, accountEntity);
            _accountRepository.UpdatePassword(accountEntity);
            await _accountRepository.SaveAsync();

            return(NoContent());
        }