public async Task <ActionResult> CreateItemAsync([FromBody] UserInfoDTO userInfo, CancellationToken cancellationToken) { var newItem = _mapper.Map <UserInfo>(userInfo); newItem = await _userInfoService.AddAsync(newItem, cancellationToken); if (newItem == null) { AssignToModelState(_userInfoService.Errors); return(ValidationProblem()); } return(CreatedAtAction(nameof(ItemByIdAsync), new { id = newItem.UserName }, null)); }
public async Task <ActionResult> UpdateItemAsync([FromBody] UserInfoDTO userInfo, CancellationToken cancellationToken) { var specFilter = new UserInfoFilterSpecification(userInfo.UserName); var rowCount = await _userInfoService.CountAsync(specFilter, cancellationToken); if (rowCount == 0) { throw new EntityNotFoundException(nameof(userInfo), userInfo.UserName); } var item = _mapper.Map <UserInfo>(userInfo); var result = await _userInfoService.UpdateAsync(item, cancellationToken); if (!result) { AssignToModelState(_userInfoService.Errors); return(ValidationProblem()); } return(CreatedAtAction(nameof(ItemByIdAsync), new { id = item.UserName }, null)); }