public ActionResult Create(PortfolioProjectViewModel ppvm)
 {
     try
     {
         // TODO: Add insert logic here
         ppvm.PortfolioProject.Insert();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult Edit(Guid id, PortfolioProjectViewModel ppvm)
 {
     try
     {
         // TODO: Add update logic here
         ppvm.PortfolioProject.Update();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View(ppvm));
     }
 }
        public ActionResult Project(int?id = null)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Portfolio"));
            }

            var dto = _dataContext.Projects
                      .AsNoTracking()
                      .Where(x => x.Id == id)
                      .Select(x => new
            {
                Project = x,
                Types   = x.Types,
                Clients = x.Clients
            })
                      .ToList()
                      .Select(x =>
            {
                x.Project.Types   = x.Types.ToList();
                x.Project.Clients = x.Clients.ToList();
                return(x.Project);
            })
                      .FirstOrDefault();

            if (dto == null)
            {
                return(RedirectToAction("Portfolio"));
            }

            var model = new PortfolioProjectViewModel
            {
                Project = dto
            };

            var typeIds = dto.Types.Select(t => t.Id).ToList();

            model.RelatedProjects = _dataContext.Projects
                                    .AsNoTracking()
                                    .Where(x => x.Id != dto.Id)
                                    .Where(x => x.Types.Any(tid => typeIds.Contains(tid.Id)))
                                    .OrderBy(x => x.Title)
                                    .ToList();

            return(View(model));
        }
        // GET: PortfolioProject/Create
        public ActionResult Create()
        {
            User userin = System.Web.HttpContext.Current.Session["user"] as User;

            if (userin == null || userin.UserTypeDescription != "Admin")
            {
                return(RedirectToAction("Index", "Home"));
            }

            PortfolioProjectViewModel ppvm = new PortfolioProjectViewModel()
            {
                PortfolioProject = new PortfolioProject(),
                Portfolios       = new PortfolioList(),
                Projects         = new ProjectList(),
            };

            ppvm.Projects.Load();
            ppvm.Portfolios.Load();

            return(View(ppvm));
        }