public async Task <AssetClass> WriteAsync(int portfolioId, string name, Rate?target) { using (var context = Context()) { var eAssetClass = await context .AssetClasses .Where(c => c.PortfolioId == portfolioId && c.Name == name) .FirstOrDefaultAsync(); if (eAssetClass == null) { eAssetClass = new AssetClassEntity { PortfolioId = portfolioId, Name = name }; context.AssetClasses.Add(eAssetClass); } eAssetClass.Target = target; await context.SaveChangesAsync(); return(eAssetClass.ToModel()); } }
public async Task <AssetClass> ReadCashByPortfolioIdAsync(int portfolioId) { using (var context = Context()) { var assetClass = await ReadByAsync(c => c.PortfolioId == portfolioId && c.Name == Balance.Cash); if (assetClass == null) { var eAssetClass = new AssetClassEntity { PortfolioId = portfolioId, Name = Balance.Cash }; context.AssetClasses.Add(eAssetClass); assetClass = eAssetClass.ToModel(); } return(assetClass); } }