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));
        }
Exemple #2
0
        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 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();
        }
Exemple #4
0
        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 portfolio = await context.Portfolios.FindAsync(id);

            context.Remove(portfolio);

            await context.SaveChangesAsync();
        }
        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();
        }
Exemple #7
0
        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 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();
        }
Exemple #9
0
        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 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();
        }
Exemple #12
0
        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 <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.Portfolio> AddAsync(Domain.Models.Portfolio portfolio, Domain.Models.User user)
        {
            if (portfolio.Id != 0)
            {
                throw new ArgumentException("Portfolio already exists.");
            }

            using var context = new mmpproject2Context(_contextOptions);
            var dbUser = await context.Users
                         .Include(u => u.Portfolios)
                         .FirstOrDefaultAsync(u => u.Id == user.Id);

            var newPortfolio = Mapper.MapPortfolio(portfolio);

            dbUser.Portfolios.Add(newPortfolio);
            context.Portfolios.Add(newPortfolio);

            await context.SaveChangesAsync();

            return(Mapper.MapPortfolio(newPortfolio));
        }
Exemple #15
0
        public async Task <Domain.Models.Asset> AddAsync(Domain.Models.Asset asset, Domain.Models.Portfolio portfolio)
        {
            if (asset.Id != 0)
            {
                throw new ArgumentException("Asset already exists.");
            }
            using var context = new mmpproject2Context(_contextOptions);
            var dbPortfolio = await context.Portfolios
                              .Include(p => p.Assets)
                              .FirstAsync(p => p.Id == portfolio.Id);

            var newAsset = Mapper.MapAsset(asset);

            dbPortfolio.Assets.Add(newAsset);
            context.Assets.Add(newAsset);

            await context.SaveChangesAsync();

            var created = await context.Assets
                          .Include(a => a.Stock)
                          .FirstAsync(a => a.Id == newAsset.Id);

            return(Mapper.MapAsset(created));
        }