protected override void OnSaving()
 {
     base.OnSaving();
     if (!(Session is NestedUnitOfWork) &&
         (Session.DataLayer != null) &&
         (Session.ObjectLayer is SimpleObjectLayer)
         )
     {
         if (Session.IsNewObject(this))
         {
             PurchaseReturnDocStatus ds = new PurchaseReturnDocStatus(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<PurchaseReturnDocStatus, DateTime?>(pp => pp.CreateDate).First<PurchaseReturnDocStatus>().DocStatus;

        //}
        public void AddDocStatus(DocStatus newstatus, string remarks)
        {
            PurchaseReturnDocStatus ds = new PurchaseReturnDocStatus(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);
        }