Beispiel #1
0
        public void WriteTransitionHistory(Guid id, string currentState, string nextState, string command, IEnumerable <string> identities)
        {
            using (var session = Store.OpenSession())
            {
                var doc = session.Load <Entities.Document>(id);

                if (doc == null)
                {
                    throw new ArgumentException("Document not found", "id");
                }

                var historyItem = new Entities.DocumentTransitionHistory
                {
                    Id = Guid.NewGuid(),
                    AllowedToEmployeeNames = GetEmployeesString(identities),
                    DestinationState       = nextState,
                    InitialState           = currentState,
                    Command = command
                };

                doc.TransitionHistories.Add(historyItem);

                session.SaveChanges();
            }
        }
        public void UpdateTransitionHistory(Guid id, string currentState, string nextState, string command, Guid?employeeId)
        {
            var db = _connector.GetDatabase();

            var doc = GetDocument(db, id);

            if (doc == null)
            {
                throw new ArgumentException("Document not found", nameof(id));
            }

            var historyItem = doc.TransitionHistories.FirstOrDefault(h => !h.TransitionTime.HasValue &&
                                                                     h.InitialState == currentState &&
                                                                     h.DestinationState == nextState);

            if (historyItem == null)
            {
                historyItem = new Entities.DocumentTransitionHistory
                {
                    Id = Guid.NewGuid(),
                    AllowedToEmployeeNames = string.Empty,
                    DestinationState       = nextState,
                    InitialState           = currentState
                };

                doc.TransitionHistories.Add(historyItem);
            }

            historyItem.Command        = command;
            historyItem.TransitionTime = DateTime.Now;
            historyItem.EmployeeId     = employeeId;

            if (employeeId.HasValue)
            {
                var employee = GetEmployee(db, employeeId.Value);
                historyItem.EmployeeName = employee.Name;
            }
            else
            {
                historyItem.EmployeeName = null;
            }

            var batch = db.CreateBatch();

            SaveDocument(batch, doc);
            if (employeeId.HasValue)
            {
                batch.SortedSetAddAsync(GetKeyForOutboxDocuments(employeeId.Value), id.ToString(), GetNextOutboxNumber(db));
            }

            batch.Execute();
        }
Beispiel #3
0
        public void UpdateTransitionHistory(Guid id, string currentState, string nextState, string command, Guid?employeeId)
        {
            using (var session = Store.OpenSession())
            {
                var doc = session.Load <Entities.Document>(id);

                if (doc == null)
                {
                    throw new ArgumentException("Document not found", "id");
                }

                var historyItem = doc.TransitionHistories.FirstOrDefault(h => !h.TransitionTime.HasValue &&
                                                                         h.InitialState == currentState &&
                                                                         h.DestinationState == nextState);

                if (historyItem == null)
                {
                    historyItem = new Entities.DocumentTransitionHistory
                    {
                        Id = Guid.NewGuid(),
                        AllowedToEmployeeNames = string.Empty,
                        DestinationState       = nextState,
                        InitialState           = currentState
                    };

                    doc.TransitionHistories.Add(historyItem);
                }

                historyItem.Command        = command;
                historyItem.TransitionTime = DateTime.Now;
                historyItem.EmployeeId     = employeeId;

                if (employeeId.HasValue)
                {
                    var employee = session.Load <Entities.Employee>(employeeId.Value);
                    historyItem.EmployeeName = employee.Name;
                }
                else
                {
                    historyItem.EmployeeName = null;
                }

                session.SaveChanges();
            }
        }
        public void UpdateTransitionHistory(Guid id, string currentState, string nextState, string command, Guid?employeeId)
        {
            var dbcoll = Store.GetCollection <Entities.Document>("Document");
            var doc    = dbcoll.Find(x => x.Id == id).FirstOrDefault();

            if (doc == null)
            {
                throw new ArgumentException("Document not found", "id");
            }

            var historyItem = doc.TransitionHistories.FirstOrDefault(h => !h.TransitionTime.HasValue &&
                                                                     h.InitialState == currentState &&
                                                                     h.DestinationState == nextState);

            if (historyItem == null)
            {
                historyItem = new Entities.DocumentTransitionHistory
                {
                    Id = Guid.NewGuid(),
                    AllowedToEmployeeNames = string.Empty,
                    DestinationState       = nextState,
                    InitialState           = currentState
                };

                doc.TransitionHistories.Add(historyItem);
            }

            historyItem.Command        = command;
            historyItem.TransitionTime = DateTime.Now;
            historyItem.EmployeeId     = employeeId;

            if (employeeId.HasValue)
            {
                var employee = Store.GetCollection <Entities.Employee>("Employee").Find(x => x.Id == employeeId.Value).FirstOrDefault();
                historyItem.EmployeeName = employee.Name;
            }
            else
            {
                historyItem.EmployeeName = null;
            }

            dbcoll.ReplaceOne(x => x.Id == doc.Id, doc, new UpdateOptions {
                IsUpsert = true
            });
        }
        public void WriteTransitionHistory(Guid id, string currentState, string nextState, string command, IEnumerable <string> identities)
        {
            var db = _connector.GetDatabase();

            var doc = GetDocument(db, id);

            if (doc == null)
            {
                throw new ArgumentException("Document not found", "id");
            }

            var historyItem = new Entities.DocumentTransitionHistory
            {
                Id = Guid.NewGuid(),
                AllowedToEmployeeNames = GetEmployeesString(db, identities),
                DestinationState       = nextState,
                InitialState           = currentState,
                Command = command
            };

            doc.TransitionHistories.Add(historyItem);

            SaveDocument(db, doc);
        }
        public void WriteTransitionHistory(Guid id, string currentState, string nextState, string command, IEnumerable <string> identities)
        {
            var dbcoll = Store.GetCollection <Entities.Document>("Document");
            var doc    = dbcoll.Find(x => x.Id == id).FirstOrDefault();

            if (doc == null)
            {
                throw new ArgumentException("Document not found", "id");
            }

            var historyItem = new Entities.DocumentTransitionHistory
            {
                Id = Guid.NewGuid(),
                AllowedToEmployeeNames = GetEmployeesString(identities),
                DestinationState       = nextState,
                InitialState           = currentState,
                Command = command
            };

            doc.TransitionHistories.Add(historyItem);
            dbcoll.ReplaceOne(x => x.Id == doc.Id, doc, new UpdateOptions {
                IsUpsert = true
            });
        }