コード例 #1
0
ファイル: ChargeService.cs プロジェクト: dac5197/battery
        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);
        }