Пример #1
0
        public static async Task Delete(WineDto wineToDelete)
        {
            await using MyWineCellarDbContext dbContext   = new MyWineCellarDbContext();
            await using IDbContextTransaction transaction = await dbContext.Database.BeginTransactionAsync();

            Wine wineDeleted = dbContext.Wines.Remove(Mapper.Map <Wine>(wineToDelete)).Entity;
            await dbContext.SaveChangesAsync();

            if (wineToDelete.Id.Equals(wineDeleted.Id))
            {
                await transaction.CommitAsync();
            }
        }
Пример #2
0
        public static async Task Add(WineDto wineToAdd)
        {
            await using MyWineCellarDbContext dbContext   = new MyWineCellarDbContext();
            await using IDbContextTransaction transaction = await dbContext.Database.BeginTransactionAsync();

            Wine wineAdded = (await dbContext.Wines.AddAsync(Mapper.Map <Wine>(wineToAdd))).Entity;
            await dbContext.SaveChangesAsync();

            if (wineAdded.Id > 0)
            {
                await transaction.CommitAsync();
            }
        }