Пример #1
0
        public async Task ClearC2FK()
        {
            using (var db = new SageDb("Db"))
            {
                var docsToClear = await db.C21Documents.Where(x => x.status == -2).ToListAsync();

                if (docsToClear != null && docsToClear.Count > 0)
                {
                    await db.BeginTransactionAsync();

                    try
                    {
                        await db.C21Documents.Where(d => d.status == -2).DeleteAsync();

                        await db.C21AccountingRecords.Where(r => docsToClear.Select(d => (int?)d.id).ToList().Contains(r.dokId)).DeleteAsync();

                        await db.C21VatRegisters.Where(v => docsToClear.Select(d => (int?)d.id).ToList().Contains(v.dokId)).DeleteAsync();

                        await db.CommitTransactionAsync();
                    }
                    catch
                    {
                        await db.RollbackTransactionAsync();
                    }
                }
            }
        }
Пример #2
0
        public async Task AddDocumentAggregate(C21DocumentAggregate documentAggregate)
        {
            documentAggregate.RenumberDocumentId(await GetNextDocumentId(50), await GetNextAccountRecordtId(50), await GetNextVatRegistertId(50));
            if (documentAggregate != null)
            {
                using (var db = new SageDb("Db"))
                {
                    await db.BeginTransactionAsync();

                    try
                    {
                        await db.InsertAsync(documentAggregate.Document);

                        await db.BulkCopyAsync(documentAggregate.VatRegisters);

                        await db.BulkCopyAsync(documentAggregate.AccountingRecords);

                        await db.CommitTransactionAsync();
                    }
                    catch (Exception ex)
                    {
                        await db.RollbackTransactionAsync();

                        throw ex;
                    }
                }
            }
        }