public AssignmentProjectViewModel GetProjectByID(int projectID)
        {
            var project = _db.Projects.SingleOrDefault(x => x.ID == projectID);

            if (project != null)
            {
                var assignment = _db.Assignments.SingleOrDefault(x => x.ID == project.AssignmentID);
                var course     = _db.Courses.SingleOrDefault(x => x.ID == project.CourseID);
                var viewModel  = new AssignmentProjectViewModel
                {
                    ID             = project.ID,
                    CourseID       = project.CourseID,
                    ProjectName    = project.ProjectName,
                    Description    = project.Description,
                    Weight         = project.Weight,
                    Deadline       = project.Deadline,
                    CourseName     = course.CourseName,
                    AssignmentName = assignment.AssignmentName,
                    Input          = project.Input,
                    Output         = project.Output
                };

                return(viewModel);
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
        public ActionResult Create(int id)
        {
            var assignment = _assignmentsService.GetAssignmentByID(id);
            var viewModel  = new AssignmentProjectViewModel()
            {
                AssignmentID   = assignment.ID,
                AssignmentName = assignment.AssignmentName,
                Deadline       = assignment.Deadline
            };

            return(View(viewModel));
        }
 public void AddToDB(AssignmentProjectViewModel viewModel)
 {
     if (viewModel != null)
     {
         AssignmentProject Model = new AssignmentProject
         {
             AssignmentID = viewModel.AssignmentID,
             CourseID     = viewModel.CourseID,
             ProjectName  = viewModel.ProjectName,
             Description  = viewModel.Description,
             Weight       = viewModel.Weight,
             Deadline     = new DateTime(2016, 1, 1, 23, 59, 59),
             Input        = viewModel.Input,
             Output       = viewModel.Output
         };
         _db.Projects.Add(Model);
         _db.SaveChanges();
     }
     else
     {
         throw new ArgumentNullException();
     }
 }
        public ActionResult Save(AssignmentProjectViewModel viewModel)
        {
            _service.AddToDB(viewModel);

            return(RedirectToAction("Details", "Assignments", new { id = viewModel.AssignmentID }));
        }
 public ActionResult Details(AssignmentProjectViewModel model)
 {
     return(View(model));
 }