Exemple #1
0
        private DryBoxAssignmentInfo CreateDryBoxAssignmentInfo(DryBoxAssignment dba, DryBox db, ClientAccount ca)
        {
            //var db = Require<DryBox>(dba.DryBoxID);
            //var ca = Require<ClientAccount>(dba.ClientAccountID);
            var co = ca.ClientOrg;
            var c  = co.Client;
            var a  = ca.Account;
            var o  = a.Org;

            return(new DryBoxAssignmentInfo
            {
                ClientID = c.ClientID,
                DryBoxName = db.DryBoxName,
                Active = db.Active,
                Visible = db.Visible,
                Deleted = db.Deleted,
                UserName = c.UserName,
                LName = c.LName,
                FName = c.FName,
                ShortCode = a.ShortCode,
                AccountName = a.Name,
                OrgName = o.OrgName,
                Email = co.Email,
                ApprovedDate = dba.ApprovedDate,
                ClientAccountID = dba.ClientAccountID,
                DryBoxAssignmentID = dba.DryBoxAssignmentID,
                DryBoxID = dba.DryBoxID,
                PendingApproval = dba.PendingApproval,
                PendingRemoval = dba.PendingRemoval,
                Rejected = dba.Rejected,
                RemovedDate = dba.RemovedDate,
                ReservedDate = dba.ReservedDate
            });
        }
Exemple #2
0
        private void ApproveDryBoxAssignment(DryBoxAssignment dba, ClientAccount ca, Client modifiedBy)
        {
            //add new row to DryBoxAssignmentLog table
            var dbalog = new DryBoxAssignmentLog
            {
                DryBoxAssignment = dba,
                ClientAccount    = ca,
                EnableDate       = DateTime.Now.Date,
                DisableDate      = null,
                ModifiedBy       = modifiedBy
            };

            Session.Save(dbalog);

            if (dbalog.DryBoxAssignmentLogID != 0)
            {
                //add new row to DryBoxAssignment table
                dba.PendingApproval = false;
                dba.PendingRemoval  = false;
                dba.Rejected        = false;
                dba.ApprovedDate    = DateTime.Now;
                dba.RemovedDate     = null;

                SaveOrUpdateAssignment(dba);
            }
            else
            {
                throw new Exception("Failed to save DryBoxAssignmentLog record.");
            }
        }
Exemple #3
0
        private void UpdateLog(DryBoxAssignment dba, ClientAccount ca, Client modifiedBy)
        {
            // Step 1:  Check for an existing log. There might not be one at this point if
            //          the reservation is requested and then updated before it's approved.
            var existing = Session.Query <DryBoxAssignmentLog>().FirstOrDefault(x => x.DryBoxAssignment == dba && x.DisableDate == null);

            if (existing != null)
            {
                // Step 2:  If a log is found set the DisableDate to today (otherwise nothing happens)

                existing.DisableDate = DateTime.Now.Date;

                // Step 3:  Check to see if this is a Remove (ca == null) or a Modify (ca != null)
                if (ca == null)
                {
                    // we are removing - set ModifiedBy (DisableDate set above)
                    existing.ModifiedBy = modifiedBy;
                }
                else
                {
                    // we are modifying - create a new log entry, using modifiedBy on the new entry
                    Session.Save(new DryBoxAssignmentLog
                    {
                        DryBoxAssignment = dba,
                        ClientAccount    = ca,
                        EnableDate       = DateTime.Now.Date,
                        DisableDate      = null,
                        ModifiedBy       = modifiedBy
                    });
                }

                // save the existing entry (DisableDate only when modifying, DisableDate and ModifiedBy when removing)
                Session.Update(existing);
            }
        }
Exemple #4
0
        public DryBoxAssignmentInfo Request(DryBoxRequest request)
        {
            DryBoxAssignment dba = new DryBoxAssignment
            {
                DryBoxID        = request.DryBoxID,
                ClientAccountID = request.ClientAccountID,
                ReservedDate    = DateTime.Now,
                ApprovedDate    = null,
                RemovedDate     = null,
                PendingApproval = true,
                PendingRemoval  = false,
                Rejected        = false
            };

            SaveOrUpdateAssignment(dba);

            return(CreateDryBoxAssignmentInfo(dba, Require <DryBox>(request.DryBoxID), Require <ClientAccount>(request.ClientAccountID)));
        }
Exemple #5
0
        private void SaveOrUpdateAssignment(DryBoxAssignment dba)
        {
            // sanity checks

            if (dba.Rejected)
            {
                // The following should be true when Rejected = 1
                //      ApprovedDate IS NULL
                //      RemovedDate IS NOT NULL
                //      PendingApproval = 0
                //      PendingRemoval = 0

                if (dba.ApprovedDate.HasValue)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because Rejected = 1 and ApprovedDate IS NOT NULL");
                }

                if (!dba.RemovedDate.HasValue)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because Rejected = 1 and RemovedDate IS NULL");
                }

                if (dba.PendingApproval)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because Rejected = 1 and PendingApproval = 1");
                }

                if (dba.PendingRemoval)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because Rejected = 1 and PendingApproval = 1");
                }
            }

            if (dba.PendingRemoval)
            {
                // The following should be true when PendingRemoval = 1
                //      ApprovedDate IS NOT NULL
                //      RemovedDate IS NULL
                //      PendingApproval = 0
                //      Rejected = 0

                if (!dba.ApprovedDate.HasValue)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingRemoval = 1 and ApprovedDate IS NULL");
                }

                if (dba.RemovedDate.HasValue)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingRemoval = 1 and RemovedDate IS NOT NULL");
                }

                if (dba.PendingApproval)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingRemoval = 1 and PendingApproval = 1");
                }

                if (dba.Rejected)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingRemoval = 1 and Rejected = 1");
                }
            }

            if (dba.PendingApproval)
            {
                // The following should be true when PendingApproval = 1
                //      ApprovedDate IS NULL
                //      RemovedDate IS NULL
                //      PendingRemoval = 0
                //      Rejected = 0

                if (dba.ApprovedDate.HasValue)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingApproval = 1 and ApprovedDate IS NOT NULL");
                }

                if (dba.RemovedDate.HasValue)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingApproval = 1 and RemovedDate IS NOT NULL");
                }

                if (dba.PendingRemoval)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingApproval = 1 and PendingRemoval = 1");
                }

                if (dba.Rejected)
                {
                    throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingApproval = 1 and Rejected = 1");
                }
            }

            if (!dba.PendingApproval && !dba.PendingRemoval && !dba.Rejected)
            {
                // The following should be true
                //      ApprovedDate IS NOT NULL (RemovedDate can be NULL or NOT NULL)
                //      OR
                //      ApprovedDate IS NULL and RemovedDate IS NOT NULL (this happens when a request is cancelled)

                if (!dba.ApprovedDate.HasValue)
                {
                    if (!dba.RemovedDate.HasValue)
                    {
                        throw new Exception($"DryBoxAssignment#{dba.DryBoxAssignmentID} cannot be updated because PendingApproval = 0 and PendingRemoval = 0 and Rejected = 0 and ApprovedDate IS NULL and RemovedDate IS NULL");
                    }
                }
            }

            // all checks passed
            Session.SaveOrUpdate(dba);
        }