入库任务-仓储

This commit is contained in:
tongfei
2023-10-27 11:25:05 +08:00
parent c2ae0b8c52
commit b4f0f6783b
3 changed files with 133 additions and 0 deletions

View File

@@ -146,5 +146,67 @@ namespace WMS.Web.Repositories
}
}
/// <summary>
/// 批量修改
/// </summary>
/// <param name="entitys"></param>
/// <returns></returns>
public async Task<bool> UpdateRange(List<InStockTask> entitys, bool isTransaction = true)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
{
try
{
List<int> list = entitys.Select(s => s.Id).ToList();
var res = await _context.InStockTask.Include(x => x.Details).Where(f => list.Contains(f.Id)).ToListAsync();
_mapper.Map(entitys, res);
await _context.SaveChangesAsync();
if (_transaction != null)
_transaction.Commit();
}
catch (Exception ex)
{
if (_transaction != null)
_transaction.Rollback();
return false;
}
return true;
}
}
/// <summary>
/// 修改
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public async Task<InStockTask> Update(InStockTask entity,bool isTransaction = true)
{
IDbContextTransaction _transaction = null;
if (isTransaction)
_transaction = _context.Database.BeginTransaction();
try
{
var model = await _context.InStockTask
.AsNoTracking()
.Include(s => s.Details)
.FirstOrDefaultAsync(f => f.Id == entity.Id);
if (model == null)
return null;
_mapper.Map(entity, model);
await _context.SaveChangesAsync();
if (_transaction != null)
_transaction.Commit();
return model;
}
catch (Exception)
{
if (_transaction != null)
_transaction.Rollback();
return null;
}
}
}
}