There will come a time when you might want to store some setting for the current user and then retrieve them when they log in later. A great place to do this is within the user options section of SLX. This way you don't have to great another table in the database for this data, plus using the code below it is super easy to do!
The code below shows you two different methods. One called "GetSearchItems" and another called "cmdUpdate_Click1". When "GetSearchItems" is called it will first create a IUserOptionsService object based off the logged in user. This alone is cool because you don't have to worry about setting it up for the logged in user, it's all in context for you. Next you simply call the "GetCommonOption" method and pass in two params. The first one is the group/category the item you are looking for is in. The second one is the actual name of the item within that group/category.
Now the second method will update a user option. You first create the IUserOptionsService as before but this time you call the "SetCommonOption" method. This method takes an extra param and that is the value of the item you are storing. You still pass the group/category and the items name params.
protected string GetSearchItems() { IUserOptionsService userOption = Sage.Platform.Application.ApplicationContext.Current.Services.Get<IUserOptionsService>(); return userOption.GetCommonOption("Group", "Item"); } protected void cmdUpdate_Click1(object sender, EventArgs e) { IUserOptionsService userOption = Sage.Platform.Application.ApplicationContext.Current.Services.Get<IUserOptionsService>(); userOption.SetCommonOption("Group", "Item","Value",true); }
I've used this code many times and it is a great way to store simple settings for the logged in user. I really hope you get some mileage out of it as well!