public void editToDoList(string name, List <ItemTDLs> item) { EditToDoList editTDL = new EditToDoList(); editTDL.Location = new System.Drawing.Point(400, 100); editTDL.setValue(name, item); this.Controls.Add(editTDL); editTDL.BringToFront(); }
public async Task <IActionResult> Edit(int id, EditToDoList toDoList) { if (id != toDoList.Id) { return(NotFound()); } if (ModelState.IsValid) { var origenal = await _context.ToDoList.Include(tl => tl.Tasks) .FirstOrDefaultAsync(tl => tl.Id == id && tl.ApplicationUserId == _userManager.GetUserId(User)); if (origenal != null) { var newTaks = toDoList.Tasks.Where(nt => !string.IsNullOrWhiteSpace(nt.Task)).ToList(); origenal.Name = toDoList.Name; var tasks = origenal.Tasks.ToList() .Where(t => newTaks.Exists(nt => nt.Id == t.Id)).ToList(); tasks.ForEach(t => { var newtask = newTaks.Find(nt => nt.Id == t.Id); t.Done = newtask.Done; t.Task = newtask.Task; //_context.Entry(t).State = EntityState.Modified; //_context.Update(t); } ); newTaks.Where(nt => !tasks.Exists(t => t.Id == nt.Id)).ToList().ForEach(nt => tasks.Add(nt)); origenal.Tasks = tasks; try { _context.Entry(origenal).State = EntityState.Modified; _context.Update(origenal); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoListExists(toDoList.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } } return(View(toDoList)); }
// GET: ToDoLists/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var toDoList = await _context.ToDoList.Include(m => m.Tasks).SingleOrDefaultAsync(m => m.Id == id && m.ApplicationUserId == _userManager.GetUserId(User)); if (toDoList == null) { return(NotFound()); } var viewModel = new EditToDoList() { Id = toDoList.Id, Name = toDoList.Name, Tasks = toDoList.Tasks.ToList() }; viewModel.Tasks.Add(new ToDoTasks()); viewModel.Tasks.Add(new ToDoTasks()); return(View(viewModel)); }