public async Task <IEnumerable <UserNoteDetailModel> > Handle(GetNotesRequest request, CancellationToken cancellationToken)
        {
            var notes = _context.Notes.AsQueryable();

            notes = ApplyQueryFilter(request, notes);

            var result = from note in notes
                         group note by new{ note.User.Id, note.User.UserName }
            into grp
                select new UserNoteDetailModel
            {
                UserId   = grp.Key.Id,
                UserName = grp.Key.UserName,
                Notes    = grp.Select(m => new NoteDetailModel
                {
                    Id        = m.Id,
                    Text      = m.Text,
                    Latitude  = m.Location.Y,
                    Longitude = m.Location.X
                })
            };


            return(await result.ToListAsync(cancellationToken));
        }
        private static IQueryable <Note> ApplyQueryFilter(GetNotesRequest request, IQueryable <Note> notes)
        {
            if (!string.IsNullOrEmpty(request.SearchTerm))
            {
                request.SearchTerm = request.SearchTerm.Trim(); //This could be done in a filter where we can sanitize the user input
                notes = notes.Where(m => m.Text.Contains(request.SearchTerm));
            }

            if (!string.IsNullOrEmpty(request.UserName))
            {
                request.UserName = request.UserName.Trim();
                notes            = notes.Where(m => m.User.UserName == request.UserName);
            }

            return(notes);
        }