Exemplo n.º 1
0
        public ActionResult CreateProject(Project project)
        {
            //Check if there are any validation errors during model binding.
            //If validation is valid, Add project record to database
            //Else return view back to project

            if (ModelState.IsValid)
            {
                ProjectMember projectMember = new ProjectMember();

                //Add project record to database
                project.ProjectId = projectContext.Add(project);

                //set the property values for the projectmember to be prepared to insert into the database
                projectMember.ProjectId = project.ProjectId;

                //get the values for projectMember's studentID and set it to integer value
                projectMember.StudentId = HttpContext.Session.GetInt32("StudentID").Value;

                //projectmember role is = to  Leader
                projectMember.Role = "Leader";

                //projectContext method will add project as leader in projectmember
                projectContext.AddProjectAsLeader(projectMember);

                //Redirect user to Project/Index view
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(project));
            }
        }