public override async Task <int> HandleCommand(InsertProductionCommand request, CancellationToken cancellationToken) { var id = 0; var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id); if (company == null) { throw new BusinessException("Common.NoPermission"); } using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { var gTIN = await gTINService.InsertOrUpdateGTINAsync(company.Id, request.Model.GTIN, request.LoginSession); request.Model.GTINId = gTIN.Id; request.Model.PartnerId = company.Id; request.Model.CreatedDate = DateTime.Now; request.Model.CreatedBy = request.LoginSession.Id; request.Model.ModifiedDate = DateTime.Now; request.Model.ModifiedBy = request.LoginSession.Id; id = await productionRepository.AddAsync(request.Model); } catch (Exception ex) { throw ex; } finally { if (id > 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(id); }
public override async Task <GTINInformation> HandleCommand(InsertOrUpdateGTINCommand request, CancellationToken cancellationToken) { var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id); if (company == null) { throw new BusinessException("Common.NoPermission"); } GTIN gTIN = (await gTINService.InsertOrUpdateGTINAsync(company.Id, request.Model, request.LoginSession)).ToInformation(); if (gTIN == null) { throw new BusinessException("Common.TaskFailed"); } var rs = gTIN.ToInformation(); rs.Code = await gTINService.GetCodeGTINAsync(gTIN); return(rs); }
public override async Task <int> HandleCommand(UpdateProductionCommand request, CancellationToken cancellationToken) { Production production = null; if (request.Model == null || request.Model.Id == 0) { throw new BusinessException("Production.NotExisted"); } else { production = await productionQueries.GetByIdAsync(request.Model.Id); if (production == null) { throw new BusinessException("Production.NotExisted"); } } var company = await companyQueries.GetByUserIdAsync(request.LoginSession.Id); if (company == null || production.PartnerId != company.Id) { throw new BusinessException("Common.NoPermission"); } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { var gTIN = await gTINService.InsertOrUpdateGTINAsync(company.Id, request.Model.GTIN, request.LoginSession); request.Model.GTINId = gTIN.Id; request.Model.PartnerId = company.Id; request.Model.ModifiedDate = DateTime.Now; request.Model.ModifiedBy = request.LoginSession.Id; if (await productionRepository.UpdateAsync(request.Model) > 0) { rs = 0; } } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }