| | |
| | | |
| | | if (viewModel.LabList != null && viewModel.LabList.Count > 0) |
| | | { |
| | | var qcService = PalGainEngine.Instance.Resolve<QCService>(); |
| | | var existingRegisters = qcService.GetQcDistributionRegisters() |
| | | .Where(p => p.QCDistributionId == viewModel.Id) |
| | | .ToList(); |
| | | var byId = existingRegisters.ToDictionary(p => p.Id, p => p); |
| | | var byLabProject = existingRegisters |
| | | .GroupBy(p => Tuple.Create(p.LabId, p.ProjectId)) |
| | | .ToDictionary(g => g.Key, g => g.OrderByDescending(p => p.Id).First()); |
| | | |
| | | viewModel.LabList.ForEach(x => |
| | | { |
| | | QCDistributionRegisterInfo registerInfo = QCDistributionRegisterInfoViewModel.ToEntity(x); |
| | | QCDistributionRegisterInfo cachedExisting = null; |
| | | if (x.Id > 0 && !byId.TryGetValue(x.Id, out cachedExisting)) |
| | | { |
| | | cachedExisting = qcService.GetQcDistributionRegisters() |
| | | .FirstOrDefault(p => p.Id == x.Id); |
| | | } |
| | | QCDistributionRegisterInfo registerInfo = QCDistributionRegisterInfoViewModel.ToEntity(x, cachedExisting); |
| | | registerInfo.QCDistributionId = viewModel.Id; |
| | | registerInfo.LabId = x.LabId; |
| | | registerInfo.ProjectId = x.ProjectId; |
| | | if (x.IsSelected) |
| | | { |
| | | { |
| | | if (registerInfo.Id == 0) |
| | | { |
| | | QCDistributionRegisterInfo dup; |
| | | if (byLabProject.TryGetValue(Tuple.Create(x.LabId, x.ProjectId), out dup)) |
| | | { |
| | | dup.IsCharged = x.IsCharged; |
| | | dup.ModifyTime = DateTime.Now; |
| | | qcService.SaveQcDistributionRegister(dup); |
| | | return; |
| | | } |
| | | } |
| | | registerInfo.IsCharged = x.IsCharged; |
| | | PalGainEngine.Instance.Resolve<QCService>().SaveQcDistributionRegister(registerInfo); |
| | | qcService.SaveQcDistributionRegister(registerInfo); |
| | | } |
| | | else |
| | | { |
| | | var entity = PalGainEngine.Instance.Resolve<QCService>().GetQcDistributionRegisters() |
| | | .FirstOrDefault(p => p.Id == x.Id); |
| | | if (entity != null) |
| | | if (cachedExisting != null) |
| | | { |
| | | PalGainEngine.Instance.Resolve<QCService>().DeleteQcDistributionRegister(entity); |
| | | qcService.DeleteQcDistributionRegister(cachedExisting); |
| | | } |
| | | } |
| | | }); |