public virtual async Task <IActionResult> Update(Guid id, TViewModel entityViewModel) { if (id == Guid.Empty) { return(BadRequest()); } if (id != entityViewModel.Id) { return(BadRequest()); } using (IDbContextTransaction? transaction = await _unitOfWork.BeginTransactionAsync()) { try { TEntity?entity = _mapper.Map <TViewModel, TEntity>(entityViewModel); if (entity is null) { return(UnprocessableEntity()); } if (await _serviceAsync.UpdateItem(id, entity) is null) { _unitOfWork.RollbackTransaction(); } await _unitOfWork.CommitTransactionAsync(transaction); } catch (DbUpdateConcurrencyException) { if (!await EntityExists(id)) { return(NotFound()); } else { throw; } } catch (Exception ex) { _unitOfWork.RollbackTransaction(); throw new Exception(ex.Message); } } return(Ok()); }