public IActionResult AddStudentTag(AddTaskTagViewModel viewModel) { if (ModelState.IsValid) { int studentTaskId = viewModel.StudentTaskId; int studentTagId = viewModel.StudentTagId; List <TaskTag> existingItems = context.TaskTags .Where(et => et.StudentTaskId == studentTaskId) .Where(et => et.StudentTagId == studentTagId) .ToList(); if (existingItems.Count == 0) { TaskTag taskTag = new TaskTag { StudentTaskId = studentTaskId, StudentTagId = studentTagId }; context.TaskTags.Add(taskTag); context.SaveChanges(); } return(Redirect("/StudentTask/Detail/" + studentTaskId)); } return(View(viewModel)); }
public IActionResult AddStudentTag(int id) { StudentTask studentTask = context.StudentTasks.Find(id); List <StudentTag> possibleTags = context.StudentTags.ToList(); AddTaskTagViewModel viewModel = new AddTaskTagViewModel(studentTask, possibleTags); return(View(viewModel)); }
public IActionResult AddTask(int id) { Task theTask = context.Tasks.Find(id); List <Tag> possibleTags = context.Tags.ToList(); AddTaskTagViewModel viewModel = new AddTaskTagViewModel(theTask, possibleTags); return(View(viewModel)); }
public IActionResult AddEvent(AddTaskTagViewModel viewModel) { if (ModelState.IsValid) { int taskId = viewModel.TaskId; int tagId = viewModel.TagId; List <TaskTag> existingItems = context.TaskTags .Where(et => et.TaskId == taskId) .Where(et => et.TagId == tagId) .ToList(); if (existingItems.Count == 0) { TaskTag taskTag = new TaskTag { TaskId = taskId, TagId = tagId }; context.TaskTags.Add(taskTag); context.SaveChanges(); } TaskTag eventTag = new TaskTag { TaskId = taskId, TagId = tagId }; context.TaskTags.Add(eventTag); context.SaveChanges(); return(Redirect("/Tasks/Detail/" + taskId)); } return(View(viewModel)); }