public override async Task <int> HandleCommand(DeleteWardCommand request, CancellationToken cancellationToken) { Ward ward = null; if (request.Model == 0) { throw new BusinessException("Ward.NotSelected"); } else { ward = await wardQueries.GetByIdAsync(request.Model); if (ward == null) { throw new BusinessException("Ward.NotSelected"); } } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { ward.IsDeleted = true; ward.ModifiedDate = DateTime.Now; ward.ModifiedBy = request.LoginSession.Id; if (await wardRepository.UpdateAsync(ward) > 0) { rs = 0; } } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }