Exemple #1
0
 private Approver UpdateApprover(Ordering.Approver appr, bool isPrimary)
 {
     if (appr == null)
     {
         return(null);
     }
     appr.Active = true;
     SetPrimary(appr, isPrimary);
     return(CreateApprover(appr));
 }
Exemple #2
0
        public override bool Equals(object obj)
        {
            Approver item = obj as Approver;

            if (item == null)
            {
                return(false);
            }
            return(item.ApproverID == ApproverID && item.ClientID == ClientID);
        }
Exemple #3
0
 private Approver AddApprover(Ordering.Approver appr, bool isPrimary)
 {
     if (appr == null)
     {
         return(null);
     }
     appr.Active = true;
     DataSession.Insert(appr);
     SetPrimary(appr, isPrimary);
     return(CreateApprover(appr));
 }
Exemple #4
0
        internal Ordering.Approver Require(Ordering.Approver id)
        {
            var result = DataSession.Single <Ordering.Approver>(id);

            if (result == null)
            {
                throw new ItemNotFoundException("Approver", $"ClientID = {id.ClientID} and ApproverID = {id.ApproverID}");
            }

            return(result);
        }
Exemple #5
0
        private Data.Client GetApproverForCopy(Ordering.PurchaseOrder po)
        {
            var currentClientId = Context.CurrentUser.ClientID;

            Data.Client approver;

            if (po.Client.ClientID != currentClientId)
            {
                // check if the current user has the same approver
                var app = DataSession.Query <Ordering.Approver>().FirstOrDefault(x => x.ApproverID == po.Approver.ClientID && x.ClientID == currentClientId);

                if (app == null)
                {
                    // use the current user's primary approver
                    var defapp = DataSession.Query <Ordering.Approver>().FirstOrDefault(x => x.Active && x.ClientID == currentClientId && x.IsPrimary);

                    if (defapp == null)
                    {
                        // fall-back: copy the po approver
                        app = new Ordering.Approver()
                        {
                            Active     = true,
                            ApproverID = po.Approver.ClientID,
                            ClientID   = currentClientId,
                            IsPrimary  = true //because the current user has no active primary at the moment
                        };

                        DataSession.Insert(app);

                        approver = po.Approver;
                    }
                    else
                    {
                        approver = Require <Data.Client>(x => x.ClientID, defapp.ApproverID);
                    }
                }
                else
                {
                    app.Active = true; //just in case
                    approver   = Require <Data.Client>(x => x.ClientID, app.ApproverID);
                }
            }
            else
            {
                approver = po.Approver;
            }

            return(approver);
        }
Exemple #6
0
        public Approver AddOrUpdateApprover(int clientId, int approverId, bool isPrimary)
        {
            var appr = new Ordering.Approver {
                ClientID = clientId, ApproverID = approverId, IsPrimary = false
            };
            var existing = DataSession.Single <Ordering.Approver>(appr);

            if (existing == null)
            {
                return(AddApprover(appr, isPrimary));
            }
            else
            {
                return(UpdateApprover(existing, isPrimary));
            }
        }
Exemple #7
0
        private Approver CreateApprover(Ordering.Approver app)
        {
            var c = Require <Data.ClientInfo>(x => x.ClientID, app.ApproverID);

            return(new Approver()
            {
                ClientID = app.ClientID,
                UserName = c.UserName,
                ApproverID = app.ApproverID,
                FName = c.FName,
                LName = c.LName,
                Email = c.Email,
                Phone = c.Phone,
                IsPrimary = app.IsPrimary,
                Active = app.Active
            });
        }
Exemple #8
0
        private void SetPrimary(Ordering.Approver appr, bool isPrimary)
        {
            if (appr.IsPrimary != isPrimary)
            {
                if (isPrimary)
                {
                    // get the current primary approver, if any
                    var currentPrimary = DataSession.Query <Ordering.Approver>().Where(x => x.ClientID == appr.ClientID && x.ApproverID != appr.ApproverID && x.IsPrimary);

                    // set any found to false
                    foreach (var cp in currentPrimary)
                    {
                        cp.IsPrimary = false;
                    }

                    // set this approver to primary
                    appr.IsPrimary = true;
                }
                else
                {
                    appr.IsPrimary = false;
                }
            }
        }