public ActionResult DeleteConfirmed(int id) { ToDoEntry todoentry = db.ToDoList.Find(id); db.ToDoList.Remove(todoentry); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /ToDoEntry/Details/5 public ActionResult Details(int id = 0) { ToDoEntry todoentry = db.ToDoList.Find(id); if (todoentry == null) { return(HttpNotFound()); } return(View(todoentry)); }
// // GET: /ToDoEntry/Create public ActionResult Create() { ToDoEntry toDoEntry = new ToDoEntry() { ToDoDate = System.DateTime.Now, UserName = User.Identity.Name, Quantity = 1 }; ViewBag.TacticList = db.GetTacticList(User.Identity.Name.ToString()); ViewBag.ToDoStatusList = db.ToDoStatus.ToList <ToDoStatus>(); return(View(toDoEntry)); }
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()); }
// // GET: /ToDoEntry/Edit/5 public ActionResult Edit(int id = 0) { ToDoEntry todoentry = db.ToDoList.Find(id); ViewBag.TacticList = db.GetTacticList(User.Identity.Name.ToString()); ViewBag.ToDoStatusList = db.ToDoStatus.ToList <ToDoStatus>(); if (todoentry == null) { return(HttpNotFound()); } return(View(todoentry)); }
public ActionResult Edit(ToDoEntry todoentry) { if (ModelState.IsValid) { db.Entry(todoentry).State = System.Data.Entity.EntityState.Modified; //if (todoentry.tactic != null) //{ // db.Tactic.Attach(todoentry.tactic); //} db.SaveChanges(); return(RedirectToAction("Index")); } return(View(todoentry)); }
public void OnGet(int?id, string cat) { Id = id; if (id != null) { Entry = ToDoEntry.ReadOne(id.Value); } if (Entry == null) { Entry = new ToDoEntry(); Entry.Category = cat; Entry.Items.Add(new ToDoItem(null)); } }
public ActionResult Create(ToDoEntry todoentry) { if (ModelState.IsValid) { db.ToDoList.Add(todoentry); if (todoentry.tactic != null) { db.Tactic.Attach(todoentry.tactic); } if (todoentry.toDoStatus != null) { db.ToDoStatus.Attach(todoentry.toDoStatus); } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(todoentry)); }
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)); }