public ActionResult ManageProjectUsers() { ViewBag.Projects = new MultiSelectList(db.Projects, "Id", "ProjectName"); ViewBag.Developers = new MultiSelectList(roleHelper.UsersInRole("Developer"), "Id", "NameWithEmail"); ViewBag.Submitters = new MultiSelectList(roleHelper.UsersInRole("Submitter"), "Id", "NameWithEmail"); ViewBag.ProjectManagerId = new SelectList(roleHelper.UsersInRole("ProjectManager"), "Id", "NameWithEmail"); var myData = new List <ManageProjectViewModel>(); foreach (var user in db.Users.ToList()) { var userVm = new ManageProjectViewModel { NameWithEmail = $"{user.NameWithEmail}", AvatarPath = $"{user.AvatarPath}", RoleName = roleHelper.ListUserRoles(user.Id).FirstOrDefault(), ProjectNames = user.Projects.Select(p => p.ProjectName).ToList() }; if (userVm.ProjectNames.Count() == 0) { userVm.ProjectNames.Add("N/A"); } myData.Add(userVm); } return(View(myData)); }
public ActionResult ManageProject() { ViewBag.Projects = new MultiSelectList(db.Projects, "Id", "Name"); ViewBag.Developers = new MultiSelectList(userRoles.UserInRole("Developer"), "Id", "Email"); ViewBag.Submitters = new MultiSelectList(userRoles.UserInRole("Submitter"), "Id", "Email"); if (User.IsInRole("Admin")) { ViewBag.ProjectManagerId = new SelectList(userRoles.UserInRole("Project_Manager"), "Id", "Email"); } //Create View Model var myData = new List <ManageProjectViewModel>(); ManageProjectViewModel userVm = null; foreach (var user in db.Users.ToList()) { userVm = new ManageProjectViewModel { UserName = $"{user.LastName},{user.FirstName}", ProjectName = projHelper.ListUserProjects(user.Id).Select(p => p.Name).ToList() }; if (userVm.ProjectName.Count() == 0) { userVm.ProjectName.Add("N/A"); } myData.Add(userVm); } ; return(View(myData)); }
public IActionResult ManageProjects() { if (!_auth.Authorise(RolesEnum.Admin, _context)) // Authenticate the user { return(Redirect("~/Project/Dashboard")); } var vm = new ManageProjectViewModel(); // Create a new view model vm.AllProjects = _context.Projects.Where(p => p.ProjectId > 0).ToList(); // Get all the projects from the database // Return the Manage Projects view return(View(vm)); }
public async Task <IActionResult> ManageProject(int id) { Project project = await _context.Projects.Include(p => p.Tags) .ThenInclude(t => t.Tag) .Include(p => p.DescriptionVideoLink) .Include(p => p.BannerImage) .Include(p => p.DescriptiveImage) .FirstOrDefaultAsync(p => p.Id == id); if (project == null) { return(NotFound()); } ManageProjectViewModel model = new ManageProjectViewModel() { UserList = new SelectList(await _context.Users.ToListAsync(), "Id", "UserName", null), CategoryList = new SelectList(await _context.Categories.ToListAsync(), "Id", "Name", null), DisplayPriorityList = new SelectList(Enum.GetValues(typeof(ProjectDisplayPriority))), StatusList = new SelectList(Enum.GetValues(typeof(ProjectStatus))), Hashtag = project.HashTags, Name = project.Name, Description = project.Description, CategoryId = project.CategoryId, CreatorComments = project.CreatorComments, DescriptionVideoLink = project.DescriptionVideoLink?.Link, BannerImageFile = project.BannerImage, BannerImageDescription = project.BannerImage?.Description, DescriptiveImageFile = project.DescriptiveImage, DescriptiveImageDescription = project.DescriptiveImage?.Description, End = project.End, Start = project.Start, Target = project.Target, DisplayPriority = project.DisplayPriority, Goal = project.Goal, OwnerId = project.OwnerId, Status = project.Status, Proposal = project.Proposal, Id = project.Id }; return(View(model)); }
public ActionResult ManageProjectUsers(int?id) { ManageProjectViewModel vm = new ManageProjectViewModel(); var projDevs = projectHelper.UsersOnProjectByRole(id.Value, "Developer"); var projSubs = projectHelper.UsersOnProjectByRole(id.Value, "Submitter"); var project = db.Projects.Find(id.Value); var projectManager = db.Users.Find(project.ProjectManagerId); //var devs = new MultiSelectList(roleHelper.UsersInRole("Developer"), "Id", "DisplayName",projDevs.Select(u => u.Id)); var devs = new MultiSelectList(roleHelper.UsersInRole("Developer"), "Id", "DisplayName", projDevs.Select(u => u.Id)); var subs = new MultiSelectList(roleHelper.UsersInRole("Submitter"), "Id", "DisplayName", projSubs.Select(u => u.Id)); var pms = new SelectList(roleHelper.UsersInRole("ProjectManager"), "Id", "DisplayName"); //var myData = new List<UserProjectListViewModel>(); //UserProjectListViewModel userVm = null; //foreach(var user in db.Users.ToList()) //{ // userVm = new UserProjectListViewModel // { // Name = $"{user.FirstName}, {user.LastName}", // ProjectNames = projectHelper.ListUserProjects(user.Id).Select(p => p.Name).ToList() // }; // if (userVm.ProjectNames.Count() == 0) // userVm.ProjectNames.Add("N/A"); // myData.Add(userVm); //} vm.Project = project; vm.Developers = projDevs; vm.Submitters = projSubs; vm.MSDevs = devs; vm.MSSubs = subs; vm.ProjectManager = projectManager; vm.ProjectManagers = pms; return(View(vm)); }
public async Task <IActionResult> ManageProject(ManageProjectViewModel model) { Project project = await _context.Projects .Where(p => p.Id == model.Id) .Include(p => p.Owner) .Include(p => p.Tags) .ThenInclude(t => t.Tag) .Include(p => p.DescriptionVideoLink) .Include(p => p.BannerImage) .Include(p => p.DescriptiveImage) .FirstAsync(); // If the project name changed make sure it is still unique. if (project.Name != model.Name && await _context.Projects.AnyAsync(p => p.Name == model.Name)) { ModelState.AddModelError("Name", _localizer["A project with the same name already exists."]); } // If there are image descriptions without corresponding image uploads, warn the user. if (project.BannerImage == null && model.BannerImageUpload == null && !string.IsNullOrWhiteSpace(model.BannerImageDescription)) { ModelState.AddModelError("BannerImageDescription", _localizer["You can only provide a 'Banner Image Description' if you upload a 'Banner Image'."]); } if (project.DescriptiveImage == null && model.DescriptiveImageUpload == null && !string.IsNullOrWhiteSpace(model.DescriptiveImageDescription)) { ModelState.AddModelError("DescriptiveImageDescription", _localizer["You can only provide a 'DescriptiveImage Description' if you upload a 'DescriptiveImage'."]); } if (ModelState.IsValid) { bool approved = model.Status == ProjectStatus.Running && project.Status == ProjectStatus.Hidden; bool successfull = model.Status == ProjectStatus.Successful && project.Status == ProjectStatus.Running; bool failed = model.Status == ProjectStatus.Failed && project.Status == ProjectStatus.Running; if (approved) { string approvalEmail = "Hi!<br>" + "<br>" + "The CollAction Team has reviewed your project proposal and is very happy to share that your project has been approved and now live on www.collaction.org!<br>" + "<br>" + "So feel very welcome to start promoting it! If you have any further questions, feel free to contact the CollAction Team at [email protected]. And don’t forget to tag CollAction in your messages on social media so we can help you spread the word(FB: @collaction.org, Twitter: @collaction_org)!<br>" + "<br>" + "Thanks again for driving the CollAction / crowdacting movement!<br>" + "<br>" + "Warm regards,<br>" + "The CollAction team<br>"; string subject = $"Approval - {project.Name}"; await _emailSender.SendEmailAsync(project.Owner.Email, subject, approvalEmail); } else if (successfull) { string successEmail = "Hi!<br>" + "<br>" + "The deadline of the project you have started on www.collaction.org has passed. We're very happy to see that the target you have set has been reached! Congratulations! Now it's time to act collectively!<br>" + "<br>" + "The CollAction Team might reach out to you with more specifics (this is an automated message). If you have any further questions yourself, feel free to contact the CollAction Team at [email protected]. And don’t forget to tag CollAction in your messages on social media so we can help you spread the word on your achievement (FB: @collaction.org, Twitter: @collaction_org)!<br>" + "<br>" + "Thanks again for driving the CollAction / crowdacting movement!<br>" + "<br>" + "Warm regards,<br>" + "The CollAction team<br>"; string subject = $"Success - {project.Name}"; await _emailSender.SendEmailAsync(project.Owner.Email, subject, successEmail); } else if (failed) { string failedEmail = "Hi!<br>" + "<br>" + "The deadline of the project you have started on www.collaction.org has passed. Unfortunately the target that you have set has not been reached. Great effort though!<br>" + "<br>" + "The CollAction Team might reach out to you with more specifics (this is an automated message). If you have any further questions yourself, feel free to contact the CollAction Team at [email protected].<br>" + "<br>" + "Thanks again for driving the CollAction / crowdacting movement and better luck next time!<br>" + "<br>" + "Warm regards,<br>" + "The CollAction team<br>"; string subject = $"Failed - {project.Name}"; await _emailSender.SendEmailAsync(project.Owner.Email, subject, failedEmail); } project.Name = model.Name; project.Description = model.Description; project.Goal = model.Goal; project.Proposal = model.Proposal; project.CreatorComments = model.CreatorComments; project.CategoryId = model.CategoryId; project.Target = model.Target; project.Start = model.Start; project.End = model.End.Date.AddHours(23).AddMinutes(59).AddSeconds(59); project.Status = model.Status; project.OwnerId = model.OwnerId; project.DisplayPriority = model.DisplayPriority; var bannerImageManager = new ImageFileManager(_context, _hostingEnvironment.WebRootPath, Path.Combine("usercontent", "bannerimages")); project.BannerImage = await bannerImageManager.CreateOrReplaceImageFileIfNeeded(project.BannerImage, model.BannerImageUpload, model.BannerImageDescription); var descriptiveImageManager = new ImageFileManager(_context, _hostingEnvironment.WebRootPath, Path.Combine("usercontent", "descriptiveimages")); project.DescriptiveImage = await descriptiveImageManager.CreateOrReplaceImageFileIfNeeded(project.DescriptiveImage, model.DescriptiveImageUpload, model.DescriptiveImageDescription); await project.SetTags(_context, model.Hashtag?.Split(';') ?? new string[0]); project.SetDescriptionVideoLink(_context, model.DescriptionVideoLink); await _context.SaveChangesAsync(); return(RedirectToAction("ManageProjectsIndex")); } else { model.UserList = new SelectList(await _context.Users.ToListAsync(), "Id", "UserName", null); model.CategoryList = new SelectList(await _context.Categories.ToListAsync(), "Id", "Name", null); model.DisplayPriorityList = new SelectList(Enum.GetValues(typeof(ProjectDisplayPriority))); model.StatusList = new SelectList(Enum.GetValues(typeof(ProjectStatus))); model.BannerImageFile = project.BannerImage; model.DescriptiveImageFile = project.DescriptiveImage; return(View(model)); } }