Example #1
0
        public async Task <Charge> AddAsync(Charge charge)
        {
            charge.Completed = await _chargeLifecycle.GetCompletedAsync(charge);

            using var context = _contextFactory.CreateDbContext();

            var oldValues = context.Entry(charge).GetDatabaseValues();
            var newValues = context.Entry(charge).CurrentValues;

            context.Charges.Add(charge);
            await context.SaveChangesAsync();

            await _noteService.AddEntityHistoryNoteAsync(oldValues, newValues);

            if (charge.ParentId is not null)
            {
                var parent = await GetAsync((int)charge.ParentId);

                await _noteService.AddChildParentHistoryNoteAsync(charge, parent);
            }

            return(charge);
        }