示例#1
0
        public async Task SetAsync(Guid accountId, AccountFlagType type, CancellationToken ct)
        {
            var flag = await _storage.AccountFlags
                       .FirstOrDefaultAsync(x => x.Type == type && x.AccountId == accountId, ct);

            if (flag != null)
            {
                flag.SetDateTime = DateTime.UtcNow;

                _storage.Update(flag);
            }
            else
            {
                flag = new AccountFlag
                {
                    Id          = Guid.NewGuid(),
                    AccountId   = accountId,
                    Type        = type,
                    SetDateTime = DateTime.UtcNow
                };

                await _storage.AddAsync(flag, ct);
            }

            await _storage.SaveChangesAsync(ct);
        }
示例#2
0
        private async Task SetAsync(
            Guid userId,
            Guid accountId,
            Action <AccountSetting> setFunction,
            CancellationToken ct)
        {
            var setting = await _storage.AccountSettings
                          .FirstOrDefaultAsync(x => x.AccountId == accountId, ct);

            if (setting == null)
            {
                setting = new AccountSetting();
                var change = setting.CreateWithLog(userId, x =>
                {
                    x.Id        = Guid.NewGuid();
                    x.AccountId = accountId;
                    setFunction(x);
                    x.CreateDateTime = DateTime.UtcNow;
                });

                await _storage.AddAsync(setting, ct);

                await _storage.AddAsync(change, ct);
            }
            else
            {
                var change = setting.UpdateWithLog(userId, x =>
                {
                    setFunction(x);
                    x.ModifyDateTime = DateTime.UtcNow;
                });

                _storage.Update(setting);
                await _storage.AddAsync(change, ct);
            }

            await _storage.SaveChangesAsync(ct);
        }