public IEnumerable <CommentGetModel> GetAllFiltered(String filter) { IQueryable <CommentGetModel> result = context .Comments .Select(c => CommentGetModel.DinObiectiv(c)) .Where(c => c.Text.Contains(filter)) ; return(result); }
//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); }