public ActionResult Create(ProjectViewModel project, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (project.Name == "DefaultProject")
                {
                    ViewBag.ErrorMessage = AppString.ProjectNameReserved;
                    return View(project);
                }

                Project existingProject = _db.Projects.SingleOrDefault(p => p.ProjectNumber == project.ProjectNumber);
                if (existingProject != null) {
                    ViewBag.ExistingProject = new AssociateViewModel()
                    {
                        SelectedProjectId = existingProject.Id
                    };

                    ViewBag.ErrorMessage = String.Format(AppString.ProjectAlreadyExists, existingProject.Name);
                    return View(project);
                }

                Project newProject = new Project()
                {
                    ProjectNumber = project.ProjectNumber,
                    Name = project.Name
                };

                _db.Projects.Attach(newProject);
                _db.Entry(newProject).State = EntityState.Added;
                _db.SaveChanges();
                return RedirectToAction("Associate", "Project", new { projectCreatedId = newProject.Id });
            }
            return View(project);
        }
        private void PrepareProjectsForViewModel(ReportStartupViewModel model, Project associatedProject)
        {
            string userId = User.Identity.GetUserId();
            List<ProjectSelectListViewModel> selectList = new List<ProjectSelectListViewModel>();
            ProjectDAL pDb = new ProjectDAL(_db);
            List<Project> userProjects = pDb.GetUserProjects(userId).Where(p => p.Active).ToList();
            Project notProjectBound = _db.Projects.Single(p => p.Name == "DefaultProject");
            
            // Add default project first. It should always be first in the list.
            selectList.Add(new ProjectSelectListViewModel()
            {
                Id = notProjectBound.Id,
                FullInfo = "[ " + AppString.ProjectNotBound + " ]"
            });

            // Add the rest.
            foreach (Project p in userProjects)
            {
                selectList.Add(new ProjectSelectListViewModel()
                {
                    Id = p.Id,
                    FullInfo = p.FullInfo
                });
            }

            if (selectList.Count == 1)
            {
                ProjectSelectListViewModel foundProject = selectList.First();

                model.SelectedProjectName = foundProject.FullInfo;
                model.SelectedProjectId = foundProject.Id;
            }
            else
            {
                int id = -1;
                if (associatedProject != null)
                    id = associatedProject.Id;
                else
                    id = selectList.First().Id;
                model.AvailableProjects = new SelectList(selectList.ToArray(), "Id", "FullInfo", id);
            }
        }