public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken) { if (request.Caption == null || request.Caption.Id == 0) { throw new BusinessException("Caption.NotExisted"); } var caption = await languageQueries.GetCaption(request.Caption.Id); if (caption == null) { throw new BusinessException("Caption.NotExisted"); } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { languageRepository.JoinTransaction(conn, trans); caption.Type = request.Caption.Type; caption.DefaultCaption = request.Caption.DefaultCaption; caption.Languages = request.Caption.Languages; if (await languageRepository.UpdateCaption(caption) != 0) { return(rs); } await languageRepository.DeleteCaptionLanguages(caption.Id); foreach (var language in caption.Languages) { if (await languageRepository.AddCaptionLanguage(language) == 0) { return(rs); } } rs = 0; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }