public static bool SaveOrUpdateCollectionAnswer(CollectionQuestionAndAnswer cqa)
 {
     bool result = false;
     try
     {
         using (MainDataContext db = new MainDataContext())
         {
             CollectionQuestionAndAnswer info = db.CollectionQuestionAndAnswers.FirstOrDefault(p => p.AnswerID == cqa.AnswerID);
             if (info == null)
             {
                 db.CollectionQuestionAndAnswers.InsertOnSubmit(cqa);
             }
             else
             {
                 info = cqa;
                 info.ModefiedTime = DateTime.Now.ToString();
             }
             db.SubmitChanges();
             result = true;
         }
     }
     catch (Exception ex)
     {
     }
     return result;
 }
 public static bool SaveOrUpdateQuestionCount(int QuestionCount)
 {
     using (MainDataContext db = new MainDataContext())
     {
         SysDict dict = db.SysDicts.FirstOrDefault(p => p.DictName == "QuestionPageCount");
         if (dict == null)
         {
             dict = new SysDict()
             {
                 DictName = "QuestionPageCount",
                 DictValue = QuestionCount.ToString(),
                 DictCode = "QuestionPageCount",
                 Remark = "QuestionPageCount",
                 ModefyDate = DateTime.Now.ToString()
             };
             db.SysDicts.InsertOnSubmit(dict);
             db.SubmitChanges();
         }
         else
         {
             dict.DictValue = QuestionCount.ToString();
             dict.ModefyDate = DateTime.Now.ToString();
             db.SubmitChanges();
         }
     }
     return true;
 }
 public static bool SaveOrUpdateCollectionInfo(CollectionInfo ci)
 {
     bool result = false;
     try
     {
         using (MainDataContext db = new MainDataContext())
         {
             CollectionInfo info = db.CollectionInfos.FirstOrDefault(p => p.CollectionID == ci.CollectionID);
             if (info == null)
             {
                 db.CollectionInfos.InsertOnSubmit(ci);
             }
             else
             {
                 info.QuestionCount = ci.QuestionCount;
                 info.CollectionName = ci.CollectionName;
                 info.CollectionUrl = ci.CollectionUrl;
                 info.CreatorHash = ci.CreatorHash;
                 info.CreatorName = ci.CreatorName;
                 info.ModefiedTime = DateTime.Now.ToString();
             }
             db.SubmitChanges();
             result = true;
         }
     }
     catch (Exception ex)
     {
     }
     return result;
 }
 public static int GetQuestionPageCount()
 {
     using (MainDataContext db = new MainDataContext())
     {
         SysDict dict = db.SysDicts.FirstOrDefault(p => p.DictName == "QuestionPageCount");
         return dict == null ? 0 : int.Parse(dict.DictValue) - db.QuestionInfos.Count()/20-2;
     }
 }
 public static IEnumerable<CollectionInfo> GetAllCollectionInfos()
 {
     using (MainDataContext db = new MainDataContext())
     {
         var res = db.CollectionInfos.Select(p => p).ToList();
         return res;
     }
 }
 public static CollectionInfo GetCollectionInfoById(string CollectionId)
 {
     using (MainDataContext db = new MainDataContext())
     {
         var res =  db.CollectionInfos.FirstOrDefault(p => p.CollectionID.ToString() == CollectionId);
         db.Dispose();
         return res;
     }
 }
 public static int GetAnswerCountByCollectionId(string CollectionId)
 {
     using (MainDataContext db = new MainDataContext())
     {
         var res= db.CollectionQuestionAndAnswers.Count(p => p.CollectionID.ToString() == CollectionId);
         db.Dispose();
         return res;
     }
 }
 public static int GetDownLoadPageCount()
 {
     int count = 0;
     using (MainDataContext db = new MainDataContext())
     {
         SysDict dict = db.SysDicts.FirstOrDefault(p => p.DictName == "DownLoadPageCount");
         count = dict == null ? 0 : int.Parse(dict.DictValue);
     }
     return count;
 }
 public static QuestionInfo FindQuestionInfoById(int questionId)
 {
     QuestionInfo qi = null;
     try
     {
         using (MainDataContext db = new MainDataContext())
         {
             qi = db.QuestionInfos.FirstOrDefault(p => p.QuestionID == questionId);
         }
     }
     catch (Exception ex)
     {
     }
     return qi;
 }
 public static bool DeleteQuestionInfoList(IEnumerable<QuestionInfo> InfoList)
 {
     bool result = false;
     try
     {
         if (InfoList != null)
         {
             using (MainDataContext db = new MainDataContext())
             {
                 db.QuestionInfos.DeleteAllOnSubmit(InfoList);
                 db.SubmitChanges();
                 result = true;
             }
         }
     }
     catch (Exception ex)
     {
     }
     return result;
 }
 public static bool DeleteQuestionInfoById(int questionId)
 {
     bool result = false;
     try
     {
         using (MainDataContext db = new MainDataContext())
         {
             QuestionInfo Info = db.QuestionInfos.FirstOrDefault(p => p.QuestionID == questionId);
             if (Info != null)
             {
                 db.QuestionInfos.DeleteOnSubmit(Info);
             }
             db.SubmitChanges();
             result = true;
         }
     }
     catch (Exception ex)
     {
     }
     return result;
 }
Esempio n. 12
0
 public static void SaveOrUpdateDownLoadPageCount(int count)
 {
     using (MainDataContext db = new MainDataContext())
     {
         SysDict dict = db.SysDicts.FirstOrDefault(p => p.DictName == "DownLoadPageCount");
         if (dict == null)
         {
             dict = new SysDict()
             {
                 DictValue = count.ToString(),
                 DictName = "DownLoadPageCount",
                 DictCode = "DownLoadPageCount",
                 ModefyDate = DateTime.Now.ToString(),
             };
             db.SysDicts.InsertOnSubmit(dict);
         }
         else
         {
             dict.DictValue = count.ToString();
             dict.ModefyDate = DateTime.Now.ToString();
         }
         db.SubmitChanges();
     }
 }
 public static bool SaveOrUpdateQuestionInfo(QuestionInfo qi)
 {
     bool result = false;
     try
     {
         using (MainDataContext db = new MainDataContext())
         {
             QuestionInfo Info = db.QuestionInfos.FirstOrDefault(p => p.QuestionID == qi.QuestionID);
             if (Info == null)
             {
                 db.QuestionInfos.InsertOnSubmit(qi);
             }
             else
             {
                 Info = qi;
             }
             db.SubmitChanges();
             result = true;
         }
     }
     catch (Exception ex)
     {
     }
     return result;
 }