Пример #1
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);
            }
        }
Пример #2
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);
                    }
                }
            }
        }