public async Task <int> CreateAsync(PackingModel model) { using (var transaction = dbContext.Database.BeginTransaction()) { try { do { model.Code = CodeGenerator.Generate(); }while (dbSet.Any(d => d.Code.Equals(model.Code))); packingLogic.CreateModel(model); var row = await dbContext.SaveChangesAsync(); if (row > 0) { await CreateProduct(model); } transaction.Commit(); return(row); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
public async Task <int> CreateAsync(PackingModel model) { do { model.Code = CodeGenerator.Generate(); }while (dbSet.Any(d => d.Code.Equals(model.Code))); packingLogic.CreateModel(model); var row = await dbContext.SaveChangesAsync(); if (row > 0) { await packingLogic.CreateProduct(model); } return(row); }