I'm building a history writer that needs a specific piece from a CSLA list. The nature of working with the BO that's generating the history entry is that it has been initialized by the user, so where I can, the lists are singletons to save chatter.
How can I use a CSLA list to return a specific value field (MaterialNumber) from the list? I didn't see a find method and since this is a library item so I can't use a existing, populated control in the GUI.
So what I'll have is this:
MaterialList list = MaterialList.GetList(); //fully populated and what I'm working with now is below. I know I'm missing something. I thought I could use something like this for both values:
originalValue = list[Original.MaterialID].MaterialNumber;
but that isn't working.
Below is the method at this point.
internal void WriteHistory(RedZone source, RedZone changed)
{
string changedValue = string.Empty;
string originalValue = string.Empty;
if(ChangedItems.Contains("MaterialID"))
{
MaterialList listChanged, listOriginal;
// if the material has never been set, ignore history creation
if(Original.MaterialID != 0 && Original.MaterialID != this.MaterialID)
{
listChanged = MaterialList.GetMaterial(this.MaterialID);
listOriginal = MaterialList.GetMaterial(Original.MaterialID);
// Here's where I need to use the list
changedValue = listChanged[0].MaterialNumber;
originalValue = listOriginal[0].MaterialNumber;
}
HistoryItem historyItem = HistoryItem.NewHistoryItem(this.Principal.ResourceID, changedValue, originalValue, "Material", sourceID);
this.HistoryItems.Add(historyItem);
}
HistoryItems.Save(this.RedZoneID);
ChangedItems.Clear();
}
_E
I'm not sure I understand the question - but I think you want a method on your collection to return a specific item based on a key value?
I'd just create this method in your collection class - kind of like this:
public string GetMaterialNumber(string id)
{
foreach (Material m in this.list)
if (m.Id == id)
return m.MaterialNumber;
return null;
}
This encapsulates the process of finding the value, allowing the calling code to collapse to just a couple lines.
I'm just forgetting all the helper Utilities I've written already to do this. I did it just that way.
Sorry to bother...
_E
Copyright (c) Marimer LLC