Exemple #1
0
        public IActionResult Index(DateTime start_date, DateTime last_date, int?pageNumber, string btnSubmit, string chosenCategory = "All")
        {
            NoteRepository repository = new NoteRepository();

            notes = (List <Note>)repository.FindAll();


            foreach (Note note in notes)
            {
                foreach (string category in note.categories)
                {
                    allCategories.Add(category);
                }
            }

            ViewData["Categories"] = allCategories;

            if (btnSubmit == "Clear")
            {
                TempData.Clear();
                return(View(new PaginatedList <Note>(notes, pageNumber ?? 1, pageSize)));
            }

            if (last_date == DateTime.MinValue)
            {
                last_date = DateTime.MaxValue;
            }
            else
            {
                TempData["lastDate"] = last_date.ToString("yyyy-MM-dd");
            }

            if (start_date != DateTime.MinValue)
            {
                TempData["startDate"] = start_date.ToString("yyyy-MM-dd");
            }
            else if (Convert.ToDateTime(TempData.Peek("startDate")) != DateTime.MinValue)
            {
                start_date = Convert.ToDateTime(TempData.Peek("startDate"));
            }

            notes = notes.Where(note => note.date >= start_date && note.date <= last_date).ToList();

            if (chosenCategory != null && chosenCategory != "All")
            {
                notes = notes.Where(note => note.categories.Contains(chosenCategory)).ToList();
            }

            TempData["chosenCategory"] = chosenCategory;
            TempData["pageNumber"]     = pageNumber ?? 1;
            TempData.Keep("chosenCategory");
            TempData.Keep("startDate");
            TempData.Keep("lastDate");
            TempData.Keep("pageNumber");

            return(View(new PaginatedList <Note>(notes, pageNumber ?? 1, pageSize)));
        }
Exemple #2
0
        public NoteController()
        {
            _notesRepository = new NoteRepository {
            };
            var notes = new List <Note>();

            // notes.Add(new Note{
            //     Title = "Some note",
            //     Date = DateTime.Today.AddDays(-1),
            //     Categories = new string[]{"sport","someothercategory"},
            //     Text = "tralala, some note"
            // });
            // notes.Add(new Note{
            //     Title = "Some other note",
            //     Date = DateTime.Today.AddDays(1),
            //     Categories = new string[]{"notsport"},
            //     Text = "tralala, some note"
            // });
            this.Notes = _notesRepository.FindAll().Cast <Note>().ToList();
        }