This project is read-only.

Editing a user profile field

Topics: Writing modules
May 28, 2013 at 2:58 PM
Edited May 28, 2013 at 2:59 PM
Hi, I'm developing a module to show and edit some data from user profile. Some users can be sortered in a list and I save them position in a profile part field named position. I saw core.Navigation jquery sortable to make this part of the module. I have a problem, I want save changes in Position but I not found where is "position" value. I tried this:
var user = _contentManager.Get(menuItemEntry.MenuItemId);  //MenuItemId is the ContentItem Id for each user
var position = elemento.Parts.Skip(2).First().Fields.First(m => m.Name == "Posicion").;
I know god killed many kittens after use Skip and First to try get ContentPart of user, but I not found Value property of position. Anyone can help?

Thanks in advanced.
sorry for my bad english
May 29, 2013 at 12:17 AM
Well, "position" with a 't', not a 'c'. But other than that, I'm also having trouble understanding why you put a Skip and a First before Fields.
May 29, 2013 at 4:20 PM
Edited May 29, 2013 at 4:21 PM
Also, Fields is a list of ContentField items. ContentField is a base class for more specific fields, and doesn't have a Value property. If you know the field type of "Posicion" (or Position; did you make a typo or are you using your native tongue?), you should cast that field to the more specific field type class, e.g. TextField or NumberField.

Alternatively, use dynamic to access all parts and fields using dot notation, e.g.
var  position = ((dynamic)elemento).YourPart.Posicion.Value;
Question: what's the reason you're killing all these kittens using Skip, instead of saving them using a Linq query as you're doing with fields? :)
Jun 13, 2013 at 2:53 PM
Thanks BertrandLeRoy and sfmskywalker. I can get now position and change, but not changes is saved. I check in debugging and position var is updated
foreach (var menuItemEntry in menuItemEntries)
                    var elemento = _contentManager.Get(menuItemEntry.MenuItemId);
                    var position = ((dynamic)elemento).ProfilePart.Posicion.Value;

                    position = menuItemEntry.Posicion;
I have another module with a sortable and I car sort with this code:
foreach (var menuItemEntry in menuItemEntries)
                    var elemento = _repository.Get(menuItemEntry.MenuItemId);
                    elemento.Posicion = Convert.ToInt32(menuItemEntry.Position);
I tried with position = Convert.ToInt32(menuItemEntry.Posicion); without result. How can I save position field change?

Thanks in advanced.

PD: hahah, i know use skip and first are the worst method to get a part or a property.