Ejemplo n.º 1
0
        public static bool HasEqualMembership(this IUser user, ProjectMembership membership)
        {
            if (user is null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (membership is null)
            {
                throw new ArgumentNullException(nameof(membership));
            }

            return(new ProjectMembershipComparer().Equals(user.ProjectMembership(membership.ProjectId), membership));
        }
Ejemplo n.º 2
0
        public static TUser UpdateProjectMembership <TUser>(this TUser user, ProjectMembership membership)
            where TUser : class, IUser
        {
            if (user is null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (membership is null)
            {
                throw new ArgumentNullException(nameof(membership));
            }

            var existingMembership = user.ProjectMemberships.FirstOrDefault(m => m.ProjectId == membership.ProjectId);

            existingMembership.Role       = membership.Role;
            existingMembership.Properties = membership.Properties ?? new Dictionary <string, string>();

            return(user);
        }
Ejemplo n.º 3
0
        public static void EnsureProjectMembership(this IUser user, ProjectMembership membership)
        {
            if (user is null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (membership is null)
            {
                throw new ArgumentNullException(nameof(membership));
            }

            var existingMembership = user.ProjectMemberships.FirstOrDefault(m => m.ProjectId == membership.ProjectId);

            if (existingMembership is null)
            {
                user.ProjectMemberships.Add(membership);
            }
            else
            {
                existingMembership.Role = membership.Role;
                existingMembership.MergeProperties(membership.Properties, overwriteExistingValues: true);
            }
        }