internal IResult Execute(DateTime timestamp, Employee employee, LotKey lotKey, LotQualityStatus status, bool forceResolveAllDefects = false) { var lot = _lotUnitOfWork.LotRepository.FindByKey(lotKey, l => l.ChileLot, l => l.Attributes.Select(a => a.AttributeName), l => l.LotDefects.Select(d => d.Resolution)); if (lot == null) { return(new InvalidResult(string.Format(UserMessages.LotNotFound, lotKey))); } var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(lot, timestamp); if (!historyResult.Success) { return(historyResult); } if (forceResolveAllDefects) { foreach (var defect in lot.LotDefects) { if (defect.Resolution == null) { defect.Resolution = new LotDefectResolution { EmployeeId = employee.EmployeeId, TimeStamp = timestamp, ResolutionType = ResolutionTypeEnum.AcceptedByUser, Description = "Forced acceptance by user." }; } } } if (lot.ChileLot != null) { var chileLot = _lotUnitOfWork.ChileLotRepository.FindByKey(lotKey, LotStatusHelper.ChileLotIncludePaths); if (chileLot == null) { return(new InvalidResult(string.Format(UserMessages.ChileLotNotFound, lotKey))); } if (!LotStatusHelper.GetValidLotQualityStatuses(chileLot).Contains(status)) { return(new InvalidResult(string.Format(UserMessages.CannotSetLotStatus, lotKey, chileLot.Lot.QualityStatus, status))); } } lot.QualityStatus = status; lot.EmployeeId = employee.EmployeeId; lot.TimeStamp = timestamp; return(new SuccessResult()); }
public IResult RemoveLotDefectResolution(RemoveLotDefectResolutionParameters parameters, DateTime timestamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult); } var lotDefect = _lotUnitOfWork.LotDefectRepository.FindByKey(parameters.LotDefectKey, d => d.Resolution, d => d.Lot.ChileLot, d => d.Lot.Attributes); if (lotDefect == null) { return(new InvalidResult(string.Format(UserMessages.LotDefectNotFound, parameters.LotDefectKey))); } var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(lotDefect.Lot, timestamp); if (!historyResult.Success) { return(historyResult); } if (lotDefect.Resolution == null) { return(new NoWorkRequiredResult(string.Format(UserMessages.LotDefectHasNoResolution, parameters.LotDefectKey))); } lotDefect.Lot.EmployeeId = employeeResult.ResultingObject.EmployeeId; lotDefect.Lot.TimeStamp = timestamp; _lotUnitOfWork.LotDefectResolutionRepository.Remove(lotDefect.Resolution); return(new UpdateChileLotStatusCommand(_lotUnitOfWork).Execute(lotDefect)); }
private IResult SetLotAttributes(LotData data, Employee employee, DateTime timestamp, List <AttributeName> attributeNames, Dictionary <AttributeNameKey, IAttributeValueParameters> attributes) { var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(data.Lot, timestamp); if (!historyResult.Success) { return(historyResult); } var setValuesResult = new SetLotAttributeValuesCommand(_lotUnitOfWork).Execute(new SetLotAttributesParameters { Employee = employee, TimeStamp = timestamp, AttributeNames = attributeNames, Lot = data.Lot, LotUnarchivedPickedInventoryItems = data.Picked, LotAttributeDefects = data.Lot.AttributeDefects.ToList(), NewAttributes = attributes }); if (!setValuesResult.Success) { return(setValuesResult); } if (data.Lot.ChileLot != null) { var updateStatusResult = LotStatusHelper.UpdateChileLotStatus(data.Lot.ChileLot, attributeNames); if (!updateStatusResult.Success) { return(updateStatusResult); } } data.Lot.EmployeeId = employee.EmployeeId; data.Lot.TimeStamp = timestamp; return(new SuccessResult()); }