Example #1
0
 /// <summary>
 /// Search job titles by a partial text by singular or plural name, or alias,
 /// and the given locale.
 /// Just returns the ID as value and singular name as label, suitable for autocomplete components.
 /// </summary>
 /// <param name="searchText"></param>
 /// <param name="locale"></param>
 /// <returns></returns>
 public static IEnumerable <AutocompleteResult> AutocompleteSearch(string searchText, LcRest.Locale locale)
 {
     using (var db = new LcDatabase())
     {
         var sql = "EXEC SearchPositions @0, @1, @2";
         return(db.Query(sql, "%" + searchText + "%", locale.languageID, locale.countryID)
                .Select(job => new AutocompleteResult
         {
             value = job.PositionID,
             label = job.PositionSingular
         }));
     }
 }
        public static int ReferServiceProfessional(string email, string firstName, string lastName, string phone,
                                                   int referredByUserID, string marketingSource, LcRest.Locale locale)
        {
            if (!String.IsNullOrWhiteSpace(email))
            {
                var emailExists = Client.CheckEmailAvailability(email) > 0;

                if (emailExists)
                {
                    throw new Exception("That service professional is already registered. Maybe have not a public profile still.");
                }
            }
            else
            {
                // We must auto-generate an email placeholder, in order to be able to store a UserProfile and get an UserID
                // needed to store a record at [users]
                email = Client.GetEmailForDb(email);
            }

            using (var db = new LcDatabase())
            {
                // If success, it returns the userID otherwise zero
                return((int)db.QueryValue(@"
                    DECLARE @UserID int

                    BEGIN TRANSACTION

                    -- Create UserProfile record to save email and generate UserID
                    INSERT INTO UserProfile (
                        Email
                    ) VALUES (
                        @0
                    )
                    SET @UserID = @@Identity

                    -- Create user account record, but account disabled
                    INSERT INTO Users (
		                UserID,
		                IsProvider,
		                IsCustomer,
                        AccountStatusID,
                        referredByUserID,
                        loconomicsMarketingCampaigns,

		                FirstName,
		                LastName,
		                MiddleIn,
		                SecondLastName,

                        marketingSource,
                        preferredLanguageID,
                        preferredCountryID,

                        mobilePhone,

		                CreatedDate,
		                UpdatedDate,
		                ModifiedBy,
		                Active
                    ) VALUES (
                        @UserID,
                        1, -- Is professional
                        1, -- Is client
                        -1,
                        @1,
                        1,
                        
                        @2,
                        @3,
                        '',
                        '',

                        @4,
                        @5,
                        @6,

                        @7,

                        getdate(),
                        getdate(),
                        'sys',
                        1 -- Active
                    )

                    -- NOTE: since there is no Membership record with password, is not an actual Loconomics User Account
                    -- just what we need on this case
                    
                    IF @@ERROR <> 0
                        ROLLBACK TRANSACTION
                    ELSE
                        COMMIT TRANSACTION

                    SELECT @UserID
                ",
                                          email,
                                          referredByUserID,
                                          firstName,
                                          lastName,
                                          marketingSource,
                                          locale.languageID,
                                          locale.countryID,
                                          phone));
            }
        }