public async Task <ProcessInformation> NewProcessAsync(int partnerId, UserSession session) { var process = new Process(); process.Code = await GenerateTraceCodeAsync(); process.PartnerId = partnerId; process.IsUsed = true; process.IsNew = true; process.ModifiedDate = DateTime.Now; process.ModifiedBy = session.Id; process.CreatedDate = DateTime.Now; process.CreatedBy = session.Id; var id = await _processRepository.AddAsync(process); return(await _processQueries.GetByIdAsync(id)); }
public override async Task <ProcessInformation> HandleCommand(GetByIdProcessCommand request, CancellationToken cancellationToken) { var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id); if (company == null) { throw new BusinessException("Common.NoPermission"); } var rs = await processQueries.GetByIdAsync(request.Model); if (rs == null) { throw new BusinessException("Process.NotExist"); } if (rs.Production?.GTIN != null) { rs.Production.GTIN.Code = await gTINService.GetCodeGTINAsync(rs.Production.GTIN); } return(rs); }
public override async Task <int> HandleCommand(UpdateProcessCommand request, CancellationToken cancellationToken) { Process process = null; if (request.Model == null || request.Model.Id == 0) { throw new BusinessException("Process.NotExisted"); } else { process = await processQueries.GetByIdAsync(request.Model.Id); if (process == null) { throw new BusinessException("Process.NotExisted"); } } 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 { request.Model.IsNew = false; request.Model.PartnerId = company.Id; request.Model.ModifiedDate = DateTime.Now; request.Model.ModifiedBy = request.LoginSession.Id; if (await processRepository.UpdateAsync(request.Model) > 0) { rs = 0; } } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }