public void DeleteAssetAllocations(Portfolio portfolio)
        {
            List <AssetAllocation> aas = AssetAllocations.Where(aa => aa.PortfolioId == portfolio.Id).ToList();

            AssetAllocations.RemoveRange(aas);
            SaveChanges();
        }
        public Portfolio CreatePortfolio(User user, string portfolioname, bool isSimulated, Tuple <string, AssetClass>[] tuples)
        {
            Portfolio portfolio = new Portfolio()
            {
                Name             = portfolioname,
                AssetAllocations = new List <AssetAllocation>(),
                UserId           = user.Id,
            };

            Portfolios.Add(portfolio);
            SaveChanges();

            foreach (var tuple in tuples)
            {
                AssetBase assetBase = GetAssetyBy(tuple.Item2, tuple.Item1);
                if (assetBase == null)
                {
                    assetBase = CreateAsset(tuple.Item2, tuple.Item1);
                }
                AssetAllocation assetAllocation = new AssetAllocation()
                {
                    Asset       = assetBase,
                    PortfolioId = portfolio.Id,
                };
                AssetAllocations.Add(assetAllocation);
                portfolio.AssetAllocations.Add(assetAllocation);
            }
            portfolio.UserId      = user.Id;
            portfolio.IsSimulated = true;
            Update(portfolio);
            return(portfolio);
        }
        public void Update(AssetAllocation allocation)
        {
            //TODO: FALTA CAMPO FECHA DE ACTUALIZACION

            AssetAllocations.Attach(allocation);
            Entry(allocation).State = EntityState.Modified;
            SaveChanges();
        }
 public AssetAllocation GetAssetAllocationBy(int assetAllocationId)
 {
     return(AssetAllocations
            .Include(aa => aa.Asset)
            .ThenInclude(asset => ((Option)asset).UnderlyingAsset)
            .Where(aa => aa.Id == assetAllocationId)
            .SingleOrDefault());
 }