public ActionResult AddTask(int id /*id of the contact*/, FormCollection formValues) { int taskId = Int32.Parse(formValues["TaskId"]); //we retrieve the task to add to the contact Task task = _taskService.GetTask(taskId); //we retrieve the contact to add the task to Contact contact = _contactService.GetContact(id); contact.Tasks.Add(task); if (!_contactService.EditContact(contact)) { //we redisplay the form in case something goes wrong string userName = this.User.Identity.Name; //we retrieve from the db the tasks of the user, that haven't been assigned to an account yet var tasks = _taskService.ListTasksByCriteria(t => (t.ResponsibleUser.UserName == userName) && (t.Contact == null)); var viewModel = new AddTaskViewModel { AccountId = id, Tasks = new SelectList(tasks, "Id", "Subject", 1) }; return View(viewModel); } return View("Details", contact); }
// // GET: /Contact/AddTask public ActionResult AddTask(int id /*id of the contact*/) { string userName = this.User.Identity.Name; //we retrieve from the db the tasks of the user, that haven't been assigned to an account yet var tasks = _taskService.ListTasksByCriteria(task => (task.ResponsibleUser.UserName == userName) && (task.Contact == null)); var viewModel = new AddTaskViewModel { AccountId = id, Tasks = new SelectList(tasks, "Id", "Subject", 1) }; return View(viewModel); }