public async Task <bool> CreateProductAsync(CreateProductRequestBM createProductRequest) { using (IDbContextTransaction transaction = await dbContext.Database.BeginTransactionAsync()) { try { await dbContext.Product.AddAsync(new Product() { Barcode = createProductRequest.Barcode, CategoryId = createProductRequest.CategoryId, ManufacturerId = createProductRequest.ManufacturerId }); await dbContext.ProductName.AddRangeAsync( createProductRequest.Name.Select(x => new ProductName() { Barcode = createProductRequest.Barcode, LanguageCode = x.Key, LocalizedName = x.Value }) ); await dbContext.SaveChangesAsync(); transaction.Commit(); } catch (Exception) { transaction.Rollback(); return(false); } } return(true); }
public async Task DeleteAsync(ManufacturerBM manufacturer) { dbContext.Manufacturer.Remove( await dbContext.Manufacturer.SingleAsync(x => x.Id == manufacturer.ManufacturerId) ); await dbContext.SaveChangesAsync(); }