public IActionResult OnPostCheck(int id1, int id2, bool check) { var ToDo = ToDoEntry.ReadAll(); if (id1 < ToDo.Count && id2 < ToDo[id1].Items.Count) { ToDo[id1].Items[id2].Done = check; ToDoEntry.Save(); } return(new EmptyResult()); }
public IActionResult OnPostDelete() { var id = Request.Form["id"][0]; var category = Request.Form["category"][0]; int n; if (!string.IsNullOrEmpty(id) && int.TryParse(id, out n)) { var list = ToDoEntry.ReadAll(); if (list.Count > n) { list.RemoveAt(n); for (int i = n; i < list.Count; i++) { list[i].Id = i; } } ToDoEntry.Save(); } return(Redirect("~/?category=" + category)); }
public void OnGet(string category) { ToDo = ToDoEntry.ReadAll(); Categories = ToDo.Select(i => i.Category).Distinct().Where(i => !string.IsNullOrWhiteSpace(i)); if (!string.IsNullOrWhiteSpace(category)) { Category = category; var todo = new List <ToDoEntry>(); foreach (var i in ToDo) { if (i.Category == category) { todo.Add(i); } } ToDo = todo; } else { ToDo = new List <ToDoEntry>(); } }
public IActionResult OnPostSubmit() { var id = Request.Form["id"][0]; if (!string.IsNullOrEmpty(id)) { Entry = ToDoEntry.ReadOne(int.Parse(id)); } if (Entry == null) { Entry = new ToDoEntry(); var list = ToDoEntry.ReadAll(); Entry.Id = list.Count; list.Add(Entry); } int max = 0; foreach (var k in Request.Form.Keys) { if (k.ToLower().StartsWith("text-")) { int n; if (int.TryParse(k.Substring(5), out n) && n > max) { max = n; } } } Entry.Title = Request.Form["title"]; Entry.Category = Request.Form["category"]; int i1 = 0; for (int i = 0; i <= max; i++) { if (!Request.Form.ContainsKey($"text-{i}") || string.IsNullOrWhiteSpace(Request.Form[$"text-{i}"])) { continue; } var text = Request.Form[$"text-{i}"]; bool done = false; if (Request.Form.ContainsKey($"done-{i}")) { done = true; } if (Entry.Items.Count > i1) { Entry.Items[i1].Text = text; Entry.Items[i1].Done = done; } else { Entry.Items.Add(new ToDoItem(text, done)); } i1++; } while (Entry.Items.Count > max + 1) { Entry.Items.RemoveAt(Entry.Items.Count - 1); } ToDoEntry.Save(); return(Redirect("~/?category=" + Entry.Category)); }