Exemplo n.º 1
0
        public void ShareEntry(User user, ShareEntryDto shareEntryDto)
        {
            var entryAggregate = _repository.GetById <EntryAggregate>(shareEntryDto.EntryId);

            entryAggregate.ShareWith(user.Id, shareEntryDto.CollaboratorIds, shareEntryDto.Message);
            _repository.Save(entryAggregate, commitId: Guid.NewGuid(), updateHeaders: null);
        }
Exemplo n.º 2
0
        // POST entries/{entryId}/share
        // Share the entry for the user.
        public async Task <ActionResult> ShareEntry([FromBody] ShareEntryDto shareEntryDto)
        {
            var currentUser = await _userService.GetUserAsync(User);

            // Get the entry.
            var entry = await _entryService.GetEntryAsync(currentUser, shareEntryDto.EntryId);

            if (entry == null)
            {
                _logger.LogInformation($"ShareEntry action called with entry id of {shareEntryDto.EntryId} which was not valid when being requested by user id of {currentUser.Id}");
                return(new BadRequestResult());
            }

            if (entry.Author.Id != currentUser.Id)
            {
                _logger.LogInformation($"ShareEntry action called with entry id of {shareEntryDto.EntryId} by user id of {currentUser.Id}, which was not the creator of the entry, which is user id {entry.Author.Id}");
                return(new BadRequestResult());
            }

            var existingCollaborators = await _entryService.GetCollaboratorsAsync(shareEntryDto.EntryId);

            // Just in case the list container the current user or any existing collaborators, remove them.
            shareEntryDto.CollaboratorIds.Remove(currentUser.Id);
            foreach (var collaborator in existingCollaborators)
            {
                shareEntryDto.CollaboratorIds.Remove(collaborator.Id);
            }

            // Remove the entry.
            _entryService.ShareEntry(currentUser, shareEntryDto);

            return(new OkResult());
        }