예제 #1
0
        internal IResult Execute(SetLotHoldStatusParameters parameters, DateTime timestamp)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters);

            if (!employeeResult.Success)
            {
                return(employeeResult);
            }

            var lot = _lotUnitOfWork.LotRepository.FindByKey(parameters.LotKey, l => l.ChileLot, l => l.Attributes);

            if (lot == null)
            {
                return(new InvalidResult(string.Format(UserMessages.LotNotFound, parameters.LotKey)));
            }

            var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(lot, timestamp);

            if (!historyResult.Success)
            {
                return(historyResult);
            }

            if (parameters.Parameters.Hold == null)
            {
                lot.Hold            = null;
                lot.HoldDescription = null;
            }
            else
            {
                lot.Hold = parameters.Parameters.Hold.HoldType;
                var description = parameters.Parameters.Hold.Description;
                if (description != null && description.Length > Constants.StringLengths.LotHoldDescription)
                {
                    description = description.Substring(0, Constants.StringLengths.LotHoldDescription);
                }
                lot.HoldDescription = description;
            }

            lot.EmployeeId = employeeResult.ResultingObject.EmployeeId;
            lot.TimeStamp  = timestamp;

            return(new SuccessResult());
        }
예제 #2
0
        internal IResult <LotDefect> Execute(CreateLotDefectParameters parameters, DateTime timestamp)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo <LotDefect>());
            }

            var lotKey = parameters.LotKey;
            var lot    = _lotUnitOfWork.LotRepository.FindByKey(lotKey, l => l.ChileLot, l => l.Attributes);

            if (lot == null)
            {
                return(new InvalidResult <LotDefect>(null, string.Format(UserMessages.LotNotFound, lotKey.KeyValue)));
            }

            var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(lot, timestamp);

            if (!historyResult.Success)
            {
                return(historyResult.ConvertTo <LotDefect>());
            }

            var newDefectId = new EFUnitOfWorkHelper(_lotUnitOfWork).GetNextSequence <LotDefect>(d => d.LotDateCreated == lot.LotDateCreated && d.LotDateSequence == lot.LotDateSequence && d.LotTypeId == lot.LotTypeId, d => d.DefectId);
            var newDefect   = _lotUnitOfWork.LotDefectRepository.Add(new LotDefect
            {
                LotDateCreated  = lot.LotDateCreated,
                LotDateSequence = lot.LotDateSequence,
                LotTypeId       = lot.LotTypeId,
                DefectId        = newDefectId,

                DefectType  = DefectTypeEnum.InHouseContamination,
                Description = parameters.Parameters.Description
            });

            lot.EmployeeId = employeeResult.ResultingObject.EmployeeId;
            lot.TimeStamp  = timestamp;

            return(new SuccessResult <LotDefect>(newDefect));
        }