What I'm trying to achieve is similar to how the login works here on StackOverflow. If you are not logged in you can still see questions but if you try to +1 some of the questions you are asked to login. When you do login your +1 is remembered and added to the question.
This is my scenario:
- A user search for members and selects one - login is not required
- After selecting a member the user is redirected to a feedback page where the user can write a feedback message to the member
- The user writes the feedback and click Save
- No matter if the user is logged in or not the feedback is saved
- If the user is not logged in a popup will open where the user will be asked to login
- After the user logs in the feedback, created in step 4, will be updated with the user's Id
- The user is redirected back to the search page from step 1
I'm stuck at step 6. I can't figure out what the best way of getting the Id of the logged in user and then update the feedback message after that.
This code represents step 5. It simply sends the feedback message to the controller and saves it. After the message is .done
I call the login popup. The return message.Data
contains the Id of the feedback message (which just has been created) and which I need after the user logs in.
function saveModel(feedbackMessage) {
cc.Ajax.jpost(urlSave, { feedbackMessage: feedbackMessage })
.done(function (message, textStatus, jqXHR) {
if (message.Status == 2) { // user not logged in
openSignInModal(message.Data);
}
})
}
This code represents step 6. The returned data
is a partial view containing the login page.
function openSignInModal(feedbackId) {
var url = '/Account/LoginPartial';
$.ajax({
url: url,
type: 'get',
data: { returnUrl: '/Subscriber/Search', subTitle: feedbackNotSignedIn, modalTitle: '' },
success: function (data, textStatus, jqXHR) {
$('#pc_modal_container').html(data);
$('#pc_modal').modal('show');
},
});
}
If the user logs in then I want to get the Id of the user and update the feedback message with the logged in user's id (similar to what I explained in the beginning with StackOverflow).
My questions are:
Where should I keep the feedback message Id which I get in step 4 so I can use it to update the feedback message?
When the user is logged in and I want to update the feedback message how can I handle this best? I know I could store it in
TempData
but I don't really see this at the best option, or is it?I have tried to find examples online but nothing that fits this well enough. Does anyone know of any examples which could fit this scenario?
Thanks