コード例 #1
0
 public Task <int> AddPolicyDocument(IDbTransaction dbTransaction, int policyId, Guid documentId)
 {
     _logger.LogInformation($"Adding document with Id '{documentId}' to policy with Id '{policyId}'...");
     return(_dbContext.AddPolicyDocumentAsync(dbTransaction, policyId, documentId));
 }
コード例 #2
0
        public async void InsertPolicyDocumentAsync()
        {
            _logger.LogInformation("AddPolicyDocumentAsync...");
            {
                var newItem = A.New <Policy>();
                using (var dbTransaction = await _dbConnectionFactory.BeginUserTransactionAsync(UserId))
                {
                    try
                    {
                        var result = await _policiesDbContext.InsertAsync(dbTransaction, newItem);

                        dbTransaction.Commit();

                        Assert.NotNull(result);
                        Assert.NotEqual(0, result.PolicyId);
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        throw;
                    }
                }
            }

            Policy existingPolicy;

            using (var dbConnection = await _dbConnectionFactory.OpenUserConnectionAsync(UserId))
            {
                var pageRequest = new PageRequest()
                {
                    PageIndex = 0,
                    PageSize  = 1,
                    SortBy    = "PolicyId",
                    SortOrder = SortOrders.DESC
                };
                existingPolicy = (await _policiesDbContext.GetPageAsync(dbConnection, pageRequest)).Items.First();
            }

            {
                var newItem = new Document()
                {
                    Name = $"DATA_ACCESS_LAYER_TEST_{DateTime.Now:yyyyMMddHHmmssfff}.jpg",
                    Type = "jpg",
                    Data = await File.ReadAllBytesAsync("./TestFiles/Test.jpg")
                };


                using (var dbTransaction = await _dbConnectionFactory.BeginUserTransactionAsync(UserId))
                {
                    try
                    {
                        var result = await _dbContext.InsertDocumentAsync(dbTransaction, newItem);

                        Assert.NotNull(result);
                        Assert.NotEqual(newItem.DocumentId, result.DocumentId);


                        await _dbContext.AddPolicyDocumentAsync(dbTransaction, existingPolicy.PolicyId,
                                                                result.DocumentId);

                        dbTransaction.Commit();
                    }
                    catch
                    {
                        dbTransaction.Rollback();
                        throw;
                    }
                }
            }
        }