protected override void OnSaving()
 {
     base.OnSaving();
     if (!(Session is NestedUnitOfWork) &&
         (Session.DataLayer != null) &&
         (Session.ObjectLayer is SimpleObjectLayer)
         )
     {
         if (Session.IsNewObject(this))
         {
             PurchaseOrderDocStatus ds = new PurchaseOrderDocStatus(Session);
             ds.DocStatus        = DocStatus.Draft;
             ds.DocStatusRemarks = "";
             if (!GeneralValues.IsNetCore)
             {
                 ds.CreateUser = Session.GetObjectByKey <SystemUsers>(SecuritySystem.CurrentUserId);
             }
             else
             {
                 ds.CreateUser = Session.FindObject <SystemUsers>(CriteriaOperator.Parse("UserName=?", GeneralValues.NetCoreUserName));
             }
             ds.CreateDate = DateTime.Now;
             this.DocumentStatus.Add(ds);
         }
         else
         {
         }
     }
 }
        //public void assignCurrDocStatus()
        //{
        //    if (DocumentStatus.Count > 0)
        //        CurrDocStatus = DocumentStatus.OrderByDescending<PurchaseOrderDocStatus, DateTime?>(pp => pp.CreateDate).First<PurchaseOrderDocStatus>().DocStatus;

        //}
        public void AddDocStatus(DocStatus newstatus, string remarks)
        {
            PurchaseOrderDocStatus ds = new PurchaseOrderDocStatus(Session);

            ds.DocStatus        = newstatus;
            ds.DocStatusRemarks = remarks;
            if (!GeneralValues.IsNetCore)
            {
                ds.CreateUser = Session.GetObjectByKey <SystemUsers>(SecuritySystem.CurrentUserId);
            }
            else
            {
                ds.CreateUser = Session.FindObject <SystemUsers>(CriteriaOperator.Parse("UserName=?", GeneralValues.NetCoreUserName));
            }
            ds.CreateDate = DateTime.Now;
            this.DocumentStatus.Add(ds);
        }