public override async Task <int> HandleCommand(DeleteCaptionCommand request, CancellationToken cancellationToken) { Caption caption = null; if (request.Model == 0) { throw new BusinessException("Caption.NotSelected"); } else { caption = await captionQueries.GetByIdAsync(request.Model); if (caption == null) { throw new BusinessException("Caption.NotSelected"); } } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { caption.IsDeleted = true; caption.ModifiedDate = DateTime.Now; caption.ModifiedBy = request.LoginSession.Id; if (await captionRepository.UpdateAsync(caption) > 0) { rs = 0; } } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }
public override async Task <int> HandleCommand(UpdateCaptionCommand request, CancellationToken cancellationToken) { CaptionMultipleLanguage caption = null; if (request.Model == null || request.Model.Id == 0) { throw new BusinessException("Caption.NotExisted"); } else { caption = await captionQueries.GetByIdAsync(request.Model.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 { if (request.Model.Languages != null && request.Model.Languages.Count > 0) { foreach (var clang in request.Model.Languages) { if (!string.IsNullOrWhiteSpace(clang.Caption)) { if (clang.Id <= 0) { await captionLanguageRepository.AddAsync(clang); } else { await captionLanguageRepository.UpdateAsync(clang); } } else if (clang.Id > 0) { await captionLanguageRepository.DeleteAsync(clang.Id); } } } request.Model.ModifiedDate = DateTime.Now; request.Model.ModifiedBy = request.LoginSession.Id; if (await captionRepository.UpdateAsync(request.Model) > 0) { rs = 0; } } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }