前台传来明细 ,判断是否修改,在把前台 的数据组成新的类保存
1 public class tt 2 { 3 public string id { get; set; } 4 public string e_id { get; set; } 5 public string name { get; set; } 6 public int age { get; set; } 7 public bool sex { get; set; } 8 9 }10 public class t11 {12 public string id { get; set; }13 public string name { get; set; }14 public List dd { get; set; }15 }16 class Program17 {18 19 static void Main(string[] args)20 {21 var q = new List { new tt { id = "123",e_id="1", name = "pg", age = 12, sex = true }, new tt { id = "124",e_id="1", name = "pp", age = 13, sex = true } }; //后台数据22 var w = new List { new tt { name = "pg", e_id = "2", age = 12, sex = true }, new ConsoleApplication2.tt { name = "pp", e_id = "2", age = 13, sex = true }, new tt { name = "ppd", e_id = "2", age = 11, sex = true } }; //前台数据 23 24 var e = new t { id = "1", name = "pg", dd = q }; //父行25 26 var ischange1 = false;27 var ischange2 = false;28 foreach (var item in w)29 {30 item.e_id = e.id; //父ID31 tt ex = q.Where(d => d.name == item.name).FirstOrDefault();32 if (ex == null)33 {34 ischange2 = true;35 }36 else37 {38 if (ex.age != item.age || ex.sex != item.sex)39 {40 ischange2 = true;41 }42 }43 }44 45 if (q.Count != w.Count)46 {47 ischange2 = true;48 }49 if (ischange1 == true || ischange2 == true)50 {51 if (ischange2 == true)52 {53 e.dd = w;54 }55 }56 Console.WriteLine(ischange2);57 58 Console.ReadKey(true);59 }60 61 }