Пример #1
0
        public async Task <RemoveContactFromOrganisationResponse> Handle(RemoveContactFromOrganisationRequest request, CancellationToken cancellationToken)
        {
            var currentPrivileges = (await _contactQueryRepository.GetPrivilegesFor(request.ContactId));

            foreach (var currentPrivilege in currentPrivileges.Where(p => p.Privilege.MustBeAtLeastOneUserAssigned))
            {
                if (await _contactRepository.IsOnlyContactWithPrivilege(request.ContactId, currentPrivilege.PrivilegeId))
                {
                    return(new RemoveContactFromOrganisationResponse()
                    {
                        Success = false,
                        ErrorMessage = $"Before you remove this user, you must assign '{currentPrivilege.Privilege.UserPrivilege}' to another user."
                    });
                }
            }

            await _contactRepository.RemoveContactFromOrganisation(request.ContactId);

            await _contactRepository.RemoveAllPrivileges(request.ContactId);

            await _contactRepository.CreateContactLog(request.RequestingUserId, request.ContactId, ContactLogType.UserRemoved,
                                                      null);


            await LogContactRemovedChanges(request);

            return(new RemoveContactFromOrganisationResponse()
            {
                Success = true,
                SelfRemoved = request.ContactId == request.RequestingUserId
            });
        }
        public async Task <IActionResult> GetPrivilegesForContact(Guid userId)
        {
            var privileges = await _contactQueryRepository.GetPrivilegesFor(userId);

            return(Ok(privileges));
        }