public async Task <SnapshotModel> AddSnapshot(string profileClientId, SnapshotModel snapshotModel) { var snapshot = _mapper.Map <Snapshot>(snapshotModel); await _snapshotRepository.RemovePricedItems(profileClientId); snapshot.ProfileClientId = profileClientId; await _snapshotRepository.AddSnapshots(new List <Snapshot>() { snapshot }); snapshot.StashTabs.Select(stashtab => { stashtab.SnapshotClientId = snapshot.ClientId; stashtab.SnapshotProfileClientId = profileClientId; return(stashtab); }).ToList(); await _snapshotRepository.AddStashtabs(snapshot.StashTabs.ToList()); snapshot.StashTabs.ForEach( stashtab => stashtab.PricedItems.Select(pricedItem => { pricedItem.StashtabClientId = stashtab.ClientId; pricedItem.SnapshotProfileClientId = profileClientId; return(stashtab); }).ToList()); await _snapshotRepository.AddPricedItems(snapshot.StashTabs.SelectMany(s => s.PricedItems).ToList()); return(_mapper.Map <SnapshotModel>(snapshot)); }
public async Task <SnapshotModel> AddSnapshot(string profileClientId, SnapshotModel snapshotModel) { var snapshot = _mapper.Map <Snapshot>(snapshotModel); await _snapshotRepository.RemovePricedItems(profileClientId); var profile = await _accountRepository.GetProfiles(profile => profile.ClientId == profileClientId) .Include(profile => profile.Snapshots) .AsNoTracking() .FirstAsync(); snapshot.ProfileId = profile.Id; await _snapshotRepository.AddSnapshots(new List <Snapshot>() { snapshot }); return(_mapper.Map <SnapshotModel>(snapshot)); }