Commit 80d1f73b by lcx

二次绩效其他模板,修改数据方法调整

parent 201526a8
...@@ -118,6 +118,16 @@ public bool UpdateByState(TEntity entity) ...@@ -118,6 +118,16 @@ public bool UpdateByState(TEntity entity)
return context.SaveChanges() > 0; return context.SaveChanges() > 0;
} }
public bool UpdateRangeByState(IEnumerable<TEntity> entities)
{
foreach (var entity in entities)
{
var entry = context.Entry(entity);
entry.State = EntityState.Modified;
}
return context.SaveChanges() > 0;
}
public bool Update(TEntity entity, Action<TEntity> action) public bool Update(TEntity entity, Action<TEntity> action)
{ {
action?.Invoke(entity); action?.Invoke(entity);
......
...@@ -1999,28 +1999,14 @@ private void SupplementSecondDetail(ag_secondallot second, List<per_employee> em ...@@ -1999,28 +1999,14 @@ private void SupplementSecondDetail(ag_secondallot second, List<per_employee> em
public List<ag_othersource> OtherSave(int secondId, List<ag_othersource> request) public List<ag_othersource> OtherSave(int secondId, List<ag_othersource> request)
{ {
if (request == null || !request.Any()) return new List<ag_othersource>();
if (request.Any(t => t.Id != 0))
agothersourceRepository.UpdateRangeByState(request.Where(t => t.Id != 0));
var existEntities = agothersourceRepository.GetEntities(t => t.SecondId == secondId); var existEntities = agothersourceRepository.GetEntities(t => t.SecondId == secondId);
if (existEntities != null && existEntities.Any()) if (existEntities != null && existEntities.Any())
{ {
foreach (var item in request.Where(t => t.Id != 0))
{
existEntities.First(t => t.Id == item.Id).WorkNumber = item.WorkNumber;
existEntities.First(t => t.Id == item.Id).Name = item.Name;
existEntities.First(t => t.Id == item.Id).Department = item.Department;
existEntities.First(t => t.Id == item.Id).WorkPost = item.WorkPost;
existEntities.First(t => t.Id == item.Id).TitlePerformance = item.TitlePerformance;
existEntities.First(t => t.Id == item.Id).WorkPerformance = item.WorkPerformance;
existEntities.First(t => t.Id == item.Id).DeptReward = item.DeptReward;
existEntities.First(t => t.Id == item.Id).DistPerformance = item.DistPerformance;
existEntities.First(t => t.Id == item.Id).OtherPerformance = item.OtherPerformance;
existEntities.First(t => t.Id == item.Id).NightWorkPerformance = item.NightWorkPerformance;
existEntities.First(t => t.Id == item.Id).RealAmount = item.RealAmount;
existEntities.First(t => t.Id == item.Id).ManagementAllowance = item.ManagementAllowance;
existEntities.First(t => t.Id == item.Id).IndividualReward = item.IndividualReward;
existEntities.First(t => t.Id == item.Id).AllocationOfKeySpecialty = item.AllocationOfKeySpecialty;
}
agothersourceRepository.UpdateRange(existEntities.ToArray());
var delIds = existEntities.Select(t => t.Id).Except(request.Select(t => t.Id)); var delIds = existEntities.Select(t => t.Id).Except(request.Select(t => t.Id));
if (delIds != null) if (delIds != null)
agothersourceRepository.RemoveRange(existEntities.Where(t => delIds.Contains(t.Id)).ToArray()); agothersourceRepository.RemoveRange(existEntities.Where(t => delIds.Contains(t.Id)).ToArray());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment