コード例 #1
0
ファイル: CommentService.cs プロジェクト: mgci0098/Lab3
        public IEnumerable <CommentGetModel> GetAllFiltered(String filter)
        {
            IQueryable <CommentGetModel> result = context
                                                  .Comments
                                                  .Select(c => CommentGetModel.DinObiectiv(c))
                                                  .Where(c => c.Text.Contains(filter))
            ;

            return(result);
        }
コード例 #2
0
        //public IEnumerable<CommentGetModel> GetAllFiltered(String filter)
        //{
        //    IQueryable<CommentGetModel> result = context
        //                     .Comments
        //                     .Select(c => CommentGetModel.FromExpense(c))
        //                     .Where(c => c.Text.Contains(filter))
        //                     ;
        //    return result;
        //}

        public IEnumerable <CommentGetModel> GetAllFiltered(String filter)
        {
            IQueryable <Expense> result = context.Expenses.Include(c => c.Comments);

            List <CommentGetModel> resultComments    = new List <CommentGetModel>();
            List <CommentGetModel> resultCommentsAll = new List <CommentGetModel>();

            foreach (Expense expense in result)
            {
                expense.Comments.ForEach(c =>
                {
                    if (c.Text == null || filter == null)
                    {
                        CommentGetModel comment = new CommentGetModel
                        {
                            Id        = c.Id,
                            Important = c.Important,
                            Text      = c.Text,
                            ExpenseId = expense.Id
                        };
                        resultCommentsAll.Add(comment);
                    }
                    else if (c.Text.Contains(filter))
                    {
                        CommentGetModel comment = new CommentGetModel
                        {
                            Id        = c.Id,
                            Important = c.Important,
                            Text      = c.Text,
                            ExpenseId = expense.Id
                        };
                        resultComments.Add(comment);
                    }
                });
            }
            if (filter == null)
            {
                return(resultCommentsAll);
            }
            return(resultComments);
        }