So I completed my first MVVM application.
I know it isn't great, but quite proud of actually managing to separate it all out and have it still function. It is a pretty simple string manipulation application - so not overly proud...besides I think Caliburn.Micro is doing most of the work.
I wondered if I could get some advice on the button press in the ViewModel, because it is still quite busy - not sure whether this is too busy or fine for what it is? There is no code behind my View, which I think is right and I make use of Models to do all the work - except cleaning the strings/arrays that are returned/created.
I do clean them in the Models, but because a lot of the time I am working with Regex and sometimes I am passing a string, and sometimes I am passing an Array, and while I do clean the Array when it is created as an Array in the Model, the further work on the array/string seems to be adding more empty lines - so they need cleaning again.
Any thoughts or advice from the code below, is this ok, is this too much - quite new to MVVM so any advice gratefully received.
This is in a NameViewModel, which supports a NameView which has no code behind.
Apologies, if this should be in a different place in the forum, I didn't see anything for MVVM in particular. Sorry, wasn't looking under ASP. NET....
I know it isn't great, but quite proud of actually managing to separate it all out and have it still function. It is a pretty simple string manipulation application - so not overly proud...besides I think Caliburn.Micro is doing most of the work.
I wondered if I could get some advice on the button press in the ViewModel, because it is still quite busy - not sure whether this is too busy or fine for what it is? There is no code behind my View, which I think is right and I make use of Models to do all the work - except cleaning the strings/arrays that are returned/created.
I do clean them in the Models, but because a lot of the time I am working with Regex and sometimes I am passing a string, and sometimes I am passing an Array, and while I do clean the Array when it is created as an Array in the Model, the further work on the array/string seems to be adding more empty lines - so they need cleaning again.
Any thoughts or advice from the code below, is this ok, is this too much - quite new to MVVM so any advice gratefully received.
This is in a NameViewModel, which supports a NameView which has no code behind.
C#:
public void btnNames()
{
strNamesOut = "";
string noShortNames = "";
NameIdentifier ni = new NameIdentifier(); // This is a separate model
// Takes a string of names from excel copied into a TextBox
noShortNames = strNamesIn;
// this sends the data around a couple of models then sends it back
var cleanedNames = ni.ShortNames(noShortNames);
// this removes all the duplicates and empty strings from the created array
// this model requires an array as each name is processed
// the above model and this model are used by different ViewModels some need cleaning but not variants
string[] varNames = cleanedNames.Split('\r', '\n');
varNames = varNames.Where(x => !string.IsNullOrEmpty(x.Trim())).ToArray();
varNames = varNames.Distinct().ToArray();
var variantNames = ni.Variants(varNames);
// a string is returned from the above
// since these two models are shared by different ViewModels and only this one requires Finishing
// I couldn't just send it from ni.Variants
var finishedNames = ni.Finishing(variantNames);
// again cleans the created array - I clean above to reduce the string/array being processed
string[] cleanNames = finishedNames.Split('\r', '\n');
cleanNames = cleanNames.Where(x => !string.IsNullOrEmpty(x.Trim())).ToArray();
// could make this a variable but didn't see the point of creating a string builder for it.
// I do need the names output with a line break
foreach (var finalNames in cleanNames)
{
strNamesOut += finalNames + Environment.NewLine;
}
}
Apologies, if this should be in a different place in the forum, I didn't see anything for MVVM in particular. Sorry, wasn't looking under ASP. NET....
Last edited: