Esempio n. 1
0
        public SalesOrderSnapshot CreateNewSalesOrderSnapshot(Guid salesOrderId)
        {
            using (TrackerEntitiesContainer tec = GetNewTrackerObjectContext())
            {
                GetSalesOrderDetails_Result result = tec.GetSalesOrderDetails(salesOrderId).FirstOrDefault();
                if (result == null)
                {
                    return(null);
                }

                SalesOrderSnapshot snapshot = this.CreateSalesOrderSnapshot(result, salesOrderId);

                var historyEvents = tec.GetSalesOrderHistory(salesOrderId).OrderBy(he => he.eventDate);

                bool isFirstPrepayment = true;
                foreach (GetSalesOrderHistory_Result hResult in historyEvents)
                {
                    SalesOrderEvent soe = this.CreateSalesOrderEvent(hResult, snapshot, isFirstPrepayment);
                    snapshot.SalesOrderEvents.Add(soe);
                    if (soe.EventName == EventName.FirstPrepayment && isFirstPrepayment)
                    {
                        isFirstPrepayment = false;
                    }
                }

                return(snapshot);
            }
        }
Esempio n. 2
0
        public List <Event> CreateEventsList(SalesOrderSnapshot salesOrder)
        {
            List <Event> result = new List <Event>();

            if (salesOrder != null)
            {
                foreach (SalesOrderEvent salesOrderEvent in salesOrder.SalesOrderEvents.OrderBy(soe => soe.Date))
                {
                    Event createEvent = ToSOTEvent(salesOrderEvent, salesOrder);
                    if (createEvent != null)
                    {
                        result.Add(createEvent);
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        private Event ToSOTEvent(SalesOrderEvent salesOrderEvent, SalesOrderSnapshot salesOrder)
        {
            Event result = null;

            switch (salesOrderEvent.EventName)
            {
            case EventName.DocumentIssued:
                result = new DocumentIssuedEvent(salesOrderEvent.EventName, salesOrderEvent.ContractNumber, salesOrderEvent.Date.Value)
                {
                    Login    = salesOrder.Contractor.Login,
                    Password = salesOrder.Contractor.Password,
                    RelatedDocumentNumber = salesOrderEvent.Number
                };
                break;

            case EventName.DocumentSettled:
            case EventName.FirstPrepayment:
            case EventName.NextPrepayment:
            case EventName.RelatedSalesDocumentIssued:
                result = new RelatedDocumentEvent(salesOrderEvent.EventName, salesOrderEvent.ContractNumber, salesOrderEvent.Date.Value, salesOrderEvent.Number, salesOrderEvent.Value.Value);
                break;

            case EventName.MarkedAsPlanned:
                result = new MarkedAsPlannedEvent(salesOrderEvent.EventName, salesOrderEvent.ContractNumber, salesOrderEvent.Date.Value, salesOrder.ProductionOrderNumber);
                break;

            case EventName.MarkedAsReady:
            case EventName.MarkedAsReadyToInstallation:
                result = new Event(salesOrderEvent.EventName, salesOrderEvent.ContractNumber, salesOrderEvent.Date.Value);
                break;
            }
            if (result != null)
            {
                result.InitDescription();
                salesOrderEvent.Description = result.Description;
            }
            return(result);
        }
Esempio n. 4
0
        private SalesOrderEvent CreateSalesOrderEvent(GetSalesOrderHistory_Result hResult, SalesOrderSnapshot salesOrder, bool isFirstPrepayment)
        {
            var result = new SalesOrderEvent()
            {
                Date           = hResult.eventDate,
                Number         = hResult.documentNumber,
                Value          = hResult.documentValue,
                ContractNumber = salesOrder.Number
            };

            result.SetEventType(hResult.eventType.Value, salesOrder.SalesTypeName, isFirstPrepayment);
            return(result);
        }
Esempio n. 5
0
        public void PersistSalesOrderSnapshot(SalesOrderSnapshot salesOrderSnapshot, SalesOrderSnapshot oldSnapshot
                                              , List <Message> messages, TrackerEntitiesContainer tec)
        {
            #region Message references - create them and insert to collection
            foreach (Message message in messages)
            {
                MessageReference reference = new MessageReference()
                {
                    Id = Guid.NewGuid(), MessageId = message.Id, SalesOrderId = salesOrderSnapshot.Id
                };
                salesOrderSnapshot.MessageReferences.Add(reference);
            }
            #endregion

            #region Related Events - delete old events and create ids for new events
            if (oldSnapshot != null)
            {
                while (oldSnapshot.SalesOrderEvents.Count > 0)
                {
                    tec.DeleteObject(oldSnapshot.SalesOrderEvents.Last());
                }
            }
            foreach (SalesOrderEvent newEvent in salesOrderSnapshot.SalesOrderEvents)
            {
                newEvent.Id = Guid.NewGuid();
            }
            #endregion

            #region Set all objects state before saving

            object oldObject     = null;
            string entitySetName = tec.SalesOrderSnapshots.EntitySet.Name;
            tec.TryGetObjectByKey(tec.CreateEntityKey(entitySetName, salesOrderSnapshot), out oldObject);

            if (oldObject == null)
            {
                tec.AddObject(entitySetName, salesOrderSnapshot);                 //all related objects will be also added
            }
            else
            {
                tec.ApplyCurrentValues(entitySetName, salesOrderSnapshot);
                //salesOrderSnapshot remains detached. Status of related objects must be set manualy.
                oldSnapshot = (SalesOrderSnapshot)oldObject;

                while (salesOrderSnapshot.MessageReferences.Count > 0)
                {
                    oldSnapshot.MessageReferences.Add(salesOrderSnapshot.MessageReferences.Last());
                }
                //tec.AddObject(tec.MessageReferences.EntitySet.Name, messageReference);

                while (salesOrderSnapshot.SalesOrderEvents.Count > 0)
                {
                    oldSnapshot.SalesOrderEvents.Add(salesOrderSnapshot.SalesOrderEvents.Last());
                }
                //tec.AddObject(tec.SalesOrderEvents.EntitySet.Name, soEvent);
            }

            #endregion

            tec.SaveChanges();
        }