public async Task <APIResult> Get(int id) { return(new APIResult() { Result = 0, Data = await seedQueries.GetById(id) }); }
public override async Task <int> HandleCommand(DeleteCommand request, CancellationToken cancellationToken) { var seed = await seedQueries.GetById(request.Id); if (seed == null) { throw new BusinessException("Seed.NotExisted"); } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { seed.IsDeleted = true; seed = UpdateBuild(seed, request.LoginSession); if (await seedRepository.Update(seed) > 0) { rs = 0; } } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }
public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken) { if (request.Seed == null || request.Seed.Id == 0) { throw new BusinessException("Seed.NotExisted"); } var seed = await seedQueries.GetById(request.Seed.Id); if (seed == null) { throw new BusinessException("Seed.NotExisted"); } if (request.Seed.ProductId > 0) { var product = await WebHelper.HttpGet <ProductViewModel>(GlobalConfiguration.APIGateWayURI, $"{AppUrl.GetProductById}?productId={request.Seed.ProductId}", request.LoginSession.AccessToken, request.LoginSession.LanguageCode); if (product == null) { throw new BusinessException("Product.NotExisted"); } } else { throw new BusinessException("Product.NotExisted"); } var rs = -1; using (var conn = DALHelper.GetConnection()) { conn.Open(); using (var trans = conn.BeginTransaction()) { try { request.Seed.CreatedDate = seed.CreatedDate; request.Seed.CreatedBy = seed.CreatedBy; request.Seed = UpdateBuild(request.Seed, request.LoginSession); request.Seed.Code = string.IsNullOrWhiteSpace(seed.Code) ? (await storageQueries.GenarateCodeAsync(StorageKeys.SeedCode)) : seed.Code; rs = await seedRepository.Update(request.Seed); if (rs == 0) { return(-1); } rs = 0; } catch (Exception ex) { throw ex; } finally { if (rs == 0) { trans.Commit(); } else { try { trans.Rollback(); } catch { } } } } } return(rs); }