Ejemplo n.º 1
0
        public async Task SellShares(ulong userId, ulong guildId, string symbol, long shares, decimal price)
        {
            // position guaranteed to already exist
            Investment position = await _context.Investments.AsQueryable().SingleOrDefaultAsync(x => x.UserId == userId && x.GuildId == guildId && x.Symbol == symbol) ?? new Investment(userId, guildId, symbol, -shares);

            position.Shares -= shares;
            position.Trades.Add(new Trade(-shares, price));
            await _currency.AddInvestingAsync(userId, guildId, price *shares);

            await _context.SaveChangesAsync();
        }