Skip to content

Instantly share code, notes, and snippets.

@mgravell
Created July 25, 2017 11:50
Show Gist options
  • Save mgravell/2601158e0fe982dcb92fe8b38d15f04c to your computer and use it in GitHub Desktop.
Save mgravell/2601158e0fe982dcb92fe8b38d15f04c to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
static class P
{
static void Main()
{
List<Question> question = new List<Question>
{
new Question {
Details = new List<Details>
{
new Details { Id = 1, Description = "abc"},
new Details { Id = 2, Description = "def"},
},
Id = 3, Name = "ghi", SelectedRatingDescriptionId = 4,
},
new Question {
Details = new List<Details>
{
new Details { Id = 5, Description = "jkl"},
new Details { Id = 6, Description = "mno"},
},
Id = 7, Name = "pqr", SelectedRatingDescriptionId = 8,
}
};
List<Class1> class1 = new List<Class1>
{
new Class1 { QuestionId = 3, RatingDescId = 9 },
new Class1 { QuestionId = 7, RatingDescId = 10 },
};
question.ForEach(q =>
{
class1.ForEach(c =>
{
if (q.Id == c.QuestionId)
q.SelectedRatingDescriptionId = c.RatingDescId;
});
});
// now show the orders
foreach(var q in question)
{
Console.WriteLine("Question: " + q.Id);
foreach(var d in q.Details)
{
Console.WriteLine("Detail: " + d.Id);
}
}
foreach (var c in class1)
{
Console.WriteLine("Class1 for Q: " + c.QuestionId);
}
}
}
public class Question
{
public int Id { get; set; }
public string Name { get; set; }
public List<Details> Details { get; set; }
public int SelectedRatingDescriptionId { get; set; }
}
public class Details
{
public int Id { get; set; }
public string Description { get; set; }
}
public class Class1
{
public int QuestionId { get; set; }
public int RatingDescId { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment