Esempio n. 1
0
 public static void refreshEvals(azure.driverLow db, string compId, LineIds line, string email, string productId, int testKeyId, AzureData.saveKeyDataObj[] pcEvals) {
   var res = readOrCreate(db, compId, line, email);
   //adjust test
   if (res.dataObj == null) res.dataObj = new List<azure.hmanEvalController.testItem>();
   var test = res.dataObj.FirstOrDefault(t => t.productId == productId && t.testKeyId == testKeyId);
   if (test == null) res.dataObj.Add(test = new azure.hmanEvalController.testItem { productId = productId, testKeyId = testKeyId });
   if (test.items == null) test.items = new List<azure.hmanEvalController.exItem>();
   //zatrid pcEvals
   foreach (var eval in pcEvals) {
     if ((eval.flag & CourseDataFlag.testImpl_result) == CourseDataFlag.testImpl_result)
       test.flag = eval.flag;
     else {
       var item = test.items.FirstOrDefault(it => it.key == eval.key);
       if (item == null) test.items.Add(item = new azure.hmanEvalController.exItem { key = eval.key, flag = eval.flag });
       item.flag = eval.flag;
       if ((item.flag & CourseDataFlag.needsEval) == 0) test.items.Remove(item);
     }
   }
   if ((test.flag & CourseDataFlag.needsEval) == 0) {
     if (test.items.Count > 0) throw new Exception("test.items.Count > 0");
     res.dataObj.Remove(test);
   }
   //empty and attach
   if (res.isNew()) //new
     if (res.dataObj.Count == 0) { } else db.attach(res, TableOperationType.Insert);
   else //old
     db.attach(res, res.dataObj.Count == 0 ? TableOperationType.Delete : TableOperationType.Replace);
 }