public async Task <IEnumerable <Domain.Models.Stock> > GetAllByMarketAsync(string market) { using var context = new mmpproject2Context(_contextOptions); var stocks = await context.Stocks.Where(s => s.Market == market).ToListAsync(); return(stocks.Select(Mapper.MapStock)); }
public async Task <Domain.Models.Stock> GetAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var stock = await context.Stocks.FirstAsync(s => s.Id == id); return(Mapper.MapStock(stock)); }
public async Task <Domain.Models.Trade> AddAsync(Domain.Models.Trade trade, Domain.Models.Portfolio portfolio) { if (trade.Id != 0) { throw new ArgumentException("Trade already exists."); } using var context = new mmpproject2Context(_contextOptions); var dbPortfolio = await context.Portfolios .Include(p => p.Trades) .FirstAsync(p => p.Id == portfolio.Id); var newTrade = Mapper.MapTrade(trade); dbPortfolio.Trades.Add(newTrade); context.Trades.Add(newTrade); await context.SaveChangesAsync(); var created = await context.Trades .Include(t => t.Stock) .FirstAsync(t => t.Id == newTrade.Id); return(Mapper.MapTrade(created)); }
public async Task <Domain.Models.Stock> GetAsync(string symbol) { using var context = new mmpproject2Context(_contextOptions); var stock = await context.Stocks.Where(s => s.Symbol.Contains(symbol)).FirstAsync(); return(Mapper.MapStock(stock)); }
public async Task DeleteAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var dbStock = await context.Stocks.FirstAsync(s => s.Id == id); context.Remove(dbStock); await context.SaveChangesAsync(); }
public async Task DeleteAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var tr = await context.Trades.FirstAsync(t => t.Id == id); context.Remove(tr); await context.SaveChangesAsync(); }
public async Task <Domain.Models.Asset> GetAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var asset = await context.Assets .Include(a => a.Stock) .FirstAsync(a => a.Id == id); return(Mapper.MapAsset(asset)); }
public async Task <IEnumerable <Domain.Models.Trade> > GetAllAsync(Domain.Models.Portfolio portfolio) { using var context = new mmpproject2Context(_contextOptions); var trades = await context.Trades.Where(t => t.PortfolioId == portfolio.Id) .Include(t => t.Stock) .ToListAsync(); return(trades.Select(Mapper.MapTrade)); }
public async Task DeleteAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var user = await context.Users.FindAsync(id); context.Remove(user); await context.SaveChangesAsync(); }
public async Task DeleteAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var ast = await context.Assets.FirstAsync(a => a.Id == id); context.Remove(ast); await context.SaveChangesAsync(); }
public async Task <Domain.Models.User> GetAsync(string email) { using var context = new mmpproject2Context(_contextOptions); var user = await context.Users.Where(u => u.Email.Contains(email)) .Include(u => u.Portfolios) .FirstAsync(); return(Mapper.MapUser(user)); }
public async Task <Domain.Models.User> GetAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var user = await context.Users .Include(u => u.Portfolios) .FirstAsync(u => u.Id == id); return(Mapper.MapUser(user)); }
public async Task <IEnumerable <Domain.Models.Asset> > GetAllAsync(Domain.Models.Portfolio portfolio) { using var context = new mmpproject2Context(_contextOptions); var assets = await context.Assets.Where(a => a.PortfolioId == portfolio.Id) .Include(a => a.Stock) .ToListAsync(); return(assets.Select(Mapper.MapAsset)); }
public async Task DeleteAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var portfolio = await context.Portfolios.FindAsync(id); context.Remove(portfolio); await context.SaveChangesAsync(); }
public async Task <IEnumerable <Domain.Models.User> > GetAllAsync() { using var context = new mmpproject2Context(_contextOptions); var users = await context.Users .Include(u => u.Portfolios) .ToListAsync(); return(users.Select(Mapper.MapUser)); }
public async Task <Domain.Models.Trade> GetAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var trade = await context.Trades .Include(t => t.Stock) .FirstAsync(t => t.Id == id); return(Mapper.MapTrade(trade)); }
public async Task <IEnumerable <Domain.Models.User> > GetAllAsync(string firstName, string lastName) { using var context = new mmpproject2Context(_contextOptions); var users = await context.Users .Where(u => u.FirstName == firstName && u.LastName == lastName) .Include(u => u.Portfolios) .ToListAsync(); return(users.Select(Mapper.MapUser)); }
public async Task UpdateAsync(Domain.Models.User user) { using var context = new mmpproject2Context(_contextOptions); var current = await context.Users.FindAsync(user.Id); var updated = Mapper.MapUser(user); context.Entry(current).CurrentValues.SetValues(updated); await context.SaveChangesAsync(); }
public async Task UpdateAsync(Domain.Models.Stock stock) { using var context = new mmpproject2Context(_contextOptions); var current = await context.Stocks.FirstAsync(s => s.Symbol == stock.Symbol && s.Market == stock.Market); var updated = Mapper.MapStock(stock); context.Entry(current).CurrentValues.SetValues(updated); await context.SaveChangesAsync(); }
public async Task <IEnumerable <Domain.Models.Portfolio> > GetAllAsync() { using var context = new mmpproject2Context(_contextOptions); var portfolios = await context.Portfolios .Include(p => p.Assets) .ThenInclude(a => a.Stock) .Include(p => p.Trades) .ThenInclude(t => t.Stock) .ToListAsync(); return(portfolios.Select(Mapper.MapPortfolio)); }
public async Task UpdateAsync(Domain.Models.Trade trade) { using var context = new mmpproject2Context(_contextOptions); var current = await context.Trades.FirstAsync(t => t.Id == trade.Id); var updated = Mapper.MapTrade(trade); updated.PortfolioId = current.PortfolioId; context.Entry(current).CurrentValues.SetValues(updated); await context.SaveChangesAsync(); }
public async Task UpdateAsync(Domain.Models.Portfolio portfolio) { using var context = new mmpproject2Context(_contextOptions); var current = await context.Portfolios.FindAsync(portfolio.Id); var updated = Mapper.MapPortfolio(portfolio); updated.UserId = current.UserId; context.Entry(current).CurrentValues.SetValues(updated); await context.SaveChangesAsync(); }
public async Task <Domain.Models.Portfolio> GetAsync(int id) { using var context = new mmpproject2Context(_contextOptions); var portfolio = await context.Portfolios .Include(p => p.Assets) .ThenInclude(a => a.Stock) .Include(p => p.Trades) .ThenInclude(t => t.Stock) .FirstAsync(p => p.Id == id); return(Mapper.MapPortfolio(portfolio)); }
public async Task UpdateAsync(Domain.Models.Asset asset) { using var context = new mmpproject2Context(_contextOptions); var current = await context.Assets.FirstAsync(a => a.Id == asset.Id); var updated = Mapper.MapAsset(asset); updated.PortfolioId = current.PortfolioId; context.Entry(current).CurrentValues.SetValues(updated); await context.SaveChangesAsync(); }
public async Task GetAssetbyID_Database_test(int id) { using var connection = Database_init(); var options = new DbContextOptionsBuilder <mmpproject2Context>().UseSqlite(connection).Options; using var context = new mmpproject2Context(options); var repo = new AssetRepository(options); var asset = await repo.GetAsync(id); var assetActual = context.Assets.Where(x => x.Id == id).Single(); Assert.Equal(asset.Id, assetActual.Id); Assert.Equal(asset.Quantity, assetActual.Quantity); }
public async Task GetPortfoliobyID_Database_test(int id) { using var connection = Database_init(); var options = new DbContextOptionsBuilder <mmpproject2Context>().UseSqlite(connection).Options; using var context = new mmpproject2Context(options); var repo = new PortfolioRepository(options); var portfolio = await repo.GetAsync(id); var portfolioActual = context.Portfolios.Where(x => x.Id == id).Single(); Assert.Equal(portfolio.Id, portfolioActual.Id); Assert.Equal(portfolio.Name, portfolioActual.Name); Assert.Equal(portfolio.Funds, portfolioActual.Funds); }
public async Task <Domain.Models.User> AddAsync(Domain.Models.User user) { if (user.Id != 0) { throw new ArgumentException("User already exists."); } using var context = new mmpproject2Context(_contextOptions); var newUser = Mapper.MapUser(user); await context.Users.AddAsync(newUser); await context.SaveChangesAsync(); return(Mapper.MapUser(newUser)); }
public async Task <Domain.Models.Stock> AddAsync(Domain.Models.Stock stock) { if (stock.Id != 0) { throw new ArgumentException("Stock already exists."); } using var context = new mmpproject2Context(_contextOptions); var newStock = Mapper.MapStock(stock); await context.Stocks.AddAsync(newStock); await context.SaveChangesAsync(); return(Mapper.MapStock(newStock)); }
public async Task GetTradebyID_Database_test(int id) { using var connection = Database_init(); var options = new DbContextOptionsBuilder <mmpproject2Context>().UseSqlite(connection).Options; using var context = new mmpproject2Context(options); var repo = new TradeRepository(options); var trade = await repo.GetAsync(id); var tradeActual = context.Trades.Where(x => x.Id == id).Single(); Assert.Equal(trade.Id, tradeActual.Id); Assert.Equal(trade.Price, tradeActual.Price); Assert.Equal(trade.Quantity, tradeActual.Quantity); }
public async Task GetStockbySymbol_Database_test(string symbol) { using var connection = Database_init(); var options = new DbContextOptionsBuilder <mmpproject2Context>().UseSqlite(connection).Options; using var context = new mmpproject2Context(options); var repo = new StockRepository(options); var stock = await repo.GetAsync(symbol); var stockActual = context.Stocks.Where(x => x.Symbol == symbol).Single(); Assert.Equal(stock.Name, stockActual.Name); Assert.Equal(stock.Symbol, stockActual.Symbol); Assert.Equal(stock.Market, stockActual.Market); }