コード例 #1
0
        public void Invoke(int projectId, Policy policy, PolicyConfiguration policyConfiguration)
        {
            var project = projectRepository.GetById(projectId);

            if (project == null)
            {
                throw new ArgumentNullException($"Cannot find project with id: {projectId}.");
            }

            var projectPolicy = project.ProjectPolicies.FirstOrDefault(m => m.Policy == policy);

            if (projectPolicy != null)
            {
                project.ProjectPolicies.Remove(projectPolicy);
                project.ProjectPolicies.Add(new ProjectPolicies
                {
                    Policy = policy,
                    SerializedProjectPolicySetting = jsonConvertService.Serialize(policyConfiguration)
                });
            }
            else
            {
                project.ProjectPolicies.Add(new ProjectPolicies
                {
                    Policy = policy,
                    SerializedProjectPolicySetting = jsonConvertService.Serialize(policyConfiguration)
                });
            }
            projectRepository.Edit(project);
            eventBus.Publish(new PolicySaved(projectId, policy));
        }
コード例 #2
0
        public void Invoke(int projectId, int userId, Policy policy, DateTime userExpDate)
        {
            var project = projectRepository.GetByIdWithPolicies(projectId);

            if (project == null)
            {
                throw new ArgumentNullException($"Cannot find user with id:{projectId}");
            }

            var userPolicy = project.ProjectPolicies.FirstOrDefault(m => m.Policy == policy)
                             .UserPolicies.FirstOrDefault(m => m.UserId == userId);

            if (userPolicy != null)
            {
                project.ProjectPolicies.FirstOrDefault(m => m.Policy == policy).UserPolicies.Remove(userPolicy);
                if (userExpDate == default(DateTime))
                {
                    projectRepository.Edit(project);
                    return;
                }
                var result =
                    (UserAccountExpirationDateConfiguration)
                    jsonConvertService.DeserializeUser(policy, userPolicy.SerializedUserPolicySetting);
                result.ExpirationDate = userExpDate;
                userPolicy.SerializedUserPolicySetting = jsonConvertService.Serialize(result);
                project.ProjectPolicies.FirstOrDefault(m => m.Policy == policy).UserPolicies.Add(userPolicy);
            }
            else
            {
                if (userExpDate == default(DateTime))
                {
                    return;
                }
                userPolicy = new UserPolicies
                {
                    UserId = userId,
                    SerializedUserPolicySetting =
                        jsonConvertService.Serialize(new UserAccountExpirationDateConfiguration
                    {
                        ExpirationDate = userExpDate
                    })
                };
                project.ProjectPolicies.FirstOrDefault(m => m.Policy == policy).UserPolicies.Add(userPolicy);
            }
            projectRepository.Edit(project);
        }