Example #1
0
        public void CountNotes(ref int allNotesCount, ref int todayNotesCount, ref int yesterdayNotesCount, ref int thisWeekNotesCount, ref int flaggedNotesCount)
        {
            allNotesCount       = 0;
            todayNotesCount     = 0;
            yesterdayNotesCount = 0;
            thisWeekNotesCount  = 0;
            flaggedNotesCount   = 0;

            List <Database.Entities.Note> notes = null;

            using (var conn = this.factory.GetConnection())
            {
                // First, get all the notes
                notes = conn.Table <Database.Entities.Note>().ToList();

                foreach (Database.Entities.Note note in notes)
                {
                    // All notes
                    allNotesCount += 1;

                    // Today
                    if (DateUtils.CountDays(new DateTime(note.ModificationDate), DateTime.Now) == 0)
                    {
                        todayNotesCount += 1;
                    }

                    // Yesterday
                    if (DateUtils.CountDays(new DateTime(note.ModificationDate), DateTime.Now.AddDays(-1)) == 0)
                    {
                        yesterdayNotesCount += 1;
                    }

                    // This week
                    if (DateUtils.CountDays(new DateTime(note.ModificationDate), DateTime.Now) <= (int)DateTime.Now.DayOfWeek)
                    {
                        thisWeekNotesCount += 1;
                    }

                    // Flagged
                    if (note.Flagged == 1)
                    {
                        flaggedNotesCount += 1;
                    }
                }
            }
        }
Example #2
0
        public List <Database.Entities.Note> GetNotes(Notebook notebook, string searchString, ref int count, bool orderByLastChanged, string noteFilter)
        {
            string[] search = searchString.Split(new char[] { ' ' });

            List <Database.Entities.Note> notes = null;

            using (var conn = this.factory.GetConnection())
            {
                // First, get all the notes
                notes = conn.Table <Database.Entities.Note>().ToList();

                switch (noteFilter)
                {
                case NoteFilters.Today:
                    notes = notes.Where(n => DateUtils.CountDays(new DateTime(n.ModificationDate), DateTime.Now) == 0).ToList();
                    break;

                case NoteFilters.Yesterday:
                    notes = notes.Where(n => DateUtils.CountDays(new DateTime(n.ModificationDate), DateTime.Now.AddDays(-1)) == 0).ToList();
                    break;

                case NoteFilters.ThisWeek:
                    notes = notes.Where(n => DateUtils.CountDays(new DateTime(n.ModificationDate), DateTime.Now) <= (int)DateTime.Now.DayOfWeek).ToList();
                    break;

                case NoteFilters.Flagged:
                    notes = notes.Where(n => n.Flagged == 1).ToList();
                    break;

                case NoteFilters.All:
                    break;
                    // do not filter
                }

                // Then, add a WHERE clause
                if (notebook.Id.Equals("0"))
                {
                    // Get all the notes
                    notes = notes.Where(n => search.All(s => n.Title.ToLower().Contains(s.ToLower()) | n.Text.ToLower().Contains(s.ToLower()))).ToList();
                }
                else if (notebook.Id.Equals("1"))
                {
                    // Get only the notes without notebook id
                    notes = notes.Where(n => n.NotebookId.Equals("") & (search.All(s => n.Title.ToLower().Contains(s.ToLower()) | n.Text.ToLower().Contains(s.ToLower())))).ToList();
                }
                else
                {
                    // Get only the notes for the selected notebook id
                    notes = notes.Where(n => n.NotebookId.Equals(notebook.Id) & (search.All(s => n.Title.ToLower().Contains(s.ToLower()) | n.Text.ToLower().Contains(s.ToLower())))).ToList();
                }

                // Finally, ORDER BY
                if (!orderByLastChanged)
                {
                    // Order alpabetically
                    notes = notes.OrderBy(n => n.Title).ToList();
                }
                else
                {
                    // Order by last changed
                    notes = notes.OrderByDescending(n => n.ModificationDate).ToList();
                }

                count = notes.Count();
            }

            return(notes);
        }