internal IResult AddLotAttributes(DateTime timestamp, AddLotAttributeParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var lotKeys = parameters.LotKeys.Where(k => k != null).Distinct().ToList(); if (!lotKeys.Any()) { return(new NoWorkRequiredResult()); } var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ILotKey>()); } var dataResult = GetLotData(lotKeys.ToArray()); if (!dataResult.Success) { return(dataResult); } var attributeNames = _lotUnitOfWork.AttributeNameRepository.Filter(a => true, a => a.ValidTreatments).ToList(); foreach (var chileLot in dataResult.ResultingObject) { var setResult = SetLotAttributes(chileLot, timestamp, parameters, employeeResult.ResultingObject, attributeNames); if (!setResult.Success) { return(setResult); } } return(new SuccessResult()); }
private IResult SetLotAttributes(LotData data, DateTime timestamp, AddLotAttributeParameters parameters, Employee user, List <AttributeName> attributeNames) { var lotAttributes = parameters.Attributes.ToDictionary(a => a.Key, a => a.Value); foreach (var attribute in data.Lot.Attributes) { var attributeNameKey = attribute.ToAttributeNameKey(); if (!lotAttributes.ContainsKey(attributeNameKey)) { lotAttributes.Add(attributeNameKey, new AttributeValueParameters { AttributeInfo = new AttributeInfoParameters { Value = attribute.AttributeValue, Date = attribute.AttributeDate } }); } } var setAttributesResult = SetLotAttributes(data, user, timestamp, attributeNames, lotAttributes); if (!setAttributesResult.Success) { return(setAttributesResult); } if (parameters.Parameters.OverrideOldContextLotAsCompleted) { var setStatusResult = new SetLotStatusConductor(_lotUnitOfWork).Execute(timestamp, user, data.Lot.ToLotKey(), LotQualityStatus.Released); if (!setStatusResult.Success) { return(setStatusResult); } } return(new SuccessResult()); }