Esempio n. 1
0
        public async Task <CollaboratorResponseDto> AddCollaborator(string email, int userId, CollaboratorRequestDto collaborator)
        {
            try
            {
                Collaborator modelCollaborator = _mapper.Map <Collaborator>(collaborator);
                if (email == modelCollaborator.email)
                {
                    throw new FundooException(ExceptionMessages.SELF_COLLABORATE);
                }
                Collaborator collaboratorWithSameUser = await _collaboratorRepository.GetCollaboratorByEmail(modelCollaborator.email, modelCollaborator.NoteId);

                if (collaboratorWithSameUser != null)
                {
                    throw new FundooException(ExceptionMessages.ALREADY_COLLABORATER);
                }
                Note note = await _noteRepository.GetNote(modelCollaborator.NoteId, userId);

                if (note == null)
                {
                    throw new FundooException(ExceptionMessages.NO_SUCH_NOTE);
                }
                Message message = new EmailService.Message(new string[] { modelCollaborator.email },
                                                           "Added as collaborator",
                                                           $"<h2>You have been added as collaborated by <p style='color:red'>" + email + "</p> To note <p style='color:green'>" + note.Title + "</p><h2>");
                _mqServices.AddToQueue(message);
                return(_mapper.Map <CollaboratorResponseDto>(await _collaboratorRepository.AddCollaborator(email, modelCollaborator)));
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateException)
            {
                throw new FundooException(ExceptionMessages.NO_SUCH_USER);
            }
        }