public async Task <IEnumerable <ProductChangeNoteEntityBase> > GetProductChangeNotesAsync( Guid productId, CancellationToken cancellationToken) { using (var context = _dbContextProvider.GetNewDbContext()) { return(await context.Set <ProductChangeNoteEntityBase>() .AsNoTracking() .Where(entity => entity.ProductId == productId) .ToArrayAsync(cancellationToken)); } }
public async Task <ProductEntity> CreateProductAsync( ProductEntity productEntity, CancellationToken cancellationToken) { using (var context = _dbContextProvider.GetNewDbContext()) { var entry = context.Add(productEntity); await context.SaveChangesAsync(); return(entry.Entity); } }
public async Task <OrderEntity> CreateOrderAsync( OrderEntity orderEntity, CancellationToken cancellationToken) { using (var context = _dbContextProvider.GetNewDbContext()) { context.Add(orderEntity); await context.SaveChangesAsync(cancellationToken); orderEntity.Products = await _productRepository.GetProductsAsync( orderEntity.ProductIdCollection, cancellationToken); orderEntity.ProductIdCollection = orderEntity.Products.Select(entity => entity.Id); foreach (var productEntity in orderEntity.Products) { var relation = new OrderProductRelationEntity(); _mapper.Map(orderEntity, relation); _mapper.Map(productEntity, relation); context.Add(relation); } await context.SaveChangesAsync(cancellationToken); await _productChangeNoteRepository.CreateOrderCreatedProductChangeNotesAsync(orderEntity, cancellationToken); return(orderEntity); } }