Exemple #1
0
        public async Task <IActionResult> Delete(long id)
        {
            var userId       = _userManager.GetUserId(HttpContext.User);
            var collaborator = _collaboratorRepository.Find(id);

            if (collaborator == null)
            {
                return(NotFound());
            }


            var currentCollaborator = _collaboratorRepository.Find(collaborator.ProjectID, userId);

            // You can only delete if you exist and are trying to delete yourself
            // or when you are the owner of the project
            if (currentCollaborator != null && (currentCollaborator == collaborator || currentCollaborator.Permission == Permissions.Owner))
            {
                // Broadcast new collaborator
                var project = _projectRepository.Find(collaborator.ProjectID);
                await _projAndCollabHandler.Remove(
                    project.Id,
                    project.Name,
                    collaborator.Id
                    );

                _collaboratorRepository.Remove(id);
                return(NoContent());
            }
            return(Unauthorized());
        }
Exemple #2
0
        public async Task Remove(Guid id)
        {
            var collaborator = _collaboratorRepository.GetCollaboratorPhonesAddressesContacts(id);

            foreach (var phone in collaborator.Result.Phones)
            {
                await _phoneService.Remove(phone.Id);
            }

            foreach (var address in collaborator.Result.Addresses)
            {
                await _addressService.Remove(address.Id);
            }

            await _collaboratorRepository.Remove(id);
        }