public async Task DeleteAsync(Guid?processId) { if (processId == null) { return; } var processEntity = await _processRepository.GetByIdAsync(processId.Value); if (processEntity == null) { throw new NotFoundException("ProcessId", Messaging.NotFoundProcess); } await _processRepository.DeleteAsync(processEntity); }
public override async Task <int> HandleCommand(DeleteProcessCommand request, CancellationToken cancellationToken) { Process process = null; if (request.Model == 0) { throw new BusinessException("Process.NotSelected"); } else { process = await processQueries.GetByIdAsync(request.Model); if (process == null) { throw new BusinessException("Process.NotSelected"); } } var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id); if (company == null || process.PartnerId != company.Id) { throw new BusinessException("Common.NoPermission"); } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { if (process.IsNew) { if (await processRepository.DeleteAsync(process.Id) > 0) { rs = 0; } } else { process.IsDeleted = true; process.ModifiedDate = DateTime.Now; process.ModifiedBy = request.LoginSession.Id; if (await processRepository.UpdateAsync(process) > 0) { rs = 0; } } } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }