public static ApplicationTransaction FinishApplicationTransaction(int id, int?userID, DateTime?endTimestamp)
        {
            ApplicationTransaction ret = null;

            using (HistoryContext ctx = HistoryContext.CreateInstance())
            {
                ret = ctx.GetApplicationTransaction(id);
                if (ret == null)
                {
                    //TODO: throw.
                }
                if (userID.HasValue)
                {
                    ret.UserID = userID;
                }
                if (!endTimestamp.HasValue)
                {
                    endTimestamp = DateTime.Now;
                }
                ret.EndTimestamp = endTimestamp;

                ctx.SaveChanges();
            }

            return(ret);
        }
        public static ApplicationTransaction StartApplicationTransaction(string externalID, int?userID, string remoteEndPoint, string localEndPoint, string action, DateTime?beginTimestamp)
        {
            ApplicationTransaction ret = null;

            using (HistoryContext ctx = HistoryContext.CreateInstance())
            {
                ret                = new ApplicationTransaction();
                ret.ExternalID     = externalID;
                ret.UserID         = userID;
                ret.RemoteEndPoint = remoteEndPoint;
                ret.LocalEndPoint  = localEndPoint;
                ret.Action         = action;
                if (!beginTimestamp.HasValue)
                {
                    beginTimestamp = DateTime.Now;
                }
                ret.BeginTimestamp = beginTimestamp;

                ctx.AddToApplicationTransactionSet(ret);
                ctx.SaveChanges();
            }

            return(ret);
        }