public override async Task <int> HandleCommand(InsertWardCommand request, CancellationToken cancellationToken) { var id = 0; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { request.Model.CreatedDate = DateTime.Now; request.Model.CreatedBy = request.LoginSession.Id; request.Model.ModifiedDate = DateTime.Now; request.Model.ModifiedBy = request.LoginSession.Id; id = await wardRepository.AddAsync(request.Model); } catch (Exception ex) { throw ex; } finally { if (id > 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(id); }