17 using System.Collections.Generic;
20 using erminas.SmartAPI.CMS.ServerManagement;
21 using erminas.SmartAPI.Utils;
22 using erminas.SmartAPI.Utils.CachedCollections;
24 namespace erminas.SmartAPI.CMS.Project
29 bool ContainsProject(
IProject project);
30 bool ContainsProjectGuid(Guid projectGuid);
31 bool ContainsProjectName(
string projectName);
43 internal class UserProjects : IndexedCachedList<string, IUserProjectAssignment>, IUserProjects
45 private readonly
IUser _user;
47 internal UserProjects(
IUser user,
Caching caching) : base(assignment => assignment.Project.Name, caching)
50 RetrieveFunc = GetProjectAssignments;
55 return UserProjectAssignment.Create(_user, project, role, extendedRoles);
58 public bool ContainsProject(IProject project)
60 return ContainsProjectGuid(project.Guid);
63 public bool ContainsProjectGuid(Guid projectGuid)
65 return this.Any(assignment => assignment.Project.Guid == projectGuid);
68 public bool ContainsProjectName(
string projectName)
70 return ContainsKey(projectName);
80 return this.First(assignment => assignment.Project.Guid == projectGuid);
85 return this[projectName];
90 get {
return GetByProjectGuid(project.Guid); }
93 public void Remove(IProject project)
95 UserProjectAssignment.Delete(project, User);
98 public ISession Session
100 get {
return _user.Session; }
105 return TryGetByProjectName(project.Name, out assignment);
110 assignment = this.FirstOrDefault(projectAssignment => projectAssignment.Project.Guid == projectGuid);
111 return assignment != null;
116 return TryGet(projectName, out assignment);
121 get {
return _user; }
124 private List<IUserProjectAssignment> GetProjectAssignments()
126 const string LIST_USER_PROJECTS =
127 @"<ADMINISTRATION><USER guid=""{0}""><PROJECTS action=""list"" extendedinfo=""1""/></USER></ADMINISTRATION>";
129 var xmlDoc = Session.ExecuteRQL(LIST_USER_PROJECTS.RQLFormat(User));
130 return (from XmlElement assignmentElement in xmlDoc.GetElementsByTagName(
"PROJECT")