Beispiel #1
0
        public async Task <GetContributorsByMemberUsernameResponse> Handle(GetContributorsByMemberUsernameRequest query, CancellationToken cancellationToken)
        {
            var result = new GetContributorsByMemberUsernameResponse();

            var contributors = await _context.Contributors
                               .Where(x => x.MemberUsername == query.MemberUsername)
                               .Include(a => a.Project).ThenInclude(a => a.Blockchain)
                               .ToListAsync(cancellationToken);

            if (contributors.Count == 0)
            {
                result.IsSuccessful = false;
                result.ErrorMessage = ErrorMessage.ContributorNotFound;

                return(result);
            }

            foreach (var contributor in contributors)
            {
                ContributorDTO contributorDTO = new ContributorDTO
                {
                    ContributorID         = contributor.ContributorID,
                    ProjectID             = contributor.ProjectID,
                    InvitationStatus      = contributor.InvitationStatus,
                    ProjectName           = contributor.Project.Name,
                    ProjectBlockchainName = contributor.Project.Blockchain.Name
                };

                result.Contributors.Add(contributorDTO);
            }

            result.IsSuccessful = true;

            return(result);
        }
Beispiel #2
0
        public async Task <GetProjectResponse> Handle(GetProjectRequest query, CancellationToken cancellationToken)
        {
            var result = new GetProjectResponse();

            if (query.IsExistProjectByMemberUsername != null)
            {
                result.IsExistProjectByMemberUsernameResult = false;

                var isExistProject = await _context.Projects
                                     .Where(x => x.MemberUsername == query.IsExistProjectByMemberUsername)
                                     .FirstOrDefaultAsync(cancellationToken);

                if (isExistProject != null)
                {
                    result.IsSuccessful = true;
                    result.IsExistProjectByMemberUsernameResult = true;
                    result.ProjectID = isExistProject.ProjectID;
                }

                return(result);
            }

            var project = await _context.Projects
                          .Where(x => x.ProjectID == query.ProjectID)
                          .Include(a => a.Blockchain)
                          .Include(a => a.Contributors)
                          .Include(a => a.ProjectDocuments)
                          .SingleOrDefaultAsync(cancellationToken);

            if (project == null)
            {
                result.IsSuccessful = false;

                throw new NotFoundException(nameof(Project), query.ProjectID);
            }

            result.IsSuccessful     = true;
            result.ProjectID        = query.ProjectID;
            result.MemberUsername   = project.MemberUsername;
            result.Name             = project.Name;
            result.BlockchainID     = project.Blockchain.BlockchainID;
            result.BlockchainName   = project.Blockchain.Name;
            result.Description      = project.Description;
            result.WalletAddress    = project.WalletAddress;
            result.ProjectStatus    = project.ProjectStatus;
            result.Contributors     = new List <ContributorDTO>();
            result.ProjectDocuments = new List <ProjectDocumentDTO>();

            foreach (var contributor in project.Contributors)
            {
                var contributorDTO = new ContributorDTO()
                {
                    ContributorID    = contributor.ContributorID,
                    MemberUsername   = contributor.MemberUsername,
                    InvitationStatus = contributor.InvitationStatus,
                    ProjectID        = contributor.ProjectID
                };

                result.Contributors.Add(contributorDTO);
            }

            foreach (var projectDocument in project.ProjectDocuments)
            {
                var projectDocumentDTO = new ProjectDocumentDTO()
                {
                    ProjectDocumentID = projectDocument.ProjectDocumentID,
                    DocumentID        = projectDocument.DocumentID,
                    Title             = projectDocument.Title,
                    OriginalFileName  = projectDocument.OriginalFileName
                };

                result.ProjectDocuments.Add(projectDocumentDTO);
            }

            return(result);
        }
Beispiel #3
0
        public async Task <CreateContributorsResponse> Handle(CreateContributorsRequest request, CancellationToken cancellationToken)
        {
            var result = new CreateContributorsResponse();

            foreach (var candidate in request.MemberUsername)
            {
                var invitedContributor = await _context.Contributors
                                         .Where(x => x.MemberUsername == candidate && x.ProjectID == request.ProjectID)
                                         .FirstOrDefaultAsync(cancellationToken);

                if (invitedContributor == null)
                {
                    var contributor = new Contributor
                    {
                        MemberUsername   = candidate,
                        ProjectID        = request.ProjectID,
                        InvitationCode   = Guid.NewGuid(),
                        InvitationStatus = InvitationStatus.Invited
                    };

                    await _context.Contributors.AddAsync(contributor);

                    ContributorDTO contributorDTO = new ContributorDTO
                    {
                        MemberUsername = contributor.MemberUsername,
                        ProjectID      = contributor.ProjectID,
                        InvitationCode = contributor.InvitationCode
                    };

                    result.Contributors.Add(contributorDTO);
                }
            }

            await _context.SaveChangesAsync(cancellationToken);

            foreach (var contributorDTO in result.Contributors)
            {
                StringBuilder emailBodyStringBuilder = new StringBuilder();
                emailBodyStringBuilder.AppendLine("Silahkan klik link di bawah ini untuk Accept atau Reject");
                emailBodyStringBuilder.AppendLine("<br />");
                emailBodyStringBuilder.AppendLine($"Username Anda: {contributorDTO.MemberUsername} : {contributorDTO.InvitationCode}");
                emailBodyStringBuilder.AppendLine("<br />");
                emailBodyStringBuilder.AppendLine("<div>");
                emailBodyStringBuilder.AppendLine($"<a href=\"{_currentWeb.BaseURL}/projects/accept?invitationCode={contributorDTO.InvitationCode}\">Accept</a>");
                emailBodyStringBuilder.AppendLine($"<a href=\"{_currentWeb.BaseURL}/projects/reject?invitationCode={contributorDTO.InvitationCode}\">Reject</a>");
                emailBodyStringBuilder.AppendLine("</div>");

                EmailItem mailItem = new EmailItem
                {
                    ToAdress = "*****@*****.**",
                    Subject  = "Welcome to Fortifex",
                    Body     = emailBodyStringBuilder.ToString()
                };

                await _emailService.SendEmailAsync(mailItem);
            }

            result.IsSuccessful = true;

            return(result);
        }