I have a Complex Situation now and i am terribly stuck. Kindly Let me know if you can share some light to it.
I have a
List<categories> Which will have the Following properties
public class Categories
{
public string DisplayName { get; set; }
public string ValueCode { get; set; }
public string Count { get; set; }
}
This will have Values like
<br />
Category1/SubCategory1<br />
cat1/sc1<br />
5<br />
<br />
Category1/SubCategory2<br />
cat1/sc2<br />
4<br />
<br />
Category 2/Subcategory1<br />
cat2/sc1<br />
5<br />
<br />
Category 2/Subcategory2<br />
cat2/sc2<br />
23
I created a Custom Class to fill in the values
public class JobCateogry
{
public string DisplayName { get; set; }
public string ValueCode { get; set; }
public string Count { get; set; }
public List<JobCateogry> SubCategories { get; set; }
}
I have to Split the String in the Code Value and assign it to the SubCategory.
Like My Final out of jobCategory would be
<code>Category1
Cat1
9
inside the list
SubCategory1
sub1
5
SubCateogry2
sub2
4</code>
I tried to Split the string and assign it to the new class in two step first by splitting and then by assiging. But i am sure i am doing it the wrong way, because the moment i split, i loose the count .
<pre>var lstCategory = Categories
.Where(i => i.count > 0)
.Select(item => item.valueCode.Split('/')
.Select(k =>(k)).ToList();
List<JobCategories> jobcategories = lstCategory
.Select(item => item.Split(QueryStringConstants.CAT_SEPERATOR.ToCharArray()[0]))
.GroupBy(tokens => tokens[0].Trim(), tokens => tokens[1])
.Select(g => new JobCategories(g.Key, g.DisplayName,g.ToList(),)).ToList();
Can you please help?