public async Task AddAsync(ImageEntity entity) { logger.LogDebug($"Attempting to Add a new image with id {entity.Id}."); using (var transaction = await dbContext.Database.BeginTransactionAsync()) { await dbContext.Images.AddAsync(entity); await dbContext.SaveChangesAsync(); transaction.Commit(); } logger.LogInformation($"Sucessfully added Image with id {entity.Id}"); }
public async virtual Task AddAsync(T entity) { logger.LogInformation($"Attempting to add new {entityName}."); using (var transaction = await dbContext.Database.BeginTransactionAsync()) { entityDao.Add(entity); await dbContext.SaveChangesAsync(); transaction.Commit(); } logger.LogInformation($"Successfully added {entityName} with id {entity.Id}."); }
public async Task AddAsync(ProductEntity entity, List <ProductPriceEntity> priceEntities, List <ProductTranslationEntity> translationEntities) { logger.LogDebug($"Attempting to add new product"); // Check if all provided currencies are supported // Later todo: Fetch from DB foreach (var priceEntity in priceEntities) { if (!i18nService.SupportedCurrencies.Any(x => x.Code == priceEntity.CurrencyId)) { throw new ArgumentException($"Currency {priceEntity.CurrencyId} is not supported."); } } // Check if all provided translations are supported // Later todo: Fetch from DB foreach (var translationEntity in translationEntities) { if (!i18nService.SupportedLanguages.Any(x => x.Code == translationEntity.LanguageId)) { throw new ArgumentException($"Language {translationEntity.LanguageId} is not supported."); } } using (var transaction = await dbContext.Database.BeginTransactionAsync()) { // Persist ProductEntity first dbContext.Products.Add(entity); await dbContext.SaveChangesAsync(); // Persist price entities priceEntities.ForEach(x => x.ProductId = entity.Id); dbContext.ProductPrices.AddRange(priceEntities); // Persist translation entities translationEntities.ForEach(x => x.ProductId = entity.Id); dbContext.ProductTranslations.AddRange(translationEntities); await dbContext.SaveChangesAsync(); transaction.Commit(); } }
public async Task AddOrderAsync(OrderEntity entity) { await dbContext.Orders.AddRangeAsync(entity); await dbContext.SaveChangesAsync(); }
public async Task AddAsync(WishlistEntity entity) { await dbContext.Wishlists.AddAsync(entity); await dbContext.SaveChangesAsync(); }