public IResult Execute(SampleOrderKey sampleOrderKey, out int?sampleId) { if (sampleOrderKey == null) { throw new ArgumentNullException("sampleOrderKey"); } sampleId = null; var sampleOrder = _sampleOrderUnitOfWork.SampleOrderRepository.FindByKey(sampleOrderKey, o => o.JournalEntries, o => o.Items.Select(i => i.Spec), o => o.Items.Select(i => i.Match)); if (sampleOrder == null) { return(new NoWorkRequiredResult()); } sampleId = sampleOrder.SampleID; foreach (var item in sampleOrder.Items.ToList()) { if (item.Spec != null) { _sampleOrderUnitOfWork.SampleOrderItemSpecRepository.Remove(item.Spec); } if (item.Match != null) { _sampleOrderUnitOfWork.SampleOrderItemMatchRepository.Remove(item.Match); } _sampleOrderUnitOfWork.SampleOrderItemRepository.Remove(item); } foreach (var entry in sampleOrder.JournalEntries.ToList()) { _sampleOrderUnitOfWork.SampleOrderJournalEntryRepository.Remove(entry); } _sampleOrderUnitOfWork.SampleOrderRepository.Remove(sampleOrder); return(new SuccessResult()); }
internal static IResult <SetSampleOrderParameters> ToParsedParameters(this ISetSampleOrderParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } SampleOrderKey sampleOrderKey = null; if (!string.IsNullOrWhiteSpace(parameters.SampleOrderKey)) { var sampleOrderKeyResult = KeyParserHelper.ParseResult <ISampleOrderKey>(parameters.SampleOrderKey); if (!sampleOrderKeyResult.Success) { return(sampleOrderKeyResult.ConvertTo <SetSampleOrderParameters>()); } sampleOrderKey = sampleOrderKeyResult.ResultingObject.ToSampleOrderKey(); } CustomerKey requestCustomerKey = null; if (!string.IsNullOrWhiteSpace(parameters.RequestedByCompanyKey)) { var customerKeyResult = KeyParserHelper.ParseResult <ICustomerKey>(parameters.RequestedByCompanyKey); if (!customerKeyResult.Success) { return(customerKeyResult.ConvertTo <SetSampleOrderParameters>()); } requestCustomerKey = customerKeyResult.ResultingObject.ToCustomerKey(); } CompanyKey brokerKey = null; if (!string.IsNullOrWhiteSpace(parameters.BrokerKey)) { var companyKey = KeyParserHelper.ParseResult <ICompanyKey>(parameters.BrokerKey); if (!companyKey.Success) { return(companyKey.ConvertTo <SetSampleOrderParameters>()); } brokerKey = companyKey.ResultingObject.ToCompanyKey(); } var itemParameters = parameters.Items.ToParsedParameters(ToParsedParameters); if (!itemParameters.Success) { return(itemParameters.ConvertTo <SetSampleOrderParameters>()); } return(new SuccessResult <SetSampleOrderParameters>(new SetSampleOrderParameters { Parameters = parameters, SampleOrderKey = sampleOrderKey, RequestCustomerKey = requestCustomerKey, BrokerKey = brokerKey, Items = itemParameters.ResultingObject })); }
private tblSample Sync(SampleOrderKey sampleOrderKey, out bool commitNewContext) { commitNewContext = false; var sampleOrder = UnitOfWork.SampleOrderRepository.FindByKey(sampleOrderKey, s => s.Broker, s => s.RequestCustomer.Company, s => s.JournalEntries, s => s.Items.Select(i => i.Product), s => s.Items.Select(i => i.Lot), s => s.Items.Select(i => i.Spec), s => s.Items.Select(i => i.Match)); if(sampleOrder == null) { throw new Exception(string.Format("Could not load SampleOrder[{0}]", sampleOrderKey)); } var tblSample = GetTblSampleRecords(sampleOrder.SampleID); if(tblSample == null) { commitNewContext = true; var minSampleId = sampleOrder.Year * 1000; var sampleId = OldContext.tblSamples.Select(s => s.SampleID).Where(i => i > minSampleId).DefaultIfEmpty(minSampleId).Max() + 1; tblSample = new tblSample { SampleID = sampleId, tblSampleNotes = new EntityCollection<tblSampleNote>(), tblSampleDetails = new EntityCollection<tblSampleDetail>(), s_GUID = Guid.NewGuid() }; OldContext.tblSamples.AddObject(tblSample); sampleOrder.SampleID = tblSample.SampleID; } tblSample.EmployeeID = sampleOrder.EmployeeId; tblSample.EntryDate = sampleOrder.TimeStamp.ConvertUTCToLocal(); tblSample.Comments = sampleOrder.Comments; tblSample.Notes2Print = sampleOrder.PrintNotes; tblSample.Volume = (decimal?) sampleOrder.Volume; tblSample.SampleDate = sampleOrder.DateDue; tblSample.DateRecd = sampleOrder.DateReceived; tblSample.DateCompleted = sampleOrder.DateCompleted; tblSample.Completed = sampleOrder.DateCompleted.HasValue; tblSample.Priority = sampleOrder.ShipmentMethod; tblSample.FOB = sampleOrder.FOB; tblSample.Status = sampleOrder.Status.ToDisplayString(); tblSample.Active = sampleOrder.Active; tblSample.Company_IA = sampleOrder.RequestCustomer == null ? null : sampleOrder.RequestCustomer.Company.Name; tblSample.Broker = sampleOrder.Broker == null ? null : sampleOrder.Broker.Name; tblSample.Contact_IA = sampleOrder.Request.Name; tblSample.Address1_IA = sampleOrder.Request.Address.AddressLine1; tblSample.Address2_IA = sampleOrder.Request.Address.AddressLine2; tblSample.Address3_IA = sampleOrder.Request.Address.AddressLine3; tblSample.City_IA = sampleOrder.Request.Address.City; tblSample.State_IA = sampleOrder.Request.Address.State; tblSample.Zip_IA = sampleOrder.Request.Address.PostalCode; tblSample.Country_IA = sampleOrder.Request.Address.Country; tblSample.SCompany = sampleOrder.ShipToCompany; tblSample.SContact = sampleOrder.ShipTo.Name; tblSample.SPhone = sampleOrder.ShipTo.Phone; tblSample.SAddress1 = sampleOrder.ShipTo.Address.AddressLine1; tblSample.SAddress2 = sampleOrder.ShipTo.Address.AddressLine2; tblSample.SAddress3 = sampleOrder.ShipTo.Address.AddressLine3; tblSample.SCity = sampleOrder.ShipTo.Address.City; tblSample.SState = sampleOrder.ShipTo.Address.State; tblSample.SZip = sampleOrder.ShipTo.Address.PostalCode; tblSample.SCountry = sampleOrder.ShipTo.Address.Country; SetTblSampleNotes(tblSample, sampleOrder, ref commitNewContext); SetTblSampleDetails(tblSample, sampleOrder, ref commitNewContext); return tblSample; }