public ActionResult Edit(TaskInputViewModel task) { if (ModelState.IsValid) { var taskModel = task.Map<Task>(); _taskRepository.Update(taskModel); return RedirectToAction("Index", "Home"); } var avaiableProjects = GetAvaiableProjectsForCurrentUser(); task.AvaiableProjects = avaiableProjects; return View(task); }
public ActionResult Add(TaskInputViewModel task) { task = CreateUpdateTaskInput(task); if (ModelState.IsValid) { var project = _projectRepository.Load(task.ProjectId); var taskModel = task.Map<Task>(); project.AddTask(taskModel); _projectRepository.Save(project); return RedirectToAction("Index", "Home"); } return View(task); }
private TaskInputViewModel CreateUpdateTaskInput(TaskInputViewModel task = null) { int userId = 1; var avaiableProjects = GetAvaiableProjectsForCurrentUser(); if (task == null) { task = new TaskInputViewModel { StartTime = DateTime.Now, AvaiableProjects = avaiableProjects, OwnerId = userId, }; } else { task.AvaiableProjects = avaiableProjects; } return task; }