Ejemplo n.º 1
0
            public void Serializes_Contract_with_updated_Comments_Note_in_old_context()
            {
                //Arrange
                const string updatedNote = "Updated contract comment!";
                var          contract    = RVCUnitOfWork.ContractRepository
                                           .Filter(c => c.Comments.Notes.Count() == 1 && c.Comments.Notes.All(n => n.Text != updatedNote), c => c.Comments.Notes)
                                           .FirstOrDefault();

                if (contract == null)
                {
                    Assert.Inconclusive("No suitable test contract found.");
                }
                var noteKey = new NoteKey(contract.Comments.Notes.Single());

                //Assert
                var result = Service.UpdateNote(noteKey, new UpdateNoteParameters
                {
                    UserToken = TestUser.UserName,
                    Text      = updatedNote
                });
                var contractKeyString = GetKeyFromConsoleString(ConsoleOutput.SynchronizedContract);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var contractId = int.Parse(contractKeyString);

                using (var oldContext = new RioAccessSQLEntities())
                {
                    var serialized         = oldContext.tblContracts.First(c => c.ContractID == contractId).Serialized;
                    var serializedContract = SerializableContract.Deserialize(serialized);
                    Assert.AreEqual(updatedNote, serializedContract.Notes.Single().Text);
                }
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor from an object deserialized from the settings file.
 /// </summary>
 /// <param name="ccpCharacter">The CCP character.</param>
 /// <param name="src">The source.</param>
 internal Contract(CCPCharacter ccpCharacter, SerializableContract src)
 {
     Character = ccpCharacter;
     ID        = src.ContractID;
     IssuedFor = src.IssuedFor;
     if (IssuedFor == IssuedFor.Corporation)
     {
         IssuerID = Character.CharacterID;
     }
     m_state = src.ContractState;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor from an object deserialized from the settings file.
 /// </summary>
 /// <param name="ccpCharacter">The CCP character.</param>
 /// <param name="src">The source.</param>
 internal Contract(CCPCharacter ccpCharacter, SerializableContract src)
 {
     Character = ccpCharacter;
     ID        = src.ContractID;
     IssuedFor = src.IssuedFor;
     if (IssuedFor == IssuedFor.Corporation)
     {
         IssuerID = Character.CharacterID;
     }
     m_state = src.ContractState;
     m_bids  = new LinkedList <ContractBid>();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor from an object deserialized from the settings file.
        /// </summary>
        /// <param name="ccpCharacter">The CCP character.</param>
        /// <param name="src">The source.</param>
        internal Contract(CCPCharacter ccpCharacter, SerializableContract src)
        {
            src.ThrowIfNull(nameof(src));

            m_bidsResponse = m_itemsResponse = null;
            Character      = ccpCharacter;
            ID             = src.ContractID;
            IssuedFor      = src.IssuedFor;
            if (IssuedFor == IssuedFor.Corporation)
            {
                IssuerID = Character.CharacterID;
            }
            m_state = src.ContractState;
            m_bids  = new LinkedList <ContractBid>();
        }
        private ContractLoad GetContract(tblContractDTO oldContract)
        {
            var key             = _contractKeyReservationHelper.ParseAndRegisterKey(oldContract.SerializedKey);
            var requiresKeySync = key == null;

            _loadCount.AddRead(EntityType.Contract);

            var timestamp = oldContract.EntryDate.ConvertLocalToUTC() ?? oldContract.KDate ?? oldContract.BegDate;

            if (timestamp == null)
            {
                Log(new CallbackParameters(CallbackReason.UnderterminedTimestamp)
                {
                    OldContract = oldContract
                });
                return(null);
            }

            if (oldContract.KDate == null)
            {
                Log(new CallbackParameters(CallbackReason.NullContractDate)
                {
                    OldContract = oldContract
                });
                return(null);
            }

            var employeeId = _newContextHelper.DefaultEmployee.EmployeeId;

            if (oldContract.EmployeeId == null)
            {
                Log(new CallbackParameters(CallbackReason.DefaultEmployee)
                {
                    OldContract = oldContract
                });
            }
            else
            {
                employeeId = oldContract.EmployeeId.Value;
            }

            var customer = _newContextHelper.GetCompany(oldContract.Company_IA, CompanyType.Customer);

            if (customer == null)
            {
                Log(new CallbackParameters(CallbackReason.CustomerNotLoaded)
                {
                    OldContract = oldContract
                });
                return(null);
            }

            var broker = _newContextHelper.GetCompany(oldContract.Broker, CompanyType.Broker);

            if (broker == null)
            {
                Log(new CallbackParameters(CallbackReason.BrokerNotLoaded)
                {
                    OldContract = oldContract
                });
                return(null);
            }

            Facility facility = null;

            if (oldContract.WHID == null)
            {
                facility = _newContextHelper.Facilities.Values.FirstOrDefault(f => f.Name == "Rincon");
                Log(new CallbackParameters(CallbackReason.DefaultRinconWarehouse)
                {
                    OldContract = oldContract
                });
            }
            else
            {
                facility = _newContextHelper.GetFacility(oldContract.WHID);
            }

            if (facility == null)
            {
                Log(new CallbackParameters(CallbackReason.WarehouseNotLoaded)
                {
                    OldContract = oldContract
                });
                return(null);
            }

            var contractType = GetContractType(oldContract.KType);

            if (contractType == null)
            {
                Log(new CallbackParameters(CallbackReason.UndeterminedContractType)
                {
                    OldContract = oldContract
                });
                return(null);
            }

            var contractStatus = GetContractStatus(oldContract.KStatus);

            if (contractStatus == null)
            {
                Log((new CallbackParameters(CallbackReason.UndeterminedContractStatus)
                {
                    OldContract = oldContract
                }));
                return(null);
            }

            var commentsNotebook = _notebookFactory.BirthNext(timestamp.Value, employeeId, oldContract.Comments);

            key = key ?? _contractKeyReservationHelper.GetNextAndRegisterKey(new ContractKeyReservationHelper.Key
            {
                ContractKey_Year     = oldContract.KDate.Value.Year,
                ContractKey_Sequence = 0
            });

            var newContract = new ContractLoad
            {
                RequiresKeySync = requiresKeySync,
                EmployeeId      = oldContract.EmployeeId ?? _newContextHelper.DefaultEmployee.EmployeeId,
                TimeStamp       = timestamp.Value,

                ContractYear     = key.ContractKey_Year,
                ContractSequence = key.ContractKey_Sequence,

                ContractId  = oldContract.ContractID,
                CustomerId  = customer.Id,
                ContactName = oldContract.Contact_IA,
                FOB         = oldContract.FOB,
                BrokerId    = broker.Id,
                DefaultPickFromWarehouseId = facility.Id,

                ContractType   = contractType.Value,
                ContractStatus = contractStatus.Value,
                ContractDate   = oldContract.KDate.Value,
                TimeCreated    = timestamp.Value.Date,
                TermBegin      = oldContract.BegDate.GetDate(),
                TermEnd        = oldContract.EndDate.GetDate(),

                PaymentTerms          = oldContract.PmtTerms,
                NotesToPrint          = oldContract.Notes2Print,
                CustomerPurchaseOrder = oldContract.PONum,
                ContactAddress        = new Address
                {
                    AddressLine1 = oldContract.Address1_IA,
                    AddressLine2 = oldContract.Address2_IA,
                    AddressLine3 = oldContract.Address3_IA,
                    City         = oldContract.City_IA,
                    State        = oldContract.State_IA,
                    PostalCode   = oldContract.Zip_IA,
                    Country      = oldContract.Country_IA
                },

                CommentsDate     = commentsNotebook.Date,
                CommentsSequence = commentsNotebook.Sequence,
                Comments         = commentsNotebook
            };

            SerializableContract.DeserializeIntoContract(newContract, oldContract.Serialized);

            GetContractItems(newContract, oldContract);

            return(newContract);
        }
Ejemplo n.º 6
0
        private void SynchronizeOldContract(Contract contract, tblContract oldContract)
        {
            var warehouse = OldContextHelper.GetWarehouse(contract.DefaultPickFromFacility.Name);

            if (warehouse == null)
            {
                throw new Exception(string.Format("Could not find tblWarehouse with WhouseAbbr[{0}].", contract.DefaultPickFromFacility.Name));
            }

            oldContract.EmployeeID = contract.EmployeeId;
            oldContract.KDate      = contract.ContractDate;
            oldContract.BegDate    = contract.TermBegin;
            oldContract.EndDate    = contract.TermEnd;

            oldContract.Contact_IA  = contract.ContactName;
            oldContract.Company_IA  = contract.Customer.Company.Name;
            oldContract.Address1_IA = contract.ContactAddress.AddressLine1;
            oldContract.Address2_IA = contract.ContactAddress.AddressLine2;
            oldContract.Address3_IA = contract.ContactAddress.AddressLine3;
            oldContract.City_IA     = contract.ContactAddress.City;
            oldContract.State_IA    = contract.ContactAddress.State;
            oldContract.Zip_IA      = contract.ContactAddress.PostalCode;
            oldContract.Country_IA  = contract.ContactAddress.Country;
            oldContract.Broker      = contract.Broker.Name;
            oldContract.PmtTerms    = contract.PaymentTerms;
            oldContract.PONum       = contract.CustomerPurchaseOrder;
            oldContract.KType       = contract.ContractType.ToString();
            oldContract.KStatus     = contract.ContractStatus.ToString();
            oldContract.FOB         = contract.FOB;
            oldContract.Comments    = contract.Comments.Notes.AggregateNotes();
            oldContract.Notes2Print = contract.NotesToPrint;
            oldContract.WHID        = warehouse.WHID;

            oldContract.Serialized = SerializableContract.Serialize(contract);

            var existingDetails = oldContract.tblContractDetails != null?oldContract.tblContractDetails.ToList() : new List <tblContractDetail>();

            var kDetailId = OldContext.tblContractDetails.Any() ? OldContext.tblContractDetails.Max(d => d.KDetailID) : DateTime.UtcNow.ConvertUTCToLocal();

            foreach (var item in contract.ContractItems)
            {
                var detail = item.KDetailID == null ? null : existingDetails.FirstOrDefault(d => d.KDetailID == item.KDetailID.Value);
                if (detail == null)
                {
                    kDetailId = kDetailId.AddSeconds(1);
                    detail    = new tblContractDetail
                    {
                        KDetailID  = kDetailId,
                        ContractID = oldContract.ContractID
                    };
                    OldContext.tblContractDetails.AddObject(detail);
                    item.KDetailID    = kDetailId;
                    _commitNewContext = true;
                }
                else
                {
                    existingDetails.Remove(detail);
                }

                detail.ProdID          = OldContextHelper.GetProduct(item.ChileProduct).ProdID;
                detail.PkgID           = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID;
                detail.Quantity        = item.Quantity;
                detail.TrtmtID         = OldContextHelper.GetTreatment(item).TrtmtID;
                detail.Price           = (decimal?)item.PriceBase;
                detail.FreightP        = (decimal?)item.PriceFreight;
                detail.TrtnmntP        = (decimal?)item.PriceTreatment;
                detail.WHCostP         = (decimal?)item.PriceWarehouse;
                detail.Rebate          = (decimal?)item.PriceRebate;
                detail.CustProductCode = item.CustomerProductCode;
                detail.Spec            = item.UseCustomerSpec ? "Cust" : "RVC";
                detail.TtlWgt          = (decimal?)(item.Quantity * item.PackagingProduct.Weight);
            }

            foreach (var detail in existingDetails)
            {
                OldContext.tblContractDetails.DeleteObject(detail);
            }
        }