public ActionResult RestoreVersion(int projectversionId = 0, string editorname = "default")
        {
            Mapper.CreateMap<ProjectVersion, ProjectVersion>().ForMember(x => x.ProjectVersionId, o => o.Ignore());

            ProjectVersion restoreVersion = db.ProjectVersions.Find(projectversionId);

            ProjectVersion newVersion = new ProjectVersion();
            newVersion = Mapper.Map<ProjectVersion, ProjectVersion>(restoreVersion);

            string text = editorname.Replace("/", "\\");
            newVersion.EditedBy = db.Users.Where(b => b.Username.Equals(text)).First();
            newVersion.EditedOn = DateTime.Now;
            newVersion.ChangeDescription = "restored project to old snapshot";

            Project project = db.Projects.Find(restoreVersion.parentId);

            db.ProjectVersions.Add(newVersion);
            project.CurrentVersion = newVersion;
            db.SaveChanges();

            TempData["SuccessMessage"] = "Successfully restored project to old version!";
            return RedirectToAction("Details", "Project", new { id = restoreVersion.parentId });
        }
        public ActionResult SearchAll(string searchTerm, int requestedPage, int PageSize)
        {
            double pageSize = (double)PageSize;
            string userInput = string.Empty;
            List<Project> results;

            if (!string.IsNullOrWhiteSpace(searchTerm))
            {
                userInput = searchTerm.ToLower().Trim();
                results = db.Projects.Where(b => b.CurrentVersion.ProjectName.ToLower().Contains(userInput)).ToList();
                results.AddRange(db.Projects.Where(b => b.CurrentVersion.ChanceDay.ToLower().Contains(userInput)).ToList());
                results = results.Distinct().ToList();
            }
            else
            {
                results = db.Projects.ToList();
            }

            int pageNumbers = (int) Math.Ceiling(results.Count() / pageSize);
            int skipSize = (requestedPage - 1) * (int) pageSize;

            results = results.Skip(skipSize).Take((int)pageSize).ToList();

            PaginatedProjectSearchResults finalResults = new PaginatedProjectSearchResults();
            finalResults.currentPage = requestedPage;
            finalResults.totalPages = pageNumbers;

            //Convert results to projectView
            Mapper.CreateMap<ProjectVersion, ProjectView>();
            Mapper.CreateMap<Project, ProjectView>();

            ProjectVersion loopVersion = new ProjectVersion();
            List<ProjectView> projectViewResults = new List<ProjectView>();
            ProjectView newProjectView = new ProjectView();
            foreach (var singleProject in results)
            {
                loopVersion = singleProject.CurrentVersion;
                newProjectView = Mapper.Map<ProjectVersion, ProjectView>(loopVersion);
                Mapper.Map(singleProject, newProjectView);
                projectViewResults.Add(newProjectView);
            }

            finalResults.projectResults = projectViewResults;

            return PartialView("_SearchAll", finalResults);
        }