public PortfolioProject SavePortfolioProject(PortfolioProject project)
 {
     var oldProject = context.PortfolioProjects.Find(project.Id);
     if (oldProject != null)
     {
         oldProject.Name = project.Name;
         oldProject.Description = project.Description;
         oldProject.Technologies = project.Technologies;
         oldProject.ImgUrl = project.ImgUrl;
     }
     else
     {
         context.PortfolioProjects.Add(project);
     }
     context.SaveChanges();
     return oldProject;   
     
 }
Пример #2
0
        public ActionResult AddOrEditPortfolio(AdminPortfolioFull model)
        {
            //if model state is valid, save the project to db
            if (ModelState.IsValid)
            {
                var project = new PortfolioProject
                {
                    Description = model.Description,
                    Id = model.Id,
                    ImgUrl = model.ImgUrl,
                    LinkUrl = model.LinkUrl,
                    Name = model.Name,
                    Technologies = model.Technologies
                };
                _portfolioRepo.SavePortfolioProject(project);
                return RedirectToAction("Portfolio");
            }

            //if model not valid, send user back to form with partial model
            return View(model);
        }
        public void CanDeletePortfolioProject()
        {
            var projectToDelete = new PortfolioProject
            {
                Id = 1,
                Name = "FutureCodr",
                Description = "sample desc",
                Technologies = "ASP.NET, Javascript",
                ImgUrl = "/Content",
                LinkUrl = "futurecodr.com"
            };

            var target = GetAdminController();
            var result = target.DeletePortfolioProject(projectToDelete.Id);
            portfolioMock.Verify(m => m.DeletePortfolioProject(projectToDelete.Id));
        }
        public void CanSaveValidPortfolioChanges()
        {
            var mockedBlog = new Mock<IBlogPostRepository>();
            var mockedPortfolio = new Mock<IPortfolioProjectRepository>();
            var target = new AdminController(mockedBlog.Object, mockedPortfolio.Object);

            var project = new AdminPortfolioFull
            {
                Id = 3,
                Name = "A New Project",
                Description = "desc",
                ImgUrl = "/Content",
                LinkUrl = "www.sample.com",
                Technologies = "C#, Java"
            };

            var sameProject = new PortfolioProject
            {
                Id = 3,
                Name = "A New Project",
                Description = "desc",
                ImgUrl = "/Content",
                LinkUrl = "www.sample.com",
                Technologies = "C#, Java"
            };
            
            //mockedPortfolio.Setup(m => m.SavePortfolioProject(sameProject)).Returns(sameProject);
            
            var result = target.AddOrEditPortfolio(project);

            portfolioMock.Verify(m => m.SavePortfolioProject(sameProject));

            Assert.IsInstanceOfType(result, typeof (RedirectResult));
        }