public async Task WriteAsync(int portfolioId, Allocation allocation) { using (var context = Context()) { var eAllocation = await context .Allocations .Include(a => a.Proportions) .Where(a => a.PortfolioId == portfolioId && a.SymbolId == allocation.Symbol.Id) .FirstOrDefaultAsync(); if (eAllocation == null) { eAllocation = new AllocationEntity { PortfolioId = portfolioId, SymbolId = allocation.Symbol.Id, Proportions = new List <AllocationProportionEntity>() }; context.Allocations.Add(eAllocation); } context.AllocationProportions.RemoveRange(eAllocation.Proportions); eAllocation.Proportions = allocation.Proportions.Select(p => new AllocationProportionEntity().Assign(p)).ToList(); await context.SaveChangesAsync(); } }
public static Allocation ToDomain(AllocationEntity entity) { return(new Allocation { Id = entity.Id, Created = entity.Created, AccountId = entity.AccountId, Month = entity.Month, Days = entity.Days, Cost = entity.Cost, DayRate = entity.DayRate }); }
public static Allocation ConvertToDomain(this AllocationEntity entity) { return(ToDomain(entity)); }