Exemplo n.º 1
0
 /* Notes: serialized values of SubscriptionStatus
  * Braintree.SubscriptionStatus.STATUSES.Select(s => s.ToString());
  *  string "Active"
  *  string "Canceled"
  *  string "Expired"
  *  string "Past Due"
  *  string "Pending"
  */
 /// <summary>
 /// Run membership requirements checks and returns
 /// the OwnerStatus that is expected for the user based on that
 /// (but is not saved and previous status is not checked).
 /// </summary>
 /// <param name="userID"></param>
 /// <returns>Status based on requirements</returns>
 public static LcEnum.OwnerStatus GetExpectedOwnerStatus(int userID)
 {
     // Check all requirements
     if (UserJobTitle.MeetsOwnershipRequirement(userID) &&
         OwnerAcknowledgment.MeetsOwnsershipRequirement(userID) &&
         UserPaymentPlan.MeetsOwnsershipRequirement(userID))
     {
         // It's OK
         return(LcEnum.OwnerStatus.active);
     }
     else
     {
         // It failed
         var status = UserPaymentPlan.GetLastPaymentPlanStatus(userID);
         if (status == Braintree.SubscriptionStatus.CANCELED)
         {
             return(LcEnum.OwnerStatus.cancelled);
         }
         else if (status == Braintree.SubscriptionStatus.EXPIRED)
         {
             return(LcEnum.OwnerStatus.suspended);
         }
         else
         {
             return(LcEnum.OwnerStatus.inactive);
         }
     }
 }
Exemplo n.º 2
0
        public static bool Update(UserJobTitle userJobTitle)
        {
            userJobTitle.ValidateAndFixBookingPolicies();
            var sqlUpdate = @"
                UPDATE  UserProfilePositions
                SET     PositionIntro = @4,
                        CancellationPolicyID = @5,
                        InstantBooking = @6,
                        collectPaymentAtBookMeButton = @7,
                        UpdatedDate = getdate()
                WHERE   UserID = @0 AND PositionID = @1
                    AND LanguageID = @2
                    AND CountryID = @3
            ";

            using (var db = new LcDatabase())
            {
                var affected = db.Execute(sqlUpdate,
                                          userJobTitle.userID,
                                          userJobTitle.jobTitleID,
                                          LcData.GetCurrentLanguageID(),
                                          LcData.GetCurrentCountryID(),
                                          userJobTitle.intro,
                                          userJobTitle.cancellationPolicyID,
                                          userJobTitle.instantBooking,
                                          userJobTitle.collectPaymentAtBookMeButton
                                          );

                // Task done? Almost a record must be affected to be a success
                return(affected > 0);
            }
        }
 /// <summary>
 /// Checks whether the included job titles are already in the user listing at Loconomics
 /// (AKA UseJobTitles, UserProfilePositions), adding them when not.
 /// That way, we ensure that any job title added into an external listing, is available
 /// in the regular listing at Loconomics account.
 /// This MUST be run whenever an external listing is being stored.
 /// </summary>
 /// <param name="userID"></param>
 /// <param name="jobTitles"></param>
 void AutoRegisterUserJobTitles()
 {
     foreach (var jobTitleID in jobTitles.Keys)
     {
         if (!UserJobTitle.HasItem(userID, jobTitleID))
         {
             UserJobTitle.Create(new UserJobTitle
             {
                 userID     = userID,
                 jobTitleID = jobTitleID
             });
         }
     }
 }
Exemplo n.º 4
0
        public static void Create(UserJobTitle userJobTitle)
        {
            userJobTitle.ValidateAndFixBookingPolicies();
            using (var db = new LcDatabase())
            {
                var results = db.QuerySingle("EXEC dbo.InsertUserProfilePositions @0, @1, @2, @3, @4, @5, @6, @7, @8",
                                             userJobTitle.userID,
                                             userJobTitle.jobTitleID,
                                             LcData.GetCurrentLanguageID(),
                                             LcData.GetCurrentCountryID(),
                                             userJobTitle.cancellationPolicyID,
                                             userJobTitle.intro,
                                             userJobTitle.instantBooking,
                                             userJobTitle.collectPaymentAtBookMeButton,
                                             userJobTitle.title);

                if (results.Result != "Success")
                {
                    // TODO: Add better error checks (codes) at new back-end when porting this rather than local text errors
                    var message = (string)results.Result;
                    if (message.Contains("Cannot insert duplicate key"))
                    {
                        if (userJobTitle.jobTitleID == UserGeneratedJobTitleID)
                        {
                            throw new ConstraintException("We're sorry, but we currently only support one custom job title (stay tunned, this will change soon!).");
                        }
                        else
                        {
                            throw new ConstraintException("You already have a listing with that job title.");
                        }
                    }
                    else
                    {
                        throw new Exception("We're sorry, there was an error creating your listing: " + message);
                    }
                }
                else
                {
                    // Additional data for the new listing:
                    // Needs the default solutions
                    if ((int)results.userListingID > 0)
                    {
                        UserSolution.SetDefaultSolutionsForListing((int)results.userListingID);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static PublicUserJobTitle FromUserJobTitle(UserJobTitle userJobTitle)
        {
            if (userJobTitle == null)
            {
                return(null);
            }

            return(new PublicUserJobTitle
            {
                userID = userJobTitle.userID,
                jobTitleID = userJobTitle.jobTitleID,
                intro = userJobTitle.intro,
                isActive = userJobTitle.isActive,
                cancellationPolicyID = userJobTitle.cancellationPolicyID,
                instantBooking = userJobTitle.instantBooking,
                jobTitleSingularName = userJobTitle.jobTitleSingularName,
                jobTitlePluralName = userJobTitle.jobTitlePluralName
            });
        }
Exemplo n.º 6
0
        public static void Create(UserJobTitle userJobTitle)
        {
            using (var db = new LcDatabase())
            {
                var results = db.QuerySingle("EXEC dbo.InsertUserProfilePositions @0, @1, @2, @3, @4, @5, @6, @7",
                                             userJobTitle.userID,
                                             userJobTitle.jobTitleID,
                                             LcData.GetCurrentLanguageID(),
                                             LcData.GetCurrentCountryID(),
                                             userJobTitle.cancellationPolicyID,
                                             userJobTitle.intro,
                                             userJobTitle.instantBooking,
                                             userJobTitle.collectPaymentAtBookMeButton);

                if (results.Result != "Success")
                {
                    throw new Exception("We're sorry, there was an error creating your job title: " + results.Result);
                }
            }
        }
Exemplo n.º 7
0
        public static int Set(UserEarningsEntry entry, LcDatabase sharedDb = null)
        {
            using (var db = new LcDatabase(sharedDb))
            {
                db.Query("BEGIN TRANSACTION");
                // There is only one case where job title is already added to listing and external listing
                // and will switch next flag, otherwise we need to double check.
                var skipJobTitleCheck = false;
                // On no listingID, create one for the given platform..
                if (entry.userExternalListingID <= 0 && entry.platformID > 0)
                {
                    // If  exists one..
                    var byPlatform = UserExternalListing.GetByPlatformID(entry.userID, entry.platformID).FirstOrDefault();
                    if (byPlatform != null)
                    {
                        // ..use it
                        entry.userExternalListingID = byPlatform.userExternalListingID;
                    }
                    else
                    {
                        // ..otherwise, create a new one with all data we can know for it
                        var newForPlatform = new UserExternalListing
                        {
                            userID     = entry.userID,
                            platformID = entry.platformID,
                            title      = String.Format("My {0} listing", Platform.GetItem(entry.platformID).name),
                            notes      = ""
                        };
                        var locale = Locale.Current;
                        newForPlatform.FillJobTitlesWithIds(new int[] { entry.jobTitleID }, locale.languageID, locale.countryID);
                        // insert and get the ID
                        entry.userExternalListingID = UserExternalListing.Insert(newForPlatform);
                        // this inserts the job title in the user Loconomics listing too if not exists
                        skipJobTitleCheck = true;
                    }
                }
                // ..or throw if no one of boths values is included
                else if (entry.userExternalListingID <= 0 && entry.platformID <= 0)
                {
                    throw new ConstraintException("A listing or platform must be specified for the earnings entry");
                }
                // ..otherwise, it will just use the given listingID

                // Selected job title could have being selected from an existent listing, but not exists on the external listing selected
                // or was selected as another job title from an autocomplete, then no in this external listing and no in the user listing
                // we need to add it if is not, on each place,
                // except we well know exists and skip this step, using the flag
                if (!skipJobTitleCheck)
                {
                    // Check if job title exist at user listing
                    if (!UserJobTitle.HasItem(entry.userID, entry.jobTitleID))
                    {
                        // then create a new one, with mostly default options
                        UserJobTitle.Create(new UserJobTitle
                        {
                            userID     = entry.userID,
                            jobTitleID = entry.jobTitleID
                        });
                    }
                    // Get external listing
                    var externalListing = UserExternalListing.Get(entry.userID, entry.userExternalListingID);
                    if (externalListing == null)
                    {
                        throw new ConstraintException("The listing specified does not exists");
                    }
                    // Check if job title exist at the external listing
                    if (!externalListing.jobTitles.ContainsKey(entry.jobTitleID))
                    {
                        // then add it
                        var jobTitleIds = externalListing.jobTitles.Keys.ToList();
                        jobTitleIds.Add(entry.jobTitleID);
                        var locale = Locale.Current;
                        externalListing.FillJobTitlesWithIds(jobTitleIds, locale.languageID, locale.countryID);
                        // and save it
                        UserExternalListing.Update(externalListing);
                    }
                }

                var resultID = (int)db.QueryValue(sqlSet,
                                                  entry.userID,
                                                  entry.earningsEntryID,
                                                  entry.paidDate,
                                                  entry.durationMinutes,
                                                  entry.userExternalListingID,
                                                  entry.jobTitleID,
                                                  entry.clientUserID,
                                                  entry.notes,
                                                  entry.amount
                                                  );
                db.Query("COMMIT TRANSACTION");
                return(resultID);
            }
        }