I'm trying to save a custom property to an existing user profile in DNN 7, but the profile property is not getting set. I must be understanding something incorrectly.
So, how do you properly set a custom profile property in DNN?
UserInfo.Profile.SetProfileProperty("key","value")
// I expect this to return "value", but it's always ""
var value = UserInfo.Profile.GetProfileProperty("key");
// Even if I save it...
ProfileController.UpdateUserProfile(UserInfo);
// It always returns ""
var savedValue = UserInfo.Profile.GetProfileProperty("key");
Note: I also tried InitialiseProfile but that didn't change the behavior.
Here is how I am accessing a propertyvalue from a property in a module base class I have for a client.
public string SomeKey
{
get
{
var ppd = UserInfo.Profile.GetProperty("SomeKey");
if (ppd.PropertyValue == string.Empty)
{
var SomeKeyValue = "blah"
//update the user's profile property
UserInfo.Profile.SetProfileProperty("SomeKey", SomeKeyValue);
//save the user
DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, UserInfo);
//retrieve again
return SomeKey;
}
string returnValue = ppd.PropertyValue ??
(String.IsNullOrEmpty(ppd.DefaultValue) ? String.Empty : ppd.DefaultValue);
return returnValue;
}
}
Related
How to add new field to existing document in DocumentProcessor when updating document using REST API.
#Override
public Progress process(Processing processing) {
for (DocumentOperation op : processing.getDocumentOperations()) {
if (op instanceof DocumentUpdate) {
DocumentUpdate documentUpdate = (DocumentUpdate) op;
// what shoud I write here to add new field with value
}
}
return Progress.DONE;
}
When I am using code below, this gives me error
DocumentUpdate upd = new DocumentUpdate(type, id);
upd.addFieldUpdate(FieldUpdate.createMap(type.getField("myStrWSet"), "foo", new AssignValueUpdate(100)));
Error : AssignValueUpdate cannot be applies to int.
And, how to create FieldUpdate object with new field and its value.
Please help.
documentUpdate.addFieldUpdate(FieldUpdate.createAssign(documentUpdate.getDocumentType().getField("myField"),
new StringFieldValue("myValue")));
I'm using the Keen.IO .NET sdk and I can't seem to override the keen.timestamp property. I keep receiving the error:
value of property keen must be an object, is newtonsoft.json.linq.jproperty"}
If I remove the keen property, then the event saves fine, but the keen.timestamp throws an error, if added. The KeenClient.AddEvent() seems to check for a JObject but I'm not sure why JProperty is being found. Any ideas? Thanks in advance!
Here's my test code:
var aEvent = new
{
keen = new[] { new { timestamp = "2000-05-30T12:12:12Z" } },
username = user,
position = i,
event_id = "A123",
score = new Random().Next(1, 11),
demographics = new[] { new {gender = "M", city = "San Francisco", state = "CA"}}
};
keenClient.AddEvent("events_test", aEvent);
It looks like the keen property in the event is an Object[], not just an Object. Try it just as an object and see if that works.
I've Created a Model which have few custom validation. These custom validation I've annotated at property by below code
[CustomValidation(typeof(ItemmasterModel), "ValueTextMaxLenghtValidate")]
public decimal Valuetextmaxlength
{
get
{
return _Valuetextmaxlength;
}
set
{
ValidateProperty("Valuetextmaxlength",value);
_Valuetextmaxlength = value;
RaisePropertyChanged(() => Valuetextmaxlength);
}
}
public static ValidationResult ValueTextMaxLenghtValidate(object obj, ValidationContext context)
{
var itmmstr = (ItemmasterModel)context.ObjectInstance;
if (itmmstr.SelectedValuetypeDd != null)
{
string vtype = itmmstr.SelectedValuetypeDd.Key.ToString();
if (vtype.Equals("C"))
{
if (itmmstr.SelectedItemValueCodeTypesDd != null)
{
string vcode = itmmstr.SelectedItemValueCodeTypesDd.Key.ToString();
if (vcode.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
}
else if (vtype.Equals("T"))
{
if (itmmstr.Valuetextmaxlength == null || itmmstr.Valuetextmaxlength == 0)
{
return new ValidationResult("Value Max Length is not Entered",
new List<string> { "Valuetextmaxlength" });
}
}
}
return ValidationResult.Success;
}
Now this validation code depend on other property. scenerio When User select a value from dropdown it makes 1 checkbox selected automatically and User should enter the value in texbox also.
Issue:
Validation is working. checkbox is selected at first time then also it comes with error popup.
untill user doesn't make changes into this checkbox or texbox it is with error only. 1 time it says error even value has been entered .Next time it goes even user have not entered anything but during final full object validation is again comes with error.
Why this even ambiguity is happening. How to solve this.
Need more code let me know. I'll Post. Code is in Silverlight 5, MVVM Light
During my Custom validation I was using ValidateProperty("Valuetextmaxlength",value); before setting the value of property so It was giving me issue but the moment I set the value first and then Use my ValidateProperty("Valuetextmaxlength",value); everything worked smooth. Still I don't know the reason why but It worked for me.
I know the question sounds simple but it's actually tricky.
We have a page (CoursePage) that is cloned first before setting its properties at runtime.
PageData clone = existingCoursePage.CreateWritableClone();
coursePage = (CoursePage)clone;
// set properties....
// RelevantCourseInformationCollection is a LinkItemCollection
coursePage.RelevantCourseInformationCollection.Add(new LinkItem { Href = "google.com", Text = "Google" });
and I'm getting a null LinkItemCollection.
It seems likely that your existing page does not currently have any items in the RelevantCourseInformationColletion. If this is the case, the property will be null and you will have to assign it a new LinkItemCollection instance before trying to add any LinkItems.
coursePage.RelevantCourseInformationCollection = new LinkItemCollection();
coursePage.RelevantCourseInformationCollection.Add(new LinkItem { Href = "google.com", Text = "Google" });
Or if you prefer the shorthand:
coursePage.RelevantCourseInformationCollection = new LinkItemColletion { { new LinkItem { Href = "google.com", Text = "Google" } } };
Say I have a web application which allows to filter a set of items and say that I'm using backbone.js in the web frontend.
Quite naturally I ended up creating a Filter which extends Backbone.Model and a SearchResultList extending Backbone.Collection. The Filter has some attributes like searchTerm, dataFrom, dateTo... Filter also has a method called applyFilter. Filter.applyFilter should call searchResultList.fetch, thus updating/filtering the search results.
The question is, how to best initialize searchResultList as a property of Filter instead of being an attribute in Backbone terms?
I would not like to create the SearchResultList in Filter.initialize as SearchResultList is not necessarily "owned" by Filter.
For now I ended up passing the searchResultList object as an option to Filter.initialize, but that feels a little bit awkward to me.
I doubt that it is a good idea to let Filter.applyFilter call SearchResultList.fetch. However, there needs to be a method of Filter which when called triggers a new request somehow. (Listening to change events of Filter is not an option either as the user is supposed to change filter options in multiple steps and decides to apply the filter manually via a button click)
I have a Collection for performing searches. Most of my collections extend this Search Collection.
It has an object in it holding parameters for searching. The user of the collection can call setSearchParam, and I have a method buildSearchString that will build the search part of the URL to call (I use the Matrix parameters in my REST urls).
window.SearchCollection = Backbone.Collection.extend({
initialize : function() {
this.params = {}; // holds parameters for searching
},
// Set a search param
setSearchParam: function(param, value) {
if (typeof value === 'undefined') return;
if (typeof this.params === 'undefined') this.params = {};
this.params[param] = value;
},
setSearchParams : function(paramMap) {
_.extend(this.params, paramMap);
},
// Build Matrix params for search. This could just as easily be a standard URL string
buildSearchString: function() {
var search = [];
var i = 0;
for (var key in this.params) {
var value = this.params[key];
if (utils.isEmpty(value)) continue;
search[i++] = ";";
search[i++] = key;
search[i++] = "=";
search[i++] = value;
}
return search.join('');
}
});
Then when I create a collection, I extend it:
window.BookingCollection = window.SearchCollection.extend({
model: Booking,
url: function(){
var urlString = BASE_REST_URL + "bookings/";
// Build the matrix params for the REST URL
urlString += this.buildSearchString();
return urlString;
}
});
Then, a user of this collection can use it like so:
var bookings = new BookingCollection();
bookings.setSearchParam("name", "hello");