public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            ProjectRole projectRole = _projectRoleService.GetById((int)id);

            if (projectRole == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            return(View(projectRole));
        }
        public ActionResult Create(ProjectMember projectMember)
        {
            ValidateProjectMember(projectMember);

            if (ModelState.IsValid)
            {
                Project project = _projectService.GetById(projectMember.ProjectID.Value);
                _projectMembershipService.Add(projectMember);

                if (projectMember.ProjectRoleID.HasValue == true)
                {
                    ProjectRole projectRole = _projectRoleService.GetById(projectMember.ProjectRoleID.Value);

                    if (projectRole.RoleType == ProjectRoleType.PM)
                    {
                        if (project.EmployeePM != null &&
                            project.EmployeePMID != projectMember.EmployeeID)
                        {
                            ProjectMember oldProjectMemberPM = _projectMembershipService.Get(x =>
                                                                                             x.Where(pm =>
                                                                                                     pm.ProjectID == projectMember.ProjectID &&
                                                                                                     pm.ProjectRole.RoleType == ProjectRoleType.PM).ToList()).FirstOrDefault();
                            if (oldProjectMemberPM != null)
                            {
                                if (projectMember.MembershipDateBegin.HasValue == false)
                                {
                                    projectMember.MembershipDateBegin = DateTime.Today;
                                }

                                oldProjectMemberPM.MembershipDateEnd = projectMember.MembershipDateBegin.Value.AddDays(-1);
                                _projectMembershipService.Update(oldProjectMemberPM);

                                project.EmployeePMID = projectMember.EmployeeID;
                                _projectService.Update(project);
                            }
                        }
                        else if (project.EmployeePM == null)
                        {
                            project.EmployeePMID = projectMember.EmployeeID;
                            _projectService.Update(project);
                        }
                    }
                    else if (projectRole.RoleType == ProjectRoleType.CAM)
                    {
                        if (project.EmployeeCAM != null &&
                            project.EmployeeCAMID != projectMember.EmployeeID)
                        {
                            ProjectMember oldProjectMemberCAM = _projectMembershipService.Get(x =>
                                                                                              x.Where(pm =>
                                                                                                      pm.ProjectID == projectMember.ProjectID &&
                                                                                                      pm.ProjectRole.RoleType == ProjectRoleType.CAM).ToList()).FirstOrDefault();
                            if (oldProjectMemberCAM != null)
                            {
                                if (projectMember.MembershipDateBegin.HasValue == false)
                                {
                                    projectMember.MembershipDateBegin = DateTime.Today;
                                }

                                oldProjectMemberCAM.MembershipDateEnd = projectMember.MembershipDateBegin.Value.AddDays(-1);
                                _projectMembershipService.Update(oldProjectMemberCAM);

                                project.EmployeeCAMID = projectMember.EmployeeID;
                                _projectService.Update(project);
                            }
                        }
                        else if (project.EmployeeCAM == null)
                        {
                            project.EmployeeCAMID = projectMember.EmployeeID;
                            _projectService.Update(project);
                        }
                    }
                }

                string returnUrl = Url.Action("Details", "Project", new { id = projectMember.ProjectID + "#projectmembers" }).Replace("%23", "#");
                return(new RedirectResult(returnUrl));
            }

            ViewBag.ProjectID     = new SelectList(_projectService.Get(x => x.ToList().OrderBy(p => p.ShortName).ToList()), "ID", "ShortName", projectMember.ProjectID);
            ViewBag.EmployeeID    = new SelectList(_employeeService.Get(x => x.Where(e => e.DismissalDate == null || e.DismissalDate > DateTime.Today).ToList().OrderBy(e => e.FullName).ToList()), "ID", "FullName", projectMember.EmployeeID);
            ViewBag.ProjectRoleID = new SelectList(_projectRoleService.Get(x => x.ToList().OrderBy(pr => (pr.ShortName + pr.Title)).ToList()), "ID", "FullName", projectMember.ProjectRoleID);
            return(View(projectMember));
        }