diff --git a/src/BL/Models/SubmissionGetProjectModel.cs b/src/BL/Models/SubmissionGetProjectModel.cs index 84a673ab8..5fa271015 100644 --- a/src/BL/Models/SubmissionGetProjectModel.cs +++ b/src/BL/Models/SubmissionGetProjectModel.cs @@ -1,5 +1,6 @@ using BL.Models.Enums; using BL.Models.Helpers; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -27,13 +28,17 @@ public class SubmissionGetProjectModel public virtual List Tres { get; set; } + public virtual List UsersNotInProject { get; set; } + + public virtual List TresNotInProject { get; set; } + public virtual List Submissions { get; set; } public SubmissionGetProjectModel() { } - public SubmissionGetProjectModel(Project Project) + public SubmissionGetProjectModel(Project Project, DbSet UsersAll, DbSet TREsALL) { Id = Project.Id; FormData = Project.FormData; @@ -46,17 +51,38 @@ public SubmissionGetProjectModel(Project Project) SubmissionBucket = Project.SubmissionBucket; OutputBucket = Project.OutputBucket; Users = new List(); - foreach (var item in Project.Users) + UsersNotInProject = new List(); + + + foreach (var user in UsersAll.ToArray()) { - Users.Add(new UserGetProjectModel(item)); + if (Project.Users.Contains(user)) + { + Users.Add(new UserGetProjectModel(user)); + } + else + { + UsersNotInProject.Add(new UserGetProjectModel(user)); + } } + Tres = new List(); - foreach (var item in Project.Tres) + TresNotInProject = new List(); + + + foreach (var tre in TREsALL.ToArray()) { - Tres.Add(new TreGetProjectModel(item, Id)); + if (Project.Tres.Contains(tre)) + { + Tres.Add(new TreGetProjectModel(tre, Id)); + } + else + { + TresNotInProject.Add(new TreGetProjectModel(tre, Id)); + } } - + Submissions = new List(); foreach (var item in Project.Submissions) { diff --git a/src/DARE-API/Controllers/ProjectController.cs b/src/DARE-API/Controllers/ProjectController.cs index 512789f51..90dc8b4e1 100644 --- a/src/DARE-API/Controllers/ProjectController.cs +++ b/src/DARE-API/Controllers/ProjectController.cs @@ -355,7 +355,9 @@ public ProjectController(ApplicationDbContext applicationDbContext, MinioSetting } Log.Information("{Function} Project retrieved successfully", "GetProject"); - return new SubmissionGetProjectModel(returned); + var Users = _DbContext.Users.ToList(); + _DbContext.Tres.ToList(); + return new SubmissionGetProjectModel(returned, _DbContext.Users, _DbContext.Tres); } catch (Exception ex) { diff --git a/src/DARE-FrontEnd/Controllers/ProjectController.cs b/src/DARE-FrontEnd/Controllers/ProjectController.cs index 36ed7d5cc..ed8aedea2 100644 --- a/src/DARE-FrontEnd/Controllers/ProjectController.cs +++ b/src/DARE-FrontEnd/Controllers/ProjectController.cs @@ -89,11 +89,9 @@ public async Task GetProject(int id) //Log.Error("minioEndpoint took ElapsedMilliseconds" + stopwatch.ElapsedMilliseconds); stopwatch.Stop(); var project = projectawait.Result; - var users = _clientHelper.CallAPIWithoutModel>("/api/User/GetAllUsers/").Result; - var tres = _clientHelper.CallAPIWithoutModel>("/api/Tre/GetAllTres/").Result; - - var userItems2 = users.Where(p => !project.Users.Select(x => x.Id).Contains(p.Id)).ToList(); - var treItems2 = tres.Where(p => !project.Tres.Select(x => x.Id).Contains(p.Id)).ToList(); + + var userItems2 = project.UsersNotInProject; + var treItems2 = project.TresNotInProject; var userItems = userItems2 .Select(p => new SelectListItem { Value = p.Id.ToString(), Text = p.FullName != "" ? p.FullName : p.Name })