public ViewResult ProjectDetails(int?id)
        {
            Project project = _projectRepository.GetProject(id.Value);

            if (project == null)
            {
                Response.StatusCode = 404;
                return(View("ProjectNotFound", id.Value));
            }

            HomeProjectDetailsViewModel homeProjectDetailsViewModel = new HomeProjectDetailsViewModel()
            {
                Project   = project,
                PageTitle = "Project Details"
            };

            return(View(homeProjectDetailsViewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Project(int id)
        {
            Project project = context.Projects.Where(x => x.Id == id).FirstOrDefault();

            if (project == null)
            {
                return(RedirectToAction("Index", "Error"));
            }

            Author author = context.Authors.Where(x => x.Id == project.AuthorId).FirstOrDefault();

            if (author == null)
            {
                return(RedirectToAction("Index", "Error"));
            }

            var mainImage = context.ProjectImages.Where(x => x.IsMain == 1 && x.ProjectId == id).Select(x => x.ImageUrl).FirstOrDefault();
            var images    = context.ProjectImages.Where(x => x.ProjectId == id && x.IsMain == 0).Select(x => x.ImageUrl).ToList();

            List <string> tags = new List <string>();

            foreach (var item in context.ProjectTags.Where(x => x.ProjectId == id).ToList())
            {
                Tag tag = context.Tags.Where(x => x.Id == item.TagId).FirstOrDefault();
                tags.Add(tag.Name);
            }

            HomeProjectDetailsViewModel vm = new HomeProjectDetailsViewModel()
            {
                author    = author,
                project   = project,
                MainImage = mainImage,
                Images    = images,
                Tags      = tags
            };

            return(View(vm));
        }