/// <summary> /// 取消关注 /// </summary> /// <param name="userid"></param> /// <param name="caseid"></param> /// <returns></returns> public int removeFollow(string username, int caseid) { FollowCaseService dbfollow = new FollowCaseService(); UserInfo dbuser = new UserInfo(); string userid = dbuser.GetUseByName(username).Id; var followlist = dbfollow.LoadEntities(t => t.caseid == caseid && t.userid == userid); if (followlist.Count() > 0) { var follow = followlist.FirstOrDefault(); var removeResult = dbfollow.DeleteEntity(follow); if (removeResult) { return(dbfollow.LoadEntities(t => t.caseid == caseid).Count());//删除成功 } else { return(-1);//删除关注失败 } } else { return(-2);//没有关注不能取消关注 } }
/// <summary> /// 添加关注 /// </summary> /// <param name="userid"></param> /// <param name="caseid"></param> /// <returns></returns> public int addFollow(string username, int caseid) { FollowCaseService dbfollow = new FollowCaseService(); UserInfo dbuser = new UserInfo(); string userid = dbuser.GetUseByName(username).Id; var followlist = dbfollow.LoadEntities(t => t.caseid == caseid && t.userid == userid); if (followlist.Count() > 0) { return(-1);//不能重复关注 } else { var addresult = dbfollow.AddEntity(new Models.M_FollowCase { userid = userid, caseid = caseid }); if (addresult.id != 0) { return(dbfollow.LoadEntities(t => t.caseid == caseid).Count()); } else { return(-2);//上传数据库失败 } } }
/// <summary> /// 返回个人主页数据 /// </summary> /// <param name="userid"></param> /// <returns></returns> public HomePerson userPage(string userid) { CaseService dbcase = new CaseService(); FollowCaseService dbfollow = new FollowCaseService(); InvolveService dbinvolve = new InvolveService(); M_JiangliUser user = GetUserById(userid); if (userid == null) { return(null); } //关注 var follow = dbfollow.LoadEntities(t => t.userid == userid); //参与 var involve = dbinvolve.LoadEntities(t => t.UserID == userid); //已发布 var publishlist = dbcase.LoadEntities(t => t.StateOfCase == WholeSituation.CaseState.PUBLISH && t.PublisherId == userid); //已完成 var finishlist = dbcase.LoadEntities(t => t.StateOfCase == WholeSituation.CaseState.FINISH && t.PublisherId == userid); //参与的案件列表 List <IQueryable <M_Case> > participatelist = new List <IQueryable <M_Case> >(); //关注的案件列表 List <IQueryable <M_Case> > followlist = new List <IQueryable <M_Case> >(); //所有已关注案件 if (follow.Count() != 0) { foreach (var followitem in follow) { IQueryable <M_Case> caseitem = dbcase.LoadEntities(t => t.ID == followitem.caseid); followlist.Add(caseitem); } } //所有参与案件 if (involve.Count() != 0) { foreach (var involveitem in involve) { IQueryable <M_Case> caseitem = dbcase.LoadEntities(t => t.ID == involveitem.CaseId); participatelist.Add(caseitem); } } return(new HomePerson { userid = userid, username = user.UserName, hobby = user.Hobby, headimg = user.Avatar_url, weight = user.Weight, publishlist = publishlist, finishlist = finishlist, followlist = followlist, participatelist = participatelist, }); }
/// <summary> /// 公众获取案件信息 /// </summary> /// <param name="caseid"></param> /// <returns></returns> public dynamic PublicCase(int caseid) { //通过caseid获取 用户 裁决 评论 CaseService dbcase = new CaseService(); InvolveService dbinvolve = new InvolveService(); CommentService dbcomment = new CommentService(); UserInfo dbuser = new UserInfo(); FollowCaseService dbfollow = new FollowCaseService(); var casetemp = dbcase.LoadEntities(t => t.ID == caseid); if (casetemp == null) { return(null); } var caseitem = casetemp.FirstOrDefault(); if (caseitem.StateOfCase != WholeSituation.CaseState.PUBLISH && caseitem.StateOfCase != WholeSituation.CaseState.FINISH) { return(null); } else { var follow = dbfollow.LoadEntities(t => t.caseid == caseitem.ID); //评论信息 var verdict = dbinvolve.LoadEntities(t => t.CaseId == caseitem.ID); var comment = dbcomment.LoadEntities(t => t.CaseId == caseitem.ID).OrderByDescending(t => t.Date);; publiccaseitem result = new publiccaseitem { publishid = caseitem.PublisherId, publishname = caseitem.Publisher, userhead = dbuser.GetUserById(caseitem.PublisherId) == null?"": dbuser.GetUserById(caseitem.PublisherId).Avatar_url, respondentid = caseitem.RespondentId, respondentname = caseitem.Respondent, respondenthead = dbuser.GetUserById(caseitem.RespondentId) == null?"": dbuser.GetUserById(caseitem.PublisherId).Avatar_url, casestate = caseitem.StateOfCase, publishdata = caseitem.DateOfBegin, follow = follow, verdict = verdict, comment = comment, caseid = caseitem.ID, casetitle = caseitem.Title, casecontent = caseitem.StatementOfCase, caseinfo = caseitem, }; return(result); } }