예제 #1
0
        /// <summary>
        /// Checks that the user has choosen allowed values for Booking Policies, and update
        /// current instance properly.
        /// For non-members, policies are restricted to default values.
        /// </summary>
        private void ValidateAndFixBookingPolicies()
        {
            var isMember = UserProfile.Get(userID).owner.status == LcEnum.OwnerStatus.active;

            if (!isMember)
            {
                // Enforce default policies
                instantBooking       = false;
                cancellationPolicyID = CancellationPolicy.DefaultCancellationPolicyID;
            }
        }
        private static int Insert(UserLicenseCertification item, bool internalUpdate = false)
        {
            // TODO, for an admin dashboard, we may need to implement internalUpdate allowing for update of all non-ID fields.
            if (internalUpdate)
            {
                throw new NotImplementedException("Internal update not implemented");
            }
            var user = UserProfile.Get(item.userID);

            using (var db = new LcDatabase())
            {
                // Constraint: licenses cannot be duplicated for an existant licenseID (>0), but they can for the special wildcard IDs (-1, 0)
                if (item.licenseCertificationID > 0)
                {
                    var many = (int)db.QueryValue("SELECT count(*) FROM UserLicenseCertifications WHERE ProviderUserID = @0 AND PositionID = @1 AND LicenseCertificationID = @2",
                                                  item.userID, item.jobTitleID, item.licenseCertificationID);
                    if (many > 0)
                    {
                        throw new ConstraintException("You have already registered that license, please try to update it if you want to submit a new file.");
                    }
                }

                return((int)db.QueryValue(sqlInsertNew,
                                          item.userID,
                                          item.jobTitleID,
                                          item.licenseCertificationID,
                                          2,
                                          "",
                                          "",
                                          null,
                                          "",
                                          user.firstName,
                                          user.lastName,
                                          "",
                                          "",
                                          "",
                                          "",
                                          "",
                                          item.userID,
                                          item.submittedImageLocalURL
                                          ));
            }
        }
예제 #3
0
        /// <summary>
        /// Set the user OwnerStatus in database, only if different from current
        /// one, and saving a status history entry.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="status"></param>
        public static void Set(Owner owner)
        {
            var currentOwner = UserProfile.Get(owner.userID).owner;

            if (currentOwner.status != owner.status)
            {
                var allowChange = currentOwner.CanTransitionTo(owner.status);

                if (allowChange)
                {
                    // Save on database, with a new entry at the status history
                    var his = new OwnerStatusHistory
                    {
                        userID                 = owner.userID,
                        ownerStatusID          = owner.statusID,
                        ownerStatusChangedDate = DateTime.Now,
                        ownerStatusChangedBy   = "sys"
                    };
                    using (var db = new LcDatabase())
                    {
                        var trans = db.Connection.BeginTransaction();
                        OwnerStatusHistory.Set(his, db);
                        db.Execute(@"
                            UPDATE Users SET OwnerStatusID = @1
                            WHERE UserID = @0

                            -- First time user enters 'active' status,
                            -- set the anniversary date.
                            -- Impl: we check if is active:2 and inside set date as current only if null
                            IF @1 = 2 begin
                                UPDATE Users SET OwnerAnniversaryDate = getdate()
                                WHERE UserID = @0 AND OwnerAnniversaryDate is null
                            END
                        ", owner.userID, owner.statusID);
                        trans.Commit();
                    }
                }
            }
        }