示例#1
0
 public void Hydrate(Portfolio.Data.Model.Account obj)
 {
     this.AccountId = obj.AccountId;
     this.Name      = obj.Name;
     foreach (var item in obj.Investments)
     {
         this.Investments.Add(new Investment(item));
     }
 }
示例#2
0
        public async Task <List <Investment> > GetAccount(string account, string symbol = null, string collection = null, decimal?quantity = null)
        {
            if (string.IsNullOrWhiteSpace(account))
            {
                return(null);
            }

            var userName = User.Identity.Name;

            var user = await _portfolioService.GetUser(userName);

            if (user != null)
            {
                if (!string.IsNullOrWhiteSpace(account))
                {
                    // check account
                    var model = user.Accounts.Where(x => x.Url == account).FirstOrDefault();

                    // create account if necessary
                    if (model == null)
                    {
                        model = new Portfolio.Data.Model.Account()
                        {
                            Owner = user, Name = account, Url = account.ToLower()
                        };
                        _portfolioContext.Accounts.Add(model);
                        _portfolioContext.SaveChanges();
                    }

                    model = _portfolioContext.Accounts
                            .Where(x => x.Url == account)
                            .Include(x => x.Investments).ThenInclude(y => y.Stock)
                            //.Include(x => x.Collections)
                            .FirstOrDefault();

                    if (!string.IsNullOrWhiteSpace(symbol))
                    {
                        var stock = await this._portfolioService.GetStock(symbol);

                        if (stock != null)
                        {
                            var investment = new Portfolio.Data.Model.Investment()
                            {
                                Account = model, Quantity = quantity ?? 1, Stock = stock
                            };
                            _portfolioContext.Investments.Add(investment);
                            _portfolioContext.SaveChanges();
                        }
                    }

                    var list = model.Investments.Select(x => new Investment(x)).ToList();

                    return(list);
                }
            }
            return(null);
        }
示例#3
0
 public Account(Portfolio.Data.Model.Account obj) : this()
 {
     this.Hydrate(obj);
 }