예제 #1
0
 public IActionResult Index(int?id)
 {
     if (id == 0)
     {
         return(View(_subject.All()));
     }
     else
     {
         List <CategorySubjectDTO> subjects = new List <CategorySubjectDTO>();
         var test = _subjectCategory.Find(y => y.CategoryID == id);
         foreach (var item in test.Select(x => x.SubjectID).Distinct())
         {
             var subject         = _subject.Get(item);
             var tempLastComment = _comment.getLastCommentBySubjectID(subject.ID);
             subjects.Add(new CategorySubjectDTO
             {
                 ID           = item,
                 Content      = (subject.Content.Length < 50) ? subject.Content : subject.Content.Substring(0, subject.Content.Length % 50),
                 Header       = subject.Header,
                 Description  = subject.Description,
                 CreatedDate  = subject.CreatedDate,
                 Creater      = _member.Get(x => x.ID == subject.MemberID).Name,
                 LastComment  = (tempLastComment.Length < 50)? tempLastComment : tempLastComment.Substring(0, tempLastComment.Length % 40),
                 LastMember   = (_comment.getLastCommentMembersBySubjectID(subject.ID) != 0) ? _member.Get(_comment.getLastCommentMembersBySubjectID(subject.ID)).Name : "No Comment",
                 CommentCount = _comment.getCommentCountBySubjectID(subject.ID)
             });
         }
         return(View(subjects));
     }
 }
예제 #2
0
        public IViewComponentResult Invoke()
        {
            List <MemberViewSubjectDTO> memberViewSubjectDTO;
            var tempmember = HttpContext.Session.GetObjectFromJson <Member>("Member");

            if (tempmember != null)
            {
                var memberSubjectList = _subject.All().Where(x => x.MemberID == tempmember.ID);
                if (memberSubjectList != null)
                {
                    string tempLastComment = null;
                    memberViewSubjectDTO = new List <MemberViewSubjectDTO>();
                    foreach (var item in memberSubjectList)
                    {
                        tempLastComment = _comment.getLastCommentBySubjectID(item.ID);
                        memberViewSubjectDTO.Add(new MemberViewSubjectDTO
                        {
                            ID           = item.ID,
                            CommentCount = _comment.getCommentCountBySubjectID(item.ID),
                            Content      = (item.Content.Length < 50) ? item.Content : item.Content.Substring(0, item.Content.Length % 50),
                            CreatedDate  = item.CreatedDate,
                            Description  = item.Description,
                            Header       = item.Header,
                            LastComment  = (tempLastComment.Length < 50) ? tempLastComment : tempLastComment.Substring(0, tempLastComment.Length % 40),
                            LastMember   = (_comment.getLastCommentMembersBySubjectID(item.ID) != 0)? _member.Get(_comment.getLastCommentMembersBySubjectID(item.ID)).Name:"No Comment"
                        });
                    }
                    return(View(memberViewSubjectDTO.AsQueryable()));
                }
                return(View());
            }
            return(View());
        }