public ActionResult EditContributor(ContributorViewModel contributorViewModel)
        {
            if (!ModelState.IsValid)
            {
                using (var assetRepoContext = new AssetRepoContext())
                {
                    return(View("AddEditContributor", contributorViewModel));
                }
            }

            using (var assetRepoContext = new AssetRepoContext())
            {
                var contributor = assetRepoContext.Contributors.SingleOrDefault(c => c.ContributorId == contributorViewModel.ContributorId);

                if (contributor != null)
                {
                    contributor.Name = contributorViewModel.Name;
                    assetRepoContext.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(new HttpNotFoundResult());
        }
        public ActionResult ProjectAdd()
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                ViewBag.ProjectCategories = assetRepoContext.ProjectCategories
                                            .Select(pc => new SelectListItem
                {
                    Value = pc.ProjectCategoryId.ToString(),
                    Text  = pc.Name
                })
                                            // Miscellaneous and General Use project categories are excluded since they should have exactly one corresponding project instance.
                                            .Where(pc => pc.Value != "1" && pc.Value != "2")
                                            .ToList();

                ViewBag.Contributors = assetRepoContext.Contributors
                                       .Where(c => c.ContributorId != 1)
                                       .Select(c => new SelectListItem
                {
                    Value = c.ContributorId.ToString(),
                    Text  = c.Name
                })
                                       .ToList();
            }

            var projectViewModel = new ProjectViewModel();

            return(View("AddEditProject", projectViewModel));
        }
        // Projects are not intended to be deleted by a user, so this functionality has been replaced with inactivation.

        public ActionResult InactivateProject(ProjectViewModel projectViewModel)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                var project = assetRepoContext.Projects.SingleOrDefault(p => p.ProjectId == projectViewModel.ProjectId);

                if (project != null)
                {
                    // Represents the protected 'SYSTEM' profile.
                    project.LastUpdaterId      = 1;
                    project.LastUpdateDateTime = DateTime.Now;
                    project.IsActive           = false;
                    var assets = assetRepoContext.Assets.Where(a => a.ProjectId == project.ProjectId).ToList();
                    foreach (Asset asset in assets)
                    {
                        if (asset != null)
                        {
                            asset.ProjectId          = 1;
                            asset.LastUpdaterId      = 1;
                            asset.LastUpdateDateTime = DateTime.Now;
                        }
                    }
                    assetRepoContext.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(new HttpNotFoundResult());
        }
        public ActionResult AddProject(ProjectViewModel projectViewModel)
        {
            if (!ModelState.IsValid)
            {
                using (var assetRepoContext = new AssetRepoContext())
                {
                    ViewBag.ProjectCategories = assetRepoContext.ProjectCategories
                                                .Select(pc => new SelectListItem
                    {
                        Value = pc.ProjectCategoryId.ToString(),
                        Text  = pc.Name
                    })
                                                // Miscellaneous and General Use project categories are excluded since they should have exactly one corresponding project instance.
                                                .Where(pc => pc.Value != "1" && pc.Value != "2")
                                                .ToList();

                    ViewBag.Contributors = assetRepoContext.Contributors
                                           .Where(c => c.ContributorId != 1)
                                           .Select(c => new SelectListItem
                    {
                        Value = c.ContributorId.ToString(),
                        Text  = c.Name
                    })
                                           .ToList();

                    return(View("AddEditProject", projectViewModel));
                }
            }

            using (var assetRepoContext = new AssetRepoContext())
            {
                var project = new Project
                {
                    Title             = projectViewModel.Title,
                    ProjectCategoryId = projectViewModel.Category.ProjectCategoryId.Value,
                    CreatorId         = projectViewModel.Creator.ContributorId.Value,
                    // Automatically set to current system datetime
                    CreationDateTime = DateTime.Now,
                    // Set to Creator ID value since asset is new
                    LastUpdaterId = projectViewModel.Creator.ContributorId.Value,
                    // Automatically set to current system datetime
                    LastUpdateDateTime = DateTime.Now,
                    Description        = projectViewModel.Description,
                    IsActive           = true
                };

                assetRepoContext.Projects.Add(project);
                assetRepoContext.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult EditProject(ProjectViewModel projectViewModel)
        {
            if (!ModelState.IsValid)
            {
                using (var assetRepoContext = new AssetRepoContext())
                {
                    ViewBag.ProjectCategories = assetRepoContext.ProjectCategories
                                                .Select(pc => new SelectListItem
                    {
                        Value = pc.ProjectCategoryId.ToString(),
                        Text  = pc.Name
                    })
                                                // Miscellaneous and General Use project categories are excluded since they should have exactly one corresponding project instance.
                                                .Where(pc => pc.Value != "1" && pc.Value != "2")
                                                .ToList();

                    ViewBag.Contributors = assetRepoContext.Contributors
                                           .Where(c => c.ContributorId != 1)
                                           .Select(c => new SelectListItem
                    {
                        Value = c.ContributorId.ToString(),
                        Text  = c.Name
                    })
                                           .ToList();

                    return(View("AddEditProject", projectViewModel));
                }
            }

            using (var assetRepoContext = new AssetRepoContext())
            {
                var project = assetRepoContext.Projects.SingleOrDefault(p => p.ProjectId == projectViewModel.ProjectId);

                if (project != null)
                {
                    project.Title             = projectViewModel.Title;
                    project.ProjectCategoryId = projectViewModel.Category.ProjectCategoryId.Value;
                    // CreatorId and CreationDateTime omitted so as to be set only during add
                    project.LastUpdaterId = projectViewModel.LastUpdater.ContributorId.Value;
                    // Automatically set to current system datetime
                    project.LastUpdateDateTime = DateTime.Now;
                    project.Description        = projectViewModel.Description;
                    project.IsActive           = projectViewModel.IsActive;
                    assetRepoContext.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(new HttpNotFoundResult());
        }
        public ActionResult AssetAdd(int?projectId)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                if (projectId != null)
                {
                    ViewBag.Projects = assetRepoContext.Projects
                                       .Where(p => p.IsActive == true)
                                       .Select(p => new SelectListItem
                    {
                        Value = p.ProjectId.ToString(),
                        Text  = p.Title
                    })
                                       .Where(p => p.Value == projectId.ToString())
                                       .ToList();
                }
                else
                {
                    ViewBag.Projects = assetRepoContext.Projects
                                       .Where(p => p.IsActive == true)
                                       .Select(p => new SelectListItem
                    {
                        Value = p.ProjectId.ToString(),
                        Text  = p.Title
                    })
                                       .ToList();
                }
                ViewBag.AssetTypeSubtypePairings = assetRepoContext.AssetTypeSubtypePairings.Select(atsp => new SelectListItem
                {
                    Value = atsp.AssetTypeSubtypePairingId.ToString(),
                    Text  = atsp.AssetType.Name + ": " + atsp.AssetSubtype.Name
                }).ToList();

                ViewBag.Contributors = assetRepoContext.Contributors
                                       .Where(c => c.ContributorId != 1)
                                       .Select(c => new SelectListItem
                {
                    Value = c.ContributorId.ToString(),
                    Text  = c.Name
                })
                                       .ToList();
            }

            var assetViewModel = new AssetViewModel()
            {
                ProjectRouteId = projectId
            };

            return(View("AddEditAsset", assetViewModel));
        }
        public ActionResult DeleteAsset(AssetViewModel assetViewModel)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                var projectRouteId = assetViewModel.ProjectRouteId;
                var asset          = assetRepoContext.Assets.SingleOrDefault(a => a.AssetId == assetViewModel.AssetId);

                if (asset != null)
                {
                    assetRepoContext.Assets.Remove(asset);
                    assetRepoContext.SaveChanges();

                    return(RedirectToAction("Index", new { projectId = projectRouteId }));
                }
            }

            return(new HttpNotFoundResult());
        }
        // GET: Contributor
        public ActionResult Index()
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                var contributorList = new ContributorListViewModel
                {
                    //Convert each Contributor to a ContributorViewModel
                    Contributors = assetRepoContext.Contributors.Select(c => new ContributorViewModel
                    {
                        ContributorId = c.ContributorId,
                        Name          = c.Name
                    }).Where(c => c.ContributorId != 1).ToList()
                };

                contributorList.TotalContributors = contributorList.Contributors.Count;

                return(View(contributorList));
            }
        }
        public ActionResult ReactivateProject(ProjectViewModel projectViewModel)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                var project = assetRepoContext.Projects.SingleOrDefault(p => p.ProjectId == projectViewModel.ProjectId);

                if (project != null)
                {
                    // Represents the protected 'SYSTEM' profile.
                    project.LastUpdaterId      = 1;
                    project.LastUpdateDateTime = DateTime.Now;
                    project.IsActive           = true;
                    assetRepoContext.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(new HttpNotFoundResult());
        }
        public ActionResult ProjectDetail(int id)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                var project = assetRepoContext.Projects.SingleOrDefault(p => p.ProjectId == id);
                if (project != null)
                {
                    var projectViewModel = new ProjectViewModel
                    {
                        ProjectId = project.ProjectId,
                        Title     = project.Title,
                        Category  = new ProjectCategoryViewModel
                        {
                            ProjectCategoryId = project.ProjectCategoryId,
                            Name = project.ProjectCategory.Name
                        },
                        Creator = new ContributorPopulatedViewModel
                        {
                            ContributorId = project.CreatorId,
                            Name          = project.Creator.Name
                        },
                        CreationDateTime = project.CreationDateTime,
                        LastUpdater      = new ContributorPopulatedViewModel
                        {
                            ContributorId = project.LastUpdaterId,
                            Name          = project.LastUpdater.Name
                        },
                        LastUpdateDateTime = project.LastUpdateDateTime,
                        Description        = project.Description,
                        IsActive           = project.IsActive
                    };

                    return(View(projectViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }
        public ActionResult AddContributor(ContributorViewModel contributorViewModel)
        {
            if (!ModelState.IsValid)
            {
                using (var assetRepoContext = new AssetRepoContext())
                {
                    return(View("AddEditContributor", contributorViewModel));
                }
            }

            using (var assetRepoContext = new AssetRepoContext())
            {
                var contributor = new Contributor
                {
                    Name = contributorViewModel.Name
                };

                assetRepoContext.Contributors.Add(contributor);
                assetRepoContext.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Exemple #12
0
        // GET: Home
        public ActionResult Index()
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                var lastUpdatedActiveProjects = new ProjectListViewModel
                {
                    Projects = assetRepoContext.Projects
                               .Where(p => p.IsActive == true)
                               .OrderByDescending(p => p.LastUpdateDateTime)
                               .Take(3)
                               .Select(p => new ProjectViewModel
                    {
                        ProjectId = p.ProjectId,
                        Title     = p.Title,
                        Category  = new ProjectCategoryViewModel
                        {
                            ProjectCategoryId = p.ProjectCategoryId
                        },
                        Creator = new ContributorPopulatedViewModel
                        {
                            ContributorId = p.Creator.ContributorId
                        },
                        CreationDateTime = p.CreationDateTime,
                        LastUpdater      = new ContributorPopulatedViewModel
                        {
                            ContributorId = p.LastUpdaterId
                        },
                        LastUpdateDateTime = p.LastUpdateDateTime,
                        Description        = p.Description,
                        IsActive           = p.IsActive
                    })
                               .ToList()
                };

                return(View(lastUpdatedActiveProjects));
            }
        }
        public ActionResult ContributorEdit(int id)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                if (id == 1)
                {
                    return(RedirectToAction("EditNotAllowed", "Home"));
                }

                var contributor = assetRepoContext.Contributors.SingleOrDefault(c => c.ContributorId == id);
                if (contributor != null)
                {
                    var contributorViewModel = new ContributorViewModel
                    {
                        ContributorId = contributor.ContributorId,
                        Name          = contributor.Name
                    };

                    return(View("AddEditContributor", contributorViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }
Exemple #14
0
        public ActionResult EditAsset(AssetViewModel assetViewModel)
        {
            if (!ModelState.IsValid)
            {
                using (var assetRepoContext = new AssetRepoContext())
                {
                    ViewBag.Projects = assetRepoContext.Projects
                                       .Where(p => p.IsActive == true)
                                       .Select(p => new SelectListItem
                    {
                        Value = p.ProjectId.ToString(),
                        Text  = p.Title
                    })
                                       .ToList();

                    ViewBag.AssetTypeSubtypePairings = assetRepoContext.AssetTypeSubtypePairings.Select(atsp => new SelectListItem
                    {
                        Value = atsp.AssetTypeSubtypePairingId.ToString(),
                        Text  = atsp.AssetType.Name + ": " + atsp.AssetSubtype.Name
                    }).ToList();

                    ViewBag.Contributors = assetRepoContext.Contributors
                                           .Where(c => c.ContributorId != 1)
                                           .Select(c => new SelectListItem
                    {
                        Value = c.ContributorId.ToString(),
                        Text  = c.Name
                    })
                                           .ToList();

                    return(View("AddEditAsset", assetViewModel));
                }
            }

            using (var assetRepoContext = new AssetRepoContext())
            {
                var asset = assetRepoContext.Assets.SingleOrDefault(a => a.AssetId == assetViewModel.AssetId);

                if (asset != null)
                {
                    asset.Title     = assetViewModel.Title;
                    asset.ProjectId = assetViewModel.Project.ProjectId.Value;
                    asset.AssetTypeSubtypePairingId = assetViewModel.TypeSubtypePairing.AssetTypeSubtypePairingId.Value;
                    // CreatorId and CreationDateTime omitted so as to be set only during add
                    asset.LastUpdaterId = assetViewModel.LastUpdater.ContributorId.Value;
                    // Automatically set to current system datetime
                    asset.LastUpdateDateTime = DateTime.Now;
                    asset.Comment            = assetViewModel.Comment;
                    asset.FilePlaceholder    = assetViewModel.FilePlaceholder;

                    // Updates last updated properties for respective project
                    var project = assetRepoContext.Projects.SingleOrDefault(p => p.ProjectId == assetViewModel.Project.ProjectId);
                    if (project != null)
                    {
                        project.LastUpdaterId      = assetViewModel.LastUpdater.ContributorId.Value;
                        project.LastUpdateDateTime = DateTime.Now;
                    }

                    assetRepoContext.SaveChanges();

                    return(RedirectToAction("Index", new { projectId = assetViewModel.ProjectRouteId }));
                }
            }

            return(new HttpNotFoundResult());
        }
        public ActionResult ProjectEdit(int id)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                if (id == 1 || id == 2)
                {
                    return(RedirectToAction("EditNotAllowed", "Home"));
                }

                ViewBag.ProjectCategories = assetRepoContext.ProjectCategories
                                            .Select(pc => new SelectListItem
                {
                    Value = pc.ProjectCategoryId.ToString(),
                    Text  = pc.Name
                })
                                            // Miscellaneous and General Use project categories are excluded since they should have exactly one corresponding project instance.
                                            .Where(pc => pc.Value != "1" && pc.Value != "2")
                                            .ToList();

                ViewBag.Contributors = assetRepoContext.Contributors
                                       .Where(c => c.ContributorId != 1)
                                       .Select(c => new SelectListItem
                {
                    Value = c.ContributorId.ToString(),
                    Text  = c.Name
                })
                                       .ToList();

                var project = assetRepoContext.Projects.SingleOrDefault(p => p.ProjectId == id);
                if (project != null)
                {
                    var projectViewModel = new ProjectViewModel
                    {
                        ProjectId = project.ProjectId,
                        Title     = project.Title,
                        Category  = new ProjectCategoryViewModel
                        {
                            ProjectCategoryId = project.ProjectCategoryId,
                            Name = project.ProjectCategory.Name
                        },
                        Creator = new ContributorPopulatedViewModel
                        {
                            ContributorId = project.CreatorId,
                            Name          = project.Creator.Name
                        },
                        CreationDateTime = project.CreationDateTime,
                        LastUpdater      = new ContributorPopulatedViewModel
                        {
                            ContributorId = project.LastUpdaterId,
                            Name          = project.LastUpdater.Name
                        },
                        LastUpdateDateTime = project.LastUpdateDateTime,
                        Description        = project.Description,
                        IsActive           = project.IsActive
                    };

                    return(View("AddEditProject", projectViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }
Exemple #16
0
        // GET: Asset
        public ActionResult Index(int?projectId)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                AssetListViewModel assetList;
                if (projectId == null)
                {
                    // Returns all assets
                    assetList = new AssetListViewModel
                    {
                        //Convert each Asset to an AssetViewModel
                        Assets = assetRepoContext.Assets.Select(a => new AssetViewModel
                        {
                            AssetId = a.AssetId,
                            Project = new ProjectPopulatedViewModel
                            {
                                ProjectId = a.ProjectId,
                                Title     = a.Project.Title,
                                Category  = new ProjectCategoryViewModel
                                {
                                    ProjectCategoryId = a.Project.ProjectCategoryId,
                                    Name = a.Project.ProjectCategory.Name
                                },
                                Creator = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.CreatorId,
                                    Name          = a.Project.Creator.Name
                                },
                                CreationDateTime = a.Project.CreationDateTime,
                                LastUpdater      = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.LastUpdaterId,
                                    Name          = a.Project.LastUpdater.Name
                                },
                                LastUpdateDateTime = a.Project.LastUpdateDateTime,
                                Description        = a.Project.Description,
                                IsActive           = a.Project.IsActive
                            },
                            Title = a.Title,
                            TypeSubtypePairing = new AssetTypeSubtypePairingViewModel
                            {
                                AssetTypeSubtypePairingId = a.AssetTypeSubtypePairingId,
                                Type = new AssetTypeViewModel
                                {
                                    AssetTypeId = a.AssetTypeSubtypePairing.AssetTypeId,
                                    Name        = a.AssetTypeSubtypePairing.AssetType.Name
                                },
                                Subtype = new AssetSubtypeViewModel
                                {
                                    AssetSubtypeId = a.AssetTypeSubtypePairing.AssetSubtypeId,
                                    Name           = a.AssetTypeSubtypePairing.AssetSubtype.Name
                                }
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.CreatorId,
                                Name          = a.Creator.Name
                            },
                            CreationDateTime = a.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.LastUpdaterId,
                                Name          = a.LastUpdater.Name
                            },
                            LastUpdateDateTime = a.LastUpdateDateTime,
                            Comment            = a.Comment,
                            FilePlaceholder    = a.FilePlaceholder,
                            ProjectRouteId     = projectId
                        }).ToList()
                    };
                }
                else
                {
                    //Returns all assets for a given project
                    assetList = new AssetListViewModel
                    {
                        //Convert each Asset to an AssetViewModel
                        Assets = assetRepoContext.Assets
                                 .Select(a => new AssetViewModel
                        {
                            AssetId = a.AssetId,
                            Project = new ProjectPopulatedViewModel
                            {
                                ProjectId = a.ProjectId,
                                Title     = a.Project.Title,
                                Category  = new ProjectCategoryViewModel
                                {
                                    ProjectCategoryId = a.Project.ProjectCategoryId,
                                    Name = a.Project.ProjectCategory.Name
                                },
                                Creator = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.CreatorId,
                                    Name          = a.Project.Creator.Name
                                },
                                CreationDateTime = a.Project.CreationDateTime,
                                LastUpdater      = new ContributorPopulatedViewModel
                                {
                                    ContributorId = a.Project.LastUpdaterId,
                                    Name          = a.Project.LastUpdater.Name
                                },
                                LastUpdateDateTime = a.Project.LastUpdateDateTime,
                                Description        = a.Project.Description,
                                IsActive           = a.Project.IsActive
                            },
                            Title = a.Title,
                            TypeSubtypePairing = new AssetTypeSubtypePairingViewModel
                            {
                                AssetTypeSubtypePairingId = a.AssetTypeSubtypePairingId,
                                Type = new AssetTypeViewModel
                                {
                                    AssetTypeId = a.AssetTypeSubtypePairing.AssetTypeId,
                                    Name        = a.AssetTypeSubtypePairing.AssetType.Name
                                },
                                Subtype = new AssetSubtypeViewModel
                                {
                                    AssetSubtypeId = a.AssetTypeSubtypePairing.AssetSubtypeId,
                                    Name           = a.AssetTypeSubtypePairing.AssetSubtype.Name
                                }
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.CreatorId,
                                Name          = a.Creator.Name
                            },
                            CreationDateTime = a.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = a.LastUpdaterId,
                                Name          = a.LastUpdater.Name
                            },
                            LastUpdateDateTime = a.LastUpdateDateTime,
                            Comment            = a.Comment,
                            FilePlaceholder    = a.FilePlaceholder,
                            ProjectRouteId     = projectId
                        })
                                 .Where(a => a.Project.ProjectId == projectId)
                                 .ToList()
                    };
                }

                assetList.ProjectRouteId = projectId;

                assetList.TotalAssets = assetList.Assets.Count;

                return(View(assetList));
            }
        }
Exemple #17
0
        public ActionResult AssetDetail(int id, int?projectId)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                var asset = assetRepoContext.Assets.SingleOrDefault(a => a.AssetId == id);
                if (asset != null)
                {
                    var assetViewModel = new AssetViewModel
                    {
                        AssetId = asset.AssetId,
                        Title   = asset.Title,
                        Project = new ProjectPopulatedViewModel
                        {
                            ProjectId = asset.ProjectId,
                            Title     = asset.Project.Title,
                            Category  = new ProjectCategoryViewModel
                            {
                                ProjectCategoryId = asset.Project.ProjectCategoryId,
                                Name = asset.Project.ProjectCategory.Name
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = asset.Project.CreatorId,
                                Name          = asset.Project.Creator.Name
                            },
                            CreationDateTime = asset.Project.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = asset.Project.LastUpdaterId,
                                Name          = asset.Project.LastUpdater.Name
                            },
                            LastUpdateDateTime = asset.Project.LastUpdateDateTime,
                            Description        = asset.Project.Description,
                            IsActive           = asset.Project.IsActive
                        },
                        TypeSubtypePairing = new AssetTypeSubtypePairingViewModel
                        {
                            AssetTypeSubtypePairingId = asset.AssetTypeSubtypePairingId,
                            Type = new AssetTypeViewModel
                            {
                                AssetTypeId = asset.AssetTypeSubtypePairing.AssetTypeId,
                                Name        = asset.AssetTypeSubtypePairing.AssetType.Name
                            },
                            Subtype = new AssetSubtypeViewModel
                            {
                                AssetSubtypeId = asset.AssetTypeSubtypePairing.AssetSubtypeId,
                                Name           = asset.AssetTypeSubtypePairing.AssetSubtype.Name
                            }
                        },
                        Creator = new ContributorPopulatedViewModel
                        {
                            ContributorId = asset.CreatorId,
                            Name          = asset.Creator.Name
                        },
                        CreationDateTime = asset.CreationDateTime,
                        LastUpdater      = new ContributorPopulatedViewModel
                        {
                            ContributorId = asset.LastUpdaterId,
                            Name          = asset.LastUpdater.Name
                        },
                        LastUpdateDateTime = asset.LastUpdateDateTime,
                        Comment            = asset.Comment,
                        FilePlaceholder    = asset.FilePlaceholder,
                        // Used for view filtering by project
                        ProjectRouteId = projectId
                    };

                    return(View(assetViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }
        // GET: Project
        public ActionResult Index(bool?isActive)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                ViewBag.Contributors = assetRepoContext.Contributors
                                       .Where(c => c.ContributorId != 1)
                                       .Select(c => new SelectListItem
                {
                    Value = c.ContributorId.ToString(),
                    Text  = c.Name
                })
                                       .ToList();
            }

            using (var assetRepoContext = new AssetRepoContext())
            {
                ProjectListViewModel projectList;
                if (isActive == false)
                {
                    projectList = new ProjectListViewModel
                    {
                        //Convert each Project to a ProjectViewModel
                        Projects = assetRepoContext.Projects
                                   .Select(p => new ProjectViewModel
                        {
                            ProjectId = p.ProjectId,
                            Title     = p.Title,
                            Category  = new ProjectCategoryViewModel
                            {
                                ProjectCategoryId = p.ProjectCategoryId,
                                Name = p.ProjectCategory.Name
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = p.Creator.ContributorId
                            },
                            CreationDateTime = p.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = p.LastUpdaterId
                            },
                            LastUpdateDateTime = p.LastUpdateDateTime,
                            Description        = p.Description,
                            IsActive           = p.IsActive
                        })
                                   .Where(p => p.IsActive == false)
                                   .ToList()
                    };
                }
                else
                {
                    projectList = new ProjectListViewModel
                    {
                        //Convert each Project to a ProjectViewModel
                        Projects = assetRepoContext.Projects
                                   .Select(p => new ProjectViewModel
                        {
                            ProjectId = p.ProjectId,
                            Title     = p.Title,
                            Category  = new ProjectCategoryViewModel
                            {
                                ProjectCategoryId = p.ProjectCategoryId,
                                Name = p.ProjectCategory.Name
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = p.Creator.ContributorId
                            },
                            CreationDateTime = p.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = p.LastUpdaterId
                            },
                            LastUpdateDateTime = p.LastUpdateDateTime,
                            Description        = p.Description,
                            IsActive           = p.IsActive
                        })
                                   .Where(p => p.IsActive == true)
                                   .ToList()
                    };
                }

                projectList.TotalProjects = projectList.Projects.Count;

                return(View(projectList));
            }
        }
Exemple #19
0
        public ActionResult AddAsset(AssetViewModel assetViewModel)
        {
            if (!ModelState.IsValid)
            {
                using (var assetRepoContext = new AssetRepoContext())
                {
                    ViewBag.Projects = assetRepoContext.Projects
                                       .Where(p => p.IsActive == true)
                                       .Select(p => new SelectListItem
                    {
                        Value = p.ProjectId.ToString(),
                        Text  = p.Title
                    }).ToList();

                    ViewBag.AssetTypeSubtypePairings = assetRepoContext.AssetTypeSubtypePairings.Select(atsp => new SelectListItem
                    {
                        Value = atsp.AssetTypeSubtypePairingId.ToString(),
                        Text  = atsp.AssetType.Name + ": " + atsp.AssetSubtype.Name
                    }).ToList();

                    ViewBag.Contributors = assetRepoContext.Contributors
                                           .Where(c => c.ContributorId != 1)
                                           .Select(c => new SelectListItem
                    {
                        Value = c.ContributorId.ToString(),
                        Text  = c.Name
                    })
                                           .ToList();

                    return(View("AddEditAsset", assetViewModel));
                }
            }

            using (var assetRepoContext = new AssetRepoContext())
            {
                var asset = new Asset
                {
                    Title     = assetViewModel.Title,
                    ProjectId = assetViewModel.Project.ProjectId.Value,
                    AssetTypeSubtypePairingId = assetViewModel.TypeSubtypePairing.AssetTypeSubtypePairingId.Value,
                    CreatorId = assetViewModel.Creator.ContributorId.Value,
                    // Automatically set to current system datetime
                    CreationDateTime = DateTime.Now,
                    // Set to Creator ID value since asset is new
                    LastUpdaterId = assetViewModel.Creator.ContributorId.Value,
                    // Automatically set to current system datetime
                    LastUpdateDateTime = DateTime.Now,
                    Comment            = assetViewModel.Comment,
                    FilePlaceholder    = assetViewModel.FilePlaceholder
                };

                // Updates last updated properties for respective project
                var project = assetRepoContext.Projects.SingleOrDefault(p => p.ProjectId == assetViewModel.Project.ProjectId);
                if (project != null)
                {
                    project.LastUpdaterId      = assetViewModel.Creator.ContributorId.Value;
                    project.LastUpdateDateTime = DateTime.Now;
                }

                assetRepoContext.Assets.Add(asset);
                assetRepoContext.SaveChanges();
            }

            return(RedirectToAction("Index", new { projectId = assetViewModel.ProjectRouteId }));
        }
Exemple #20
0
        public ActionResult AssetEdit(int id, int?projectId)
        {
            using (var assetRepoContext = new AssetRepoContext())
            {
                ViewBag.Projects = assetRepoContext.Projects
                                   .Where(p => p.IsActive == true)
                                   .Select(p => new SelectListItem
                {
                    Value = p.ProjectId.ToString(),
                    Text  = p.Title
                })
                                   .ToList();

                ViewBag.AssetTypeSubtypePairings = assetRepoContext.AssetTypeSubtypePairings.Select(atsp => new SelectListItem
                {
                    Value = atsp.AssetTypeSubtypePairingId.ToString(),
                    Text  = atsp.AssetType.Name + ": " + atsp.AssetSubtype.Name
                }).ToList();

                ViewBag.Contributors = assetRepoContext.Contributors
                                       .Where(c => c.ContributorId != 1)
                                       .Select(c => new SelectListItem
                {
                    Value = c.ContributorId.ToString(),
                    Text  = c.Name
                })
                                       .ToList();

                var asset = assetRepoContext.Assets.SingleOrDefault(a => a.AssetId == id);
                if (asset != null)
                {
                    var assetViewModel = new AssetViewModel
                    {
                        AssetId = asset.AssetId,
                        Title   = asset.Title,
                        Project = new ProjectPopulatedViewModel
                        {
                            ProjectId = asset.ProjectId,
                            Title     = asset.Project.Title,
                            Category  = new ProjectCategoryViewModel
                            {
                                ProjectCategoryId = asset.Project.ProjectCategoryId,
                                Name = asset.Project.ProjectCategory.Name
                            },
                            Creator = new ContributorPopulatedViewModel
                            {
                                ContributorId = asset.Project.CreatorId,
                                Name          = asset.Project.Creator.Name
                            },
                            CreationDateTime = asset.Project.CreationDateTime,
                            LastUpdater      = new ContributorPopulatedViewModel
                            {
                                ContributorId = asset.Project.LastUpdaterId,
                                Name          = asset.Project.LastUpdater.Name
                            },
                            LastUpdateDateTime = asset.Project.LastUpdateDateTime,
                            Description        = asset.Project.Description,
                            IsActive           = asset.Project.IsActive
                        },
                        TypeSubtypePairing = new AssetTypeSubtypePairingViewModel
                        {
                            AssetTypeSubtypePairingId = asset.AssetTypeSubtypePairingId,
                            Type = new AssetTypeViewModel
                            {
                                AssetTypeId = asset.AssetTypeSubtypePairing.AssetTypeId,
                                Name        = asset.AssetTypeSubtypePairing.AssetType.Name
                            },
                            Subtype = new AssetSubtypeViewModel
                            {
                                AssetSubtypeId = asset.AssetTypeSubtypePairing.AssetSubtypeId,
                                Name           = asset.AssetTypeSubtypePairing.AssetSubtype.Name
                            }
                        },
                        Creator = new ContributorPopulatedViewModel
                        {
                            ContributorId = asset.CreatorId,
                            Name          = asset.Creator.Name
                        },
                        CreationDateTime = asset.CreationDateTime,
                        LastUpdater      = new ContributorPopulatedViewModel
                        {
                            ContributorId = asset.LastUpdaterId,
                            Name          = asset.LastUpdater.Name
                        },
                        LastUpdateDateTime = asset.LastUpdateDateTime,
                        Comment            = asset.Comment,
                        FilePlaceholder    = asset.FilePlaceholder,
                        // Used for view filtering by project
                        ProjectRouteId = projectId
                    };

                    return(View("AddEditAsset", assetViewModel));
                }
            }

            return(new HttpNotFoundResult());
        }