Beispiel #1
0
        public async Task StartAsync(string user, decimal balance, CancellationToken cancellationToken = default)
        {
            if (_userStorage.Exists(user) == false)
            {
                throw new NoUserDefinedException($"System has no user with specified username `{user}`.");
            }

            if (Current is not null)
            {
                throw new MultipleSessionOpenedException("Session is already opened.");
            }

            var session = new Session
            {
                Started        = DateTime.UtcNow,
                InitialBalance = balance,
                UserName       = user
            };
            await _dbContext.Sessions.AddAsync(session, cancellationToken);

            await _dbContext.SaveChangesAsync(cancellationToken);
        }