示例#1
0
 /// <summary>
 /// 查询评论
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public List <Comment> getComment(QueryParam param)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         var list = (from comment in context.Comment
                     join user in context.User on comment.userId equals user.Id
                     where (param.lawId == null ? 1 == 1 : comment.lawId == param.lawId) &&
                     (param.nodeId == null ? 1 == 1 : comment.nodeId == param.nodeId)
                     orderby comment.comment_date
                     select new
         {
             comment_content = comment.comment_content,
             userName = user.Xm,
             department = user.Department,
             comment_date = comment.comment_date,
             nodeId = comment.nodeId,
             lawId = comment.lawId
         }).ToList().Select(x => new Comment()
         {
             comment_content = x.comment_content,
             comment_date    = x.comment_date,
             userName        = x.userName,
             department      = x.department,
             nodeId          = x.nodeId,
             lawId           = x.lawId
         });
         List <Comment> resultList = list.ToList();
         return(resultList);
     }
 }
示例#2
0
 public List <UpdateHistory> getUpdateHistorys()
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         var list = context.UpdateHistory.Where(u => u.UserId == Global.user.Id).OrderByDescending(u => u.UpdateDate);
         return(list.ToList());
     }
 }
示例#3
0
 /// <summary>
 /// 刷新章节
 /// </summary>
 /// <param name="nodes"></param>
 /// <param name="parentNode"></param>
 /// <param name="detailOnly"></param>
 /// <returns></returns>
 public bool refreshNode(List <Node> nodes, Node parentNode = null, bool detailOnly = false)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         using (DbContextTransaction transaction = context.Database.BeginTransaction())
         {
             try
             {
                 foreach (Node node in nodes)
                 {
                     var currentNode = context.Node.FirstOrDefault(n => n.Id == node.Id);
                     if (currentNode == null)
                     {
                         context.Node.Add(node);
                     }
                     else
                     {
                         if (detailOnly)
                         {
                             currentNode.content = node.content;
                             if (string.IsNullOrEmpty(currentNode.offlineContent))
                             {
                                 currentNode.offlineContent = node.offlineContent;
                             }
                             currentNode.nodeClass = node.nodeClass;
                             currentNode.nodeKey   = node.nodeKey;
                             currentNode.nodeDef   = node.nodeDef;
                             currentNode.nodeRef   = node.nodeRef;
                         }
                         else
                         {
                             currentNode.lawId      = node.lawId;
                             currentNode.nodeLevel  = node.nodeLevel;
                             currentNode.nodeNumber = node.nodeNumber;
                             currentNode.nodeOrder  = node.nodeOrder;
                             currentNode.title      = node.title;
                             currentNode.nodeClass  = node.nodeClass;
                             currentNode.nodeKey    = node.nodeKey;
                             currentNode.nodeDef    = node.nodeDef;
                             currentNode.nodeRef    = node.nodeRef;
                         }
                         if (parentNode != null)
                         {
                             currentNode.parentNodeId = parentNode.Id;
                         }
                     }
                 }
                 context.SaveChanges();
                 transaction.Commit();
                 return(true);
             }
             catch (Exception)
             {
                 return(false);
             }
         }
     }
 }
示例#4
0
 public User getUserById(string id)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         try
         {
             return(context.User.FirstOrDefault(u => u.Id == id));
         }
         catch (Exception)
         {
             return(null);
         }
     }
 }
示例#5
0
 /// <summary>
 /// 获取设置
 /// </summary>
 /// <returns></returns>
 public List <Code> getCode()
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         try
         {
             return(context.Code.OrderBy(c => c.order).ToList());
         }
         catch (Exception ex)
         {
             return(new List <Code>());
         }
     }
 }
示例#6
0
 /// <summary>
 /// 离线搜索
 /// </summary>
 /// <param name="keyword"></param>
 /// <returns></returns>
 public List <string> offLineSearch(QueryParam param, string keyword)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         List <Law> allLaws = getLaws(param);
         var        laws    = from l in allLaws
                              from n in context.Node
                              where n.lawId == l.lawId &&
                              ((l.isLocal == "1" && (l.title.Contains(keyword) || n.title.Contains(keyword) || n.content.Contains(keyword))) || l.title.Contains(keyword)) &&
                              l.userId == Global.user.Id
                              select l.lawId;
         List <string> returnList = laws.Distinct().ToList();
         return(returnList);
     }
 }
示例#7
0
 /// <summary>
 /// 清空本地库
 /// </summary>
 /// <returns></returns>
 public bool clearLocal()
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         try
         {
             context.Database.ExecuteSqlCommand("update Law set isLocal=null,downloadDate=null,downloadPercent=null where userId='" + Global.user.Id + "'");
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
示例#8
0
 /// <summary>
 /// 离线登陆验证
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public bool login(string username, string password)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         var user = context.User.FirstOrDefault(u => u.Name == username && u.Password == password);
         if (user == null)
         {
             return(false);
         }
         else
         {
             Global.user = user;
         }
         return(true);
     }
 }
示例#9
0
 public bool addUpdateHistory(UpdateHistory updateHistory)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         try
         {
             context.UpdateHistory.Add(updateHistory);
             context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
示例#10
0
 /// <summary>
 /// 保存用户信息
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool saveUser(User user)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         try
         {
             var tempUser = context.User.FirstOrDefault(u => u.Id == user.Id);
             if (tempUser == null)//不存在则新增
             {
                 context.User.Add(user);
             }
             else//已存在则更新
             {
                 if (string.IsNullOrEmpty(tempUser.Name))
                 {
                     tempUser.Name = user.Name;
                 }
                 if (string.IsNullOrEmpty(tempUser.Password))
                 {
                     tempUser.Password = user.Password;
                 }
                 tempUser.Xm         = user.Xm;
                 tempUser.Department = user.Department;
                 tempUser.Phone      = user.Phone;
                 if (user.Preload == "1")
                 {
                     tempUser.Preload = "1";
                 }
                 else
                 {
                     tempUser.Preload = "0";
                 }
             }
             context.SaveChanges();
             return(true);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
示例#11
0
 /// <summary>
 /// 刷新评论
 /// </summary>
 /// <param name="comments"></param>
 /// <returns></returns>
 public bool refreshComment(List <Comment> comments)
 {
     using (SqliteContext context = new CAAC_LawLibrary.SqliteContext())
     {
         using (DbContextTransaction transaction = context.Database.BeginTransaction())
         {
             try
             {
                 foreach (Comment comment in comments)
                 {
                     var currentComment = context.Comment.FirstOrDefault(c => c.Id == comment.Id);
                     if (currentComment == null)
                     {
                         context.Comment.Add(comment);
                     }
                     else
                     {
                         currentComment.lawId           = comment.lawId;
                         currentComment.nodeId          = comment.nodeId;
                         currentComment.userId          = comment.userId;
                         currentComment.comment_content = comment.comment_content;
                         currentComment.comment_date    = comment.comment_date;
                     }
                 }
                 context.SaveChanges();
                 transaction.Commit();
                 return(true);
             }
             catch (Exception)
             {
                 transaction.Rollback();
                 return(false);
             }
         }
     }
 }