public ActionResult Create(ProjectTask projectTask, FormCollection form) { if (!coursesRepository.IsTeacherInAnyCourse(User.Identity.GetUserId(), User.IsInRole("Administrator"))) { throw new HttpException((int)HttpStatusCode.Forbidden, "Forbidden!"); } if (ModelState.IsValid) { foreach (var file in form.GetValue("files").AttemptedValue.Split(',')) { if (String.IsNullOrEmpty(file.Trim())) { continue; } projectTasksRepository.AddFilesRequired(new FileRequired { Name = file.Trim(), ProjectTaskId = projectTask.Id }); } for (var i = 0; i < form.Count; i++) { var key = form.Keys[i]; if (key.StartsWith("test") && key.EndsWith("output")) { var counter = key.Split('_')[1]; var input = form.GetValue("test_" + counter + "_input").AttemptedValue.Replace(""", "\""); var output = form.GetValue("test_" + counter + "_output").AttemptedValue.Replace(""", "\""); projectTasksRepository.AddTaskTests(new TaskTest { Input = input, Output = output, ProjectTaskId = projectTask.Id }); } } projectTasksRepository.AddProjectTask(projectTask); projectTasksRepository.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProjectId = new SelectList(projectsRepository.GetProjectsByUserId(User.Identity.GetUserId(), User.IsInRole("Administrator")), "Id", "Name", projectTask.ProjectId); return(View(projectTask)); }