public IResult UpdateLocation(IUpdateLocationParameters parameters) { var parameterResult = parameters.ToParsedParameters(); if (!parameterResult.Success) { return(parameterResult); } var employeeResult = new GetEmployeeCommand(_facilityUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <string>()); } var result = new UpdateLocationCommand(_facilityUnitOfWork).UpdateLocation(parameterResult.ResultingObject); if (!result.Success) { return(result); } _facilityUnitOfWork.Commit(); return(SyncParameters.Using(new SuccessResult(), new SyncLocationsParameters { EmployeeKey = employeeResult.ResultingObject, Locations = new List <ILocationKey> { parameterResult.ResultingObject.LocationKey } })); }
internal IResult <Note> Execute(INotebookKey notebookKey, DateTime timestamp, ICreateNoteParameters parameters) { if (notebookKey == null) { throw new ArgumentNullException("notebookKey"); } if (timestamp == null) { throw new ArgumentNullException("timestamp"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_notebookUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo((Note)null)); } var notebookKeyFind = new NotebookKey(notebookKey); var notebook = _notebookUnitOfWork.NotebookRepository.FindByKey(notebookKeyFind); if (notebook == null) { return(new InvalidResult <Note>(null, string.Format(UserMessages.NotebookNotFound, notebookKeyFind))); } return(Execute(notebook, timestamp, employeeResult.ResultingObject, parameters.Text)); }
internal IResult <ChileLotProduction> Execute(DateTime timeStamp, UpdateMillAndWetdownParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(ProductionUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileLotProduction>()); } var chileLotResult = ProductionUnitOfWork.ChileLotProductionRepository.FindByKey(parameters.LotKey, c => c.ResultingChileLot.ChileProduct, c => c.PickedInventory.Items.Select(i => i.CurrentLocation), c => c.Results.ResultItems); if (chileLotResult == null || chileLotResult.ProductionType != ProductionType.MillAndWetdown) { return(new InvalidResult <ChileLotProduction>(null, string.Format(UserMessages.MillAndWetdownEntryNotFound, parameters.LotKey))); } return(SetMillAndWetdown(chileLotResult, parameters, timeStamp, employeeResult.ResultingObject)); }
internal IResult Execute(NoteKey noteKey, DateTime timestamp, IUpdateNoteParameters parameters) { if (noteKey == null) { throw new ArgumentNullException("noteKey "); } if (timestamp == null) { throw new ArgumentNullException("timestamp"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var note = _notebookUnitOfWork.NoteRepository.FindByKey(noteKey); if (note == null) { return(new InvalidResult(string.Format(UserMessages.NoteNotFound, noteKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(_notebookUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult); } note.EmployeeId = employeeResult.ResultingObject.EmployeeId; note.TimeStamp = timestamp; note.Text = parameters.Text; return(new SuccessResult()); }
public IResult Execute(DateTime timestamp, UpdateProductionBatchCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var productionBatch = _productionUnitOfWork.ProductionBatchRepository.FindByKey(parameters.ProductionBatchKey, b => b.Production.ResultingChileLot.Lot); if (productionBatch == null) { return(new InvalidResult(string.Format(UserMessages.ProductionBatchNotFound, parameters.ProductionBatchKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(_productionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult); } productionBatch.EmployeeId = employeeResult.ResultingObject.EmployeeId; productionBatch.TimeStamp = timestamp; productionBatch.TargetParameters = new ProductionBatchTargetParameters(parameters.Parameters); productionBatch.Production.ResultingChileLot.Lot.Notes = parameters.Parameters.Notes.TrimTruncate(Constants.StringLengths.LotNotes); return(new SuccessResult()); }
internal IResult <ILotKey> Execute(DateTime timestamp, SetLotAttributeParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ILotKey>()); } var dataResult = GetLotData(parameters.LotKey); if (!dataResult.Success) { return(dataResult.ConvertTo <ILotKey>()); } var data = dataResult.ResultingObject.First(); var attributeNames = _lotUnitOfWork.AttributeNameRepository.Filter(a => true, a => a.ValidTreatments).ToList(); var setAttributesResult = SetLotAttributes(data, employeeResult.ResultingObject, timestamp, attributeNames, parameters.Attributes); if (!setAttributesResult.Success) { return(setAttributesResult.ConvertTo <ILotKey>()); } data.Lot.Notes = parameters.Parameters.Notes; return(new SuccessResult <ILotKey>(parameters.LotKey)); }
internal IResult <ProductionSchedule> Update(DateTime timestamp, UpdateProductionScheduleParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(ProductionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionSchedule>()); } var productionSchedule = ProductionUnitOfWork.ProductionScheduleRepository.FindByKey(parameters.ProductionScheduleKey, p => p.ProductionLineLocation, p => p.ScheduledItems); if (productionSchedule == null) { return(new InvalidResult <ProductionSchedule>(null, string.Format(UserMessages.ProductionScheduleNotFound, parameters.ProductionScheduleKey))); } var items = parameters.ScheduledItems.Select(i => new SetProductionScheduleItemParameters { Index = i.Parameters.Index, FlushBefore = i.Parameters.FlushBefore, FlushBeforeInstructions = i.Parameters.FlushBeforeInstructions, FlushAfter = i.Parameters.FlushAfter, FlushAfterInstructions = i.Parameters.FlushAfterInstructions, PackScheduleKey = i.PackScheduleKey }).ToList(); return(Set(productionSchedule, employeeResult.ResultingObject, timestamp, items)); }
public IResult Execute(DateTime timeStamp, SetCustomerProductAttributeRangesParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters "); } var employeeResult = new GetEmployeeCommand(_salesUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult); } var predicate = CustomerProductAttributeRangePredicates.ByCustomerProduct(parameters.CustomerKey, parameters.ChileProductKey); var existing = _salesUnitOfWork.CustomerProductAttributeRangeRepository.Filter(predicate) .ToList() .ToDictionary(r => r.AttributeShortName); foreach (var item in parameters.AttributeRanges) { bool update; CustomerProductAttributeRange range; if (!existing.TryGetValue(item.AttributeNameKey.AttributeNameKey_ShortName, out range)) { update = true; range = _salesUnitOfWork.CustomerProductAttributeRangeRepository.Add(new CustomerProductAttributeRange { CustomerId = parameters.CustomerKey.CustomerKey_Id, ChileProductId = parameters.ChileProductKey.ChileProductKey_ProductId, AttributeShortName = item.AttributeNameKey.AttributeNameKey_ShortName, Active = true }); } else { existing.Remove(item.AttributeNameKey.AttributeNameKey_ShortName); update = range.RangeMin != item.Parameters.RangeMin || range.RangeMax != item.Parameters.RangeMax; } if (update) { range.EmployeeId = employeeResult.ResultingObject.EmployeeId; range.RangeMin = item.Parameters.RangeMin; range.RangeMax = item.Parameters.RangeMax; range.TimeStamp = timeStamp; } } foreach (var item in existing.Values) { _salesUnitOfWork.CustomerProductAttributeRangeRepository.Remove(item); } return(new SuccessResult <CustomerProductAttributeRange>()); }
internal IResult <ChileMaterialsReceived> Execute(CreateChileMaterialsReceivedParameters parameters, DateTime timeStamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(MaterialsReceivedUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileMaterialsReceived>()); } var chileProduct = MaterialsReceivedUnitOfWork.ChileProductRepository.FindByKey(parameters.ChileProductKey); if (chileProduct == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductNotFound, parameters.ChileProductKey.KeyValue))); } if (parameters.Params.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated && chileProduct.ChileState != ChileStateEnum.Dehydrated) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductInvalidState, parameters.ChileProductKey.KeyValue, chileProduct.ChileState, ChileStateEnum.Dehydrated))); } var createChileLotResult = new CreateNewChileLotCommand(MaterialsReceivedUnitOfWork).Execute(new CreateNewChileLotCommandParameters { EmployeeKey = employeeResult.ResultingObject, TimeStamp = timeStamp, LotDate = parameters.Params.DateReceived.Date, LotType = LotTypeEnum.DeHydrated, ChileProductKey = chileProduct, SetLotProductionStatus = LotProductionStatus.Produced, SetLotQualityStatus = LotQualityStatus.Pending }); if (!createChileLotResult.Success) { return(createChileLotResult.ConvertTo <ChileMaterialsReceived>()); } var chileLot = createChileLotResult.ResultingObject; var materialsReceived = MaterialsReceivedUnitOfWork.ChileMaterialsReceivedRepository.Add(new ChileMaterialsReceived { ChileLot = chileLot, LotDateCreated = chileLot.LotDateCreated, LotDateSequence = chileLot.LotDateSequence, LotTypeId = chileLot.LotTypeId, Items = new List <ChileMaterialsReceivedItem>() }); return(Set(materialsReceived, chileProduct, parameters, employeeResult.ResultingObject, timeStamp)); }
public dto.Employee Get(string name) { using (var connection = new MySqlConnection(_connectionString)) { connection.Open(); var cmd = new GetEmployeeCommand(name, connection); cmd.Execute(); connection.Close(); return(cmd.Result); } }
private IResult <IntraWarehouseOrder> GetUpdatedOrder(DateTime timestamp, IIntraWarehouseOrderKey orderKey, IIntraWarehouseOrderParameters parameters) { var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <IntraWarehouseOrder>()); } IntraWarehouseOrder order; if (orderKey != null) { var key = new IntraWarehouseOrderKey(orderKey); order = UnitOfWork.IntraWarehouseOrderRepository.FindByKey(key, o => o.PickedInventory.Items); if (order == null) { return(new InvalidResult <IntraWarehouseOrder>(null, string.Format(UserMessages.IntraWarehouseOrderNotFound, key))); } } else { var pickedInventoryResult = new CreatePickedInventoryCommand(UnitOfWork).Execute(new CreatePickedInventoryCommandParameters { EmployeeKey = employeeResult.ResultingObject, PickedReason = PickedReason.IntraWarehouseMovement, TimeStamp = timestamp }); if (!pickedInventoryResult.Success) { return(pickedInventoryResult.ConvertTo <IntraWarehouseOrder>()); } var pickedInventory = pickedInventoryResult.ResultingObject; pickedInventory.Archived = true; order = UnitOfWork.IntraWarehouseOrderRepository.Add(new IntraWarehouseOrder { DateCreated = pickedInventory.DateCreated, Sequence = pickedInventory.Sequence, PickedInventory = pickedInventoryResult.ResultingObject }); } order.TimeStamp = timestamp; order.EmployeeId = employeeResult.ResultingObject.EmployeeId; order.Employee = employeeResult.ResultingObject; order.OperatorName = parameters.OperatorName; order.MovementDate = parameters.MovementDate; return(new SuccessResult <IntraWarehouseOrder>(order)); }
public IResult <PackSchedule> Execute(DateTime timestamp, CreatePackScheduleCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var dateCreated = parameters.Parameters.DateCreated?.Date ?? timestamp.Date; var sequence = parameters.Parameters.Sequence ?? new EFUnitOfWorkHelper(_productionUnitOfWork).GetNextSequence <PackSchedule>(p => p.DateCreated == dateCreated, p => p.SequentialNumber); var employeeResult = new GetEmployeeCommand(_productionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <PackSchedule>()); } Data.Models.Company customer = null; if (parameters.CustomerKey != null) { var companyResult = new GetCompanyCommand(_productionUnitOfWork).Execute(parameters.CustomerKey, CompanyType.Customer); if (!companyResult.Success) { return(companyResult.ConvertTo <PackSchedule>()); } customer = companyResult.ResultingObject; } var packSchedule = _productionUnitOfWork.PackScheduleRepository.Add(new PackSchedule { EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timestamp, PackSchID = DataConstants.SqlMinDate, PSNum = parameters.Parameters.PSNum ?? _productionUnitOfWork.PackScheduleRepository.SourceQuery.Select(p => p.PSNum).Where(p => p != null).DefaultIfEmpty(0).Max().Value + 1, DateCreated = dateCreated, SequentialNumber = sequence, WorkTypeId = parameters.WorkTypeKey.WorkTypeKey_WorkTypeId, ChileProductId = parameters.ChileProductKey.ChileProductKey_ProductId, PackagingProductId = parameters.PackagingProductKey.PackagingProductKey_ProductId, ScheduledProductionDate = parameters.Parameters.ScheduledProductionDate, ProductionDeadline = parameters.Parameters.ProductionDeadline, ProductionLineLocationId = parameters.ProductionLocationKey.LocationKey_Id, SummaryOfWork = parameters.Parameters.SummaryOfWork ?? "", CustomerId = customer == null ? (int?)null : customer.Id, OrderNumber = parameters.Parameters.OrderNumber.TrimTruncate(Constants.StringLengths.OrderNumber), DefaultBatchTargetParameters = new ProductionBatchTargetParameters(parameters.Parameters) }); return(new SuccessResult <PackSchedule>(packSchedule)); }
public IResult Execute(DateTime timestamp, ReceiveTreatmentOrderParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_treatmentOrderUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult); } var order = _treatmentOrderUnitOfWork.TreatmentOrderRepository.FindByKey(parameters.TreatmentOrderKey, o => o.InventoryShipmentOrder.PickedInventory.Items.Select(i => i.CurrentLocation)); if (order == null) { return(new FailureResult(string.Format(UserMessages.TreatmentOrderNotFound, parameters.TreatmentOrderKey.KeyValue))); } if (order.InventoryShipmentOrder.OrderStatus == OrderStatus.Fulfilled) { return(new FailureResult <PickedInventory>(null, string.Format(UserMessages.TreatmentOrderAlreadyFulfilled, new TreatmentOrderKey(order).KeyValue))); } var inventoryModifications = new List <ModifyInventoryParameters>(); foreach (var item in order.InventoryShipmentOrder.PickedInventory.Items) { inventoryModifications.Add(new ModifyInventoryParameters(item, item, item.CurrentLocation, item, item.ToteKey, -item.Quantity)); inventoryModifications.Add(item.ToModifyInventoryDestinationParameters(parameters.DestinationLocationKey, order)); item.CurrentLocationId = parameters.DestinationLocationKey.LocationKey_Id; } var modificationsResult = new ModifyInventoryCommand(_treatmentOrderUnitOfWork).Execute(inventoryModifications, new InventoryTransactionParameters(employeeResult.ResultingObject, timestamp, InventoryTransactionType.ReceiveTreatmentOrder, parameters.TreatmentOrderKey)); if (!modificationsResult.Success) { return(modificationsResult); } order.InventoryShipmentOrder.OrderStatus = OrderStatus.Fulfilled; order.InventoryShipmentOrder.PickedInventory.Archived = true; order.Returned = DateTime.UtcNow; return(new SuccessResult <PickedInventory>(order.InventoryShipmentOrder.PickedInventory)); }
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()); }
internal IResult Execute(DateTime timestamp, SetLotStatusParameters parameters, bool forceResolveAllDefects = false) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult); } return(Execute(timestamp, employeeResult.ResultingObject, parameters.LotKey, parameters.Parameters.QualityStatus, forceResolveAllDefects)); }
internal IResult <InventoryAdjustment> Execute(DateTime timeStamp, CreateInventoryAdjustmentConductorParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_inventoryUnitOfWork).GetEmployee(parameters.CreateInventoryAdjustmentParameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo((InventoryAdjustment)null)); } var employee = employeeResult.ResultingObject; var createAdjustmentResult = CreateInventoryAdjustment(timeStamp, employee, parameters.CreateInventoryAdjustmentParameters.Comment); if (!createAdjustmentResult.Success) { return(createAdjustmentResult.ConvertTo((InventoryAdjustment)null)); } var inventoryAdjustment = createAdjustmentResult.ResultingObject; var createInventoryAdjustmentItemCommand = new CreateInventoryAdjustmentItemCommand(_inventoryUnitOfWork); var inventoryModifications = new List <ModifyInventoryParameters>(); foreach (var adjustment in parameters.Items) { var createAdjustmentItemResult = createInventoryAdjustmentItemCommand.Execute(inventoryAdjustment, adjustment); if (!createAdjustmentItemResult.Success) { return(createAdjustmentItemResult.ConvertTo((InventoryAdjustment)null)); } inventoryModifications.Add(new ModifyInventoryParameters(new InventoryKey(createAdjustmentItemResult.ResultingObject), adjustment.InventoryAdjustmentParameters.Adjustment)); } var modifyInventoryResult = new ModifyInventoryCommand(_inventoryUnitOfWork).Execute(inventoryModifications, new InventoryTransactionParameters(employee, timeStamp, InventoryTransactionType.InventoryAdjustment, new InventoryAdjustmentKey(inventoryAdjustment))); if (!modifyInventoryResult.Success) { return(modifyInventoryResult.ConvertTo((InventoryAdjustment)null)); } return(new SuccessResult <InventoryAdjustment>(inventoryAdjustment)); }
internal IResult <Lot> ReceiveInventory(DateTime timeStamp, ReceiveInventoryParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (timeStamp == null) { throw new ArgumentNullException("timeStamp"); } var employeeResult = new GetEmployeeCommand(_inventoryUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <Lot>()); } IResult <Lot> lotResult; var productType = parameters.Parameters.LotType.ToProductType(); switch (productType) { case ProductTypeEnum.Additive: lotResult = CreateAdditiveLot(timeStamp, employeeResult.ResultingObject, parameters); break; case ProductTypeEnum.Chile: lotResult = CreateChileLot(timeStamp, employeeResult.ResultingObject, parameters); break; case ProductTypeEnum.Packaging: lotResult = CreatePackagingLot(timeStamp, employeeResult.ResultingObject, parameters); break; default: throw new ArgumentOutOfRangeException(productType.ToString()); } if (!lotResult.Success) { return(lotResult); } var inventoryResult = new ModifyInventoryCommand(_inventoryUnitOfWork).Execute(parameters.Items.Select(i => i.ToModifyInventory(lotResult.ResultingObject)), new InventoryTransactionParameters(employeeResult.ResultingObject, timeStamp, InventoryTransactionType.ReceiveInventory, null)); if (!inventoryResult.Success) { return(inventoryResult.ConvertTo <Lot>()); } return(new SuccessResult <Lot>(lotResult.ResultingObject)); }
internal IResult <SampleOrderJournalEntry> Execute(SetSampleJournalEntryCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_sampleOrderUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <SampleOrderJournalEntry>()); } var sampleOrder = _sampleOrderUnitOfWork.SampleOrderRepository.FindByKey(parameters.SampleOrderKey, o => o.JournalEntries); if (sampleOrder == null) { return(new InvalidResult <SampleOrderJournalEntry>(null, string.Format(UserMessages.SampleOrderNotFound, parameters.SampleOrderKey))); } SampleOrderJournalEntry journalEntry; if (parameters.JournalEntryKey != null) { journalEntry = sampleOrder.JournalEntries.FirstOrDefault(parameters.JournalEntryKey.FindByPredicate.Compile()); if (journalEntry == null) { return(new InvalidResult <SampleOrderJournalEntry>(null, string.Format(UserMessages.SampleOrderJournalEntryNotFound, parameters.JournalEntryKey))); } } else { journalEntry = _sampleOrderUnitOfWork.SampleOrderJournalEntryRepository.Add(new SampleOrderJournalEntry { SampleOrderYear = sampleOrder.Year, SampleOrderSequence = sampleOrder.Sequence, EntrySequence = sampleOrder.JournalEntries.Select(j => j.EntrySequence).DefaultIfEmpty(0).Max() + 1 }); } journalEntry.EmployeeId = employeeResult.ResultingObject.EmployeeId; journalEntry.Date = parameters.Parameters.Date; journalEntry.Text = parameters.Parameters.Text; return(new SuccessResult <SampleOrderJournalEntry>(journalEntry)); }
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)); }
public IResult <LotKey> Execute(DateTime timeStamp, ISetPickedInventoryParameters pickedInventory, LotKey batchKey) { var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(batchKey, b => b.Production.ResultingChileLot.Lot.Attributes.Select(a => a.AttributeName), b => b.Production.PickedInventory.Items.Select(i => i.CurrentLocation)); if (productionBatch == null) { return(new InvalidResult <LotKey>(null, string.Format(UserMessages.ProductionBatchNotFound, batchKey.KeyValue))); } if (productionBatch.ProductionHasBeenCompleted) { return(new InvalidResult <LotKey>(null, string.Format(UserMessages.ProductionBatchAlreadyComplete, batchKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(pickedInventory); if (!employeeResult.Success) { return(employeeResult.ConvertTo <LotKey>()); } var parsedPicked = pickedInventory.PickedInventoryItems.ToParsedParameters(); if (!parsedPicked.Success) { return(parsedPicked.ConvertTo <LotKey>()); } var pickResult = UpdatePickedInventory(PickedInventoryValidator.ForProductionBatch, employeeResult.ResultingObject, timeStamp, productionBatch.Production.PickedInventory, parsedPicked.ResultingObject); if (!pickResult.Success) { return(pickResult.ConvertTo <LotKey>()); } var setWeightedAttributes = new SetLotWeightedAttributesConductor(UnitOfWork).Execute(productionBatch.Production.ResultingChileLot, productionBatch.Production.PickedInventory.Items.ToList(), timeStamp); if (!setWeightedAttributes.Success) { return(setWeightedAttributes.ConvertTo <LotKey>()); } return(new SuccessResult <LotKey>(batchKey)); }
private IResult <CustomerNote> SetCustomerNote(CustomerNote note, DateTime timestamp, ISetCustomerNoteParameters parameters) { var employeeResult = new GetEmployeeCommand(_companyUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <CustomerNote>()); } note.EmployeeId = employeeResult.ResultingObject.EmployeeId; note.TimeStamp = timestamp; note.Type = parameters.Type; note.Text = parameters.Text; note.Bold = parameters.Bold; return(new SuccessResult <CustomerNote>(note)); }
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)); }
internal IResult <SampleOrder> Execute(DateTime timeStamp, SetSampleOrderParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_sampleOrderUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <SampleOrder>()); } SampleOrder sampleOrder; if (parameters.SampleOrderKey != null) { sampleOrder = _sampleOrderUnitOfWork.SampleOrderRepository.FindByKey(parameters.SampleOrderKey, o => o.Items.Select(i => i.Spec), o => o.Items.Select(i => i.Match)); if (sampleOrder == null) { return(new InvalidResult <SampleOrder>(null, string.Format(UserMessages.SampleOrderNotFound, parameters.SampleOrderKey))); } } else { var year = timeStamp.Year; var sequence = new EFUnitOfWorkHelper(_sampleOrderUnitOfWork).GetNextSequence <SampleOrder>(o => o.Year == year, o => o.Sequence); sampleOrder = _sampleOrderUnitOfWork.SampleOrderRepository.Add(new SampleOrder { Year = year, Sequence = sequence, Items = new List <SampleOrderItem>() }); } return(SetSampleOrder(employeeResult.ResultingObject, timeStamp, sampleOrder, parameters)); }
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()); }
internal IResult <InventoryShipmentOrder> SetPickedInventory(DateTime timeStamp, Parameters parameters) { var inventoryShipmentOrder = UnitOfWork.InventoryShipmentOrderRepository.FindByKey(parameters.OrderKey, i => i.ShipmentInformation, i => i.SourceFacility, i => i.PickedInventory.Items.Select(t => t.FromLocation), i => i.PickedInventory.Items.Select(t => t.CurrentLocation)); if (inventoryShipmentOrder == null) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.InventoryShipmentOrderNotFound, parameters.OrderKey))); } var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(parameters.User); if (!employeeResult.Success) { return(employeeResult.ConvertTo <InventoryShipmentOrder>()); } if (inventoryShipmentOrder.ShipmentInformation.Status != ShipmentStatus.Scheduled && inventoryShipmentOrder.ShipmentInformation.Status != ShipmentStatus.Unscheduled) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.CannotPickShipment, inventoryShipmentOrder.ShipmentInformation.Status))); } var validator = GetInventoryValidator(inventoryShipmentOrder); if (!validator.Success) { return(validator.ConvertTo <InventoryShipmentOrder>()); } var pickedResult = UpdatePickedInventory(validator.ResultingObject, employeeResult.ResultingObject, timeStamp, inventoryShipmentOrder.PickedInventory, parameters.PickedInventoryParameters); if (!pickedResult.Success) { return(pickedResult.ConvertTo <InventoryShipmentOrder>()); } return(new SuccessResult <InventoryShipmentOrder>(inventoryShipmentOrder)); }
protected IResult <Data.Models.Company> SetCompany <T>(Data.Models.Company company, DateTime timestamp, SetCompanyCommandParameters <T> parameters) where T : ISetCompanyParameters { var employeeResult = new GetEmployeeCommand(CompanyUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <Data.Models.Company>()); } company.EmployeeId = employeeResult.ResultingObject.EmployeeId; company.TimeStamp = timestamp; company.Active = parameters.Parameters.Active; var setTypesResult = SetCompanyTypes(company, parameters.Parameters.CompanyTypes, parameters.BrokerKey); if (!setTypesResult.Success) { return(setTypesResult.ConvertTo <Data.Models.Company>()); } return(new SuccessResult <Data.Models.Company>(company)); }
internal IResult <ChileMaterialsReceived> Execute(UpdateChileMaterialsReceivedParameters parameters, DateTime timeStamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(MaterialsReceivedUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileMaterialsReceived>()); } var materialsReceived = MaterialsReceivedUnitOfWork.ChileMaterialsReceivedRepository.FindByKey(parameters.LotKey, m => m.ChileLot.Lot, m => m.Items); if (materialsReceived == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileMaterialsReceivedNotFound, parameters.LotKey))); } var chileProduct = MaterialsReceivedUnitOfWork.ChileProductRepository.FindByKey(parameters.ChileProductKey); if (chileProduct == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductNotFound, parameters.ChileProductKey))); } if (parameters.Params.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated && chileProduct.ChileState != ChileStateEnum.Dehydrated) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductInvalidState, parameters.ChileProductKey.KeyValue, chileProduct.ChileState, ChileStateEnum.Dehydrated))); } return(Set(materialsReceived, chileProduct, parameters, employeeResult.ResultingObject, timeStamp)); }
internal IResult UpdatePickedInventory(InventoryShipmentOrderKey orderKey, IUserIdentifiable user, DateTime timestamp, List <PickedInventoryParameters> setPickedInventoryItems) { var employeeResult = new GetEmployeeCommand(_inventoryShipmentUnitOfWork).GetEmployee(user); if (!employeeResult.Success) { return(employeeResult.ConvertTo <InventoryShipmentOrder>()); } var orderResult = GetOrder(orderKey); if (!orderResult.Success) { return(orderResult); } orderResult.ResultingObject.PickedInventory.EmployeeId = employeeResult.ResultingObject.EmployeeId; orderResult.ResultingObject.PickedInventory.TimeStamp = timestamp; var pickedInventoryModifications = PickedInventoryHelper.CreateModifyPickedInventoryItemParameters(orderResult.ResultingObject.PickedInventory, setPickedInventoryItems); var validatorResult = ValidateModifyPickedInventoryItems(orderResult.ResultingObject, pickedInventoryModifications); if (!validatorResult.Success) { return(validatorResult.ConvertTo <SalesOrder>()); } var modifyPickedResult = new ModifyPickedInventoryItemsCommand(_inventoryShipmentUnitOfWork).Execute(orderResult.ResultingObject.PickedInventory, pickedInventoryModifications); if (!modifyPickedResult.Success) { return(modifyPickedResult); } return(new ModifyInventoryCommand(_inventoryShipmentUnitOfWork).Execute(pickedInventoryModifications.Select(p => p.ToModifySourceInventoryParameters()).ToList(), null)); }
internal IResult <ProductionSchedule> Create(DateTime timestamp, CreateProductionScheduleParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(ProductionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionSchedule>()); } var location = ProductionUnitOfWork.LocationRepository.FindByKey(parameters.ProductionLocationKey); if (location == null || location.LocationType != LocationType.ProductionLine) { return(new InvalidResult <ProductionSchedule>(null, string.Format(UserMessages.ProductionLocationNotFound, parameters.ProductionLocationKey))); } if (ProductionUnitOfWork.ProductionScheduleRepository.Filter(p => p.ProductionDate == parameters.Parameters.ProductionDate && p.ProductionLineLocationId == location.Id).Any()) { return(new InvalidResult <ProductionSchedule>(null, string.Format(UserMessages.ProductionScheduleAlreadyExists, parameters.Parameters.ProductionDate.ToShortDateString(), location.Description))); } var packSchedules = ProductionUnitOfWork.PackScheduleRepository .Filter(p => p.ProductionLineLocationId == location.Id && p.ProductionBatches.Any(b => !b.ProductionHasBeenCompleted)) .Select(p => new { packSchedule = p, lastScheduled = p.ScheduledItems .OrderByDescending(i => i.ProductionSchedule.TimeStamp) .FirstOrDefault() }) .ToList(); var index = 0; var scheduledItems = new List <SetProductionScheduleItemParameters>(); foreach (var packSchedule in packSchedules .OrderByDescending(p => p.lastScheduled != null) .ThenBy(p => p.lastScheduled != null ? p.lastScheduled.Index : int.MaxValue) .ThenByDescending(p => p.lastScheduled != null ? p.lastScheduled.ProductionDate : DateTime.MinValue) .ThenBy(p => p.packSchedule.ScheduledProductionDate) .ThenBy(p => p.packSchedule.DateCreated) .ThenBy(p => p.packSchedule.SequentialNumber)) { var scheduledItem = new SetProductionScheduleItemParameters { PackScheduleKey = packSchedule.packSchedule.ToPackScheduleKey(), Index = index++ }; if (packSchedule.lastScheduled != null) { scheduledItem.FlushBefore = packSchedule.lastScheduled.FlushBefore; scheduledItem.FlushBeforeInstructions = packSchedule.lastScheduled.FlushBeforeInstructions; scheduledItem.FlushAfter = packSchedule.lastScheduled.FlushAfter; scheduledItem.FlushAfterInstructions = packSchedule.lastScheduled.FlushAfterInstructions; } scheduledItems.Add(scheduledItem); } var productionSchedule = ProductionUnitOfWork.ProductionScheduleRepository.Add(new ProductionSchedule { ProductionDate = parameters.Parameters.ProductionDate, ProductionLineLocationId = location.Id, ProductionLineLocation = location, ScheduledItems = new List <ProductionScheduleItem>() }); return(Set(productionSchedule, employeeResult.ResultingObject, timestamp, scheduledItems)); }
public IResult <ProductionBatch> Execute(DateTime timestamp, CreateProductionBatchCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var packSchedule = _productionUnitOfWork.PackScheduleRepository.FindByKey(parameters.PackScheduleKey, p => p.ChileProduct); if (packSchedule == null) { return(new InvalidResult <ProductionBatch>(null, string.Format(UserMessages.PackScheduleNotFound, parameters.PackScheduleKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(_productionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionBatch>()); } var createChileLotCommand = new CreateNewChileLotCommand(_productionUnitOfWork); var createChileLotResult = createChileLotCommand.Execute(new CreateNewChileLotCommandParameters { EmployeeKey = employeeResult.ResultingObject, TimeStamp = timestamp, PackagingReceivedKey = packSchedule, ChileProductKey = new ChileProductKey(packSchedule), LotType = parameters.Parameters.LotType ?? packSchedule.ChileProduct.ChileState.ToLotType(), LotDate = parameters.Parameters.LotDateCreated?.Date ?? timestamp, LotSequence = parameters.Parameters.LotSequence, SetLotProductionStatus = LotProductionStatus.Batched, SetLotQualityStatus = LotQualityStatus.Pending }); if (!createChileLotResult.Success) { return(createChileLotResult.ConvertTo <ProductionBatch>()); } var chileLot = createChileLotResult.ResultingObject; chileLot.Lot.Notes = parameters.Parameters.Notes.TrimTruncate(Constants.StringLengths.LotNotes); var productionResult = new CreateChileLotProductionCommand(_productionUnitOfWork).Execute(new CreateChileLotProduction { TimeStamp = timestamp, EmployeeKey = employeeResult.ResultingObject, LotKey = chileLot, ProductionType = ProductionType.ProductionBatch }); if (!productionResult.Success) { return(productionResult.ConvertTo <ProductionBatch>()); } var production = productionResult.ResultingObject; var notebookResult = new CreateNotebookCommand(_productionUnitOfWork).Execute(timestamp, employeeResult.ResultingObject, parameters.Parameters.Instructions); if (!notebookResult.Success) { return(notebookResult.ConvertTo <ProductionBatch>()); } var notebook = notebookResult.ResultingObject; var productionBatch = new ProductionBatch { EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timestamp, LotDateCreated = chileLot.LotDateCreated, LotDateSequence = chileLot.LotDateSequence, LotTypeId = chileLot.LotTypeId, PackScheduleDateCreated = parameters.PackScheduleKey.PackScheduleKey_DateCreated, PackScheduleSequence = parameters.PackScheduleKey.PackScheduleKey_DateSequence, InstructionNotebook = notebook, InstructionNotebookDateCreated = notebook.Date, InstructionNotebookSequence = notebook.Sequence, ProductionHasBeenCompleted = false, TargetParameters = new ProductionBatchTargetParameters(parameters.Parameters), Production = production }; _productionUnitOfWork.ProductionBatchRepository.Add(productionBatch); return(new SuccessResult <ProductionBatch>(productionBatch)); }