public async Task CreateRequest(Guid userId, int projectId)
        {
            try
            {
                var user = await _unitOfWork.Repository <User>().Get(u => u.Id == userId);

                var isRequested = await _unitOfWork.Repository <ProjectParticipation>()
                                  .Get(p => p.ProjectId == projectId && p.UserId == userId);


                if (isRequested == null)
                {
                    var member = new ProjectParticipation
                    {
                        User      = user,
                        ProjectId = projectId,
                        Status    = ProjectParticipationStatus.New,
                    };

                    _unitOfWork.Repository <ProjectParticipation>().Add(member);
                    await _unitOfWork.SaveChangesAsync();
                }
                else
                {
                    throw new Exception($"Request already sent for {nameof(userId)}:{userId}" +
                                        $"and {nameof(projectId)}:{projectId}: ");
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Error when creating request for {nameof(userId)}:{userId}" +
                                    $"and {nameof(projectId)}:{projectId}: ", ex);
            }
        }
Beispiel #2
0
        public void Should_Map()
        {
            // Arrange

            ProjectParticipation projectParticipation = ProjectParticipationSeedData.StaffParticipation1;

            var command = new SetProjectParticipation.Command
            {
                CommentByStaffInner           = "CommantByStaffInner",
                CommentTeam                   = "CommentTeam",
                InvitationStatusId            = Guid.NewGuid(),
                MusicianProfileId             = Guid.NewGuid(),
                ParticipationStatusInnerId    = Guid.NewGuid(),
                ParticipationStatusInternalId = Guid.NewGuid(),
                ProjectId = Guid.NewGuid()
            };
            ProjectParticipation expectedParticipation = ProjectParticipationSeedData.StaffParticipation1;

            expectedParticipation.SetProperty(nameof(projectParticipation.CommentByStaffInner), command.CommentByStaffInner);
            expectedParticipation.SetProperty(nameof(projectParticipation.CommentTeam), command.CommentTeam);
            expectedParticipation.SetProperty(nameof(projectParticipation.ParticipationStatusInnerId), command.ParticipationStatusInnerId);
            expectedParticipation.SetProperty(nameof(projectParticipation.ParticipationStatusInternalId), command.ParticipationStatusInternalId);
            expectedParticipation.SetProperty(nameof(projectParticipation.InvitationStatusId), command.InvitationStatusId);

            // Act
            ProjectParticipation mappedParticipation = _mapper.Map(command, projectParticipation);

            // Assert
            mappedParticipation.Should().BeEquivalentTo(expectedParticipation);
        }
Beispiel #3
0
        public void Should_Map_For_Performer()
        {
            // Arrange
            ProjectParticipation projectParticipation = FakeProjectParticipations.PerformerSchneeköniginParticipation;

            _tokenAccessor.UserRoles.Returns(new List <string> {
                RoleNames.Performer
            });
            var expectedDto = new ProjectParticipationDto
            {
                Id = projectParticipation.Id,
                CommentByPerformerInner       = projectParticipation.CommentByPerformerInner,
                CommentByStaffInner           = projectParticipation.CommentByStaffInner,
                CommentTeam                   = null,
                InvitationStatus              = null,
                InvitationStatusId            = null,
                ParticipationStatusInternal   = "Candidate",
                ParticipationStatusInternalId = projectParticipation.ParticipationStatusInternalId,
                ParticipationStatusInner      = "Acceptance",
                ParticipationStatusInnerId    = projectParticipation.ParticipationStatusInnerId,
                MusicianProfile               = ReducedMusicianProfileDtoData.PerformerProfile,
                Project = ReducedProjectDtoData.Schneekönigin,
                Person  = null
            };

            // Act
            ProjectParticipationDto dto = _mapper.Map <ProjectParticipationDto>(projectParticipation);

            // Assert
            dto.Should().BeEquivalentTo(expectedDto);
        }
Beispiel #4
0
        public async Task <ProjectParticipationDto> SetProjectParticipationAsync(SetProjectParticipationDto myProjectParticipationDto)
        {
            SetProjectParticipation.Command command = _mapper
                                                      .Map <SetProjectParticipation.Command>(myProjectParticipationDto);

            ProjectParticipation projectParticipation = await _mediator.Send(command);

            return(_mapper.Map <ProjectParticipationDto>(projectParticipation));
        }
Beispiel #5
0
        public async Task <bool> IsAllowedGetProject(Specification <ProjectParticipation> spec)
        {
            spec.Includes = pp => pp.Include(pp => pp.Project);

            ProjectParticipation projectParticipation = await _projectsParticiparionRepository.ReadOne(spec);

            if (projectParticipation != null)
            {
                return(true);
            }
            return(false);
        }
 public async Task ChangeStatusAsync(int participantId, ProjectParticipationStatus status)
 {
     try
     {
         ProjectParticipation participant = _unitOfWork.Repository <ProjectParticipation>()
                                            .Get().SingleOrDefault(x => x.Id == participantId);
         participant.Status = status;
         _unitOfWork.Repository <ProjectParticipation>().Update(participant);
         await _unitOfWork.SaveChangesAsync();
     }
     catch (Exception ex)
     {
         throw new Exception($"Error while updating the status for {nameof(participantId)}:{participantId}", ex);
     }
 }
Beispiel #7
0
        public async Task <ProjectParticipation> GetHighestParticipation(Specification <ProjectParticipation> spec)
        {
            List <ProjectParticipation> projectParticipations = await _projectsParticiparionRepository.ReadMany(spec);

            ProjectParticipation highestParticipation = new ProjectParticipation()
            {
                ParticipationType = ParticipationType.Executor
            };

            foreach (var projectParticipation in projectParticipations)
            {
                if ((int)highestParticipation.ParticipationType > (int)projectParticipation.ParticipationType)
                {
                    highestParticipation = projectParticipation;
                }
            }
            return(highestParticipation);
        }
Beispiel #8
0
        public async Task AddAsync(ProjectDto projectDto, Guid userId)
        {
            var user = await _unitOfWork.Repository <User>().Get(u => u.Id == userId);

            if (projectDto.ImgFile != null)
            {
                using (var fileStream = projectDto.ImgFile.OpenReadStream())
                {
                    var fileExtension = Path.GetExtension(projectDto.ImgFile.FileName);
                    var fileUri       = await _fileService.SaveFile(fileStream, fileExtension);

                    projectDto.ImgUrl = fileUri.ToString();
                }
            }

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ProjectDto, Project>()
                                                 .ForMember(p => p.DonationTarget, opt => opt.MapFrom(src => src.DonationTargetSum))
                                                 .ForMember(p => p.IsActive, opt => opt.MapFrom(src => true))
                                                 .ForMember(p => p.OwnerId, opt => opt.MapFrom(p => userId)))
                         .CreateMapper();

            var project = mapper.Map <ProjectDto, Project>(projectDto);

            var newParticipant = new ProjectParticipation
            {
                Role    = MemberRole.ProjectOwner,
                User    = user,
                Status  = ProjectParticipationStatus.Approved,
                Project = project,
            };

            try
            {
                _unitOfWork.Repository <Project>().Add(project);
                _unitOfWork.Repository <ProjectParticipation>().Add(newParticipant);
                await _unitOfWork.SaveChangesAsync();
            }
            catch (Exception e)
            {
                e.Data["project"] = projectDto;
                throw;
            }
        }
        public async Task CreateRequest(Guid userId, int projectId)
        {
            try
            {
                ProjectParticipation member = new ProjectParticipation
                {
                    CreatedById = userId,
                    ProjectId   = projectId,
                    Status      = ProjectParticipationStatus.New,
                };

                await _unitOfWork.Repository <ProjectParticipation>().Add(member);

                await _unitOfWork.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw new Exception($"Error when creating request for {nameof(userId)}:{userId}" +
                                    $"and {nameof(projectId)}:{projectId}: ", ex);
            }
        }
Beispiel #10
0
        public async Task Add(ProjectModel projectModel, Guid userId)
        {
            var newProject = new Project
            {
                Name           = projectModel.Name,
                Details        = projectModel.Details,
                Description    = projectModel.Description,
                IsActive       = true,
                ProjectStart   = projectModel.ProjectStart,
                ProjectEnd     = projectModel.ProjectEnd,
                TypeId         = projectModel.TypeId,
                DonationTarget = projectModel.DonationTargetSum
            };

            var newParticipant = new ProjectParticipation
            {
                Role        = DLL.Enums.MemberRole.ProjectOwner,
                CreatedById = userId,
                Status      = DLL.Enums.ProjectParticipationStatus.Approved,
                Project     = newProject,
            };

            try
            {
                await _uow.Repository <Project>().Add(newProject);

                await _uow.SaveChangesAsync();

                await _uow.Repository <ProjectParticipation>().Add(newParticipant);

                await _uow.SaveChangesAsync();
            }
            catch (Exception e)
            {
                e.Data["project"] = projectModel;
                throw;
            }
        }
Beispiel #11
0
        public async Task <bool> IsAllowedToUserManagement(Specification <ProjectParticipation> spec)
        {
            ProjectParticipation projectParticipation = await GetHighestParticipation(spec);

            return(ProjectActionPolicy.UserManagement(projectParticipation.ParticipationType));
        }
Beispiel #12
0
        public async Task <bool> IsAllowedToTaskMooving(Specification <ProjectParticipation> spec)
        {
            ProjectParticipation projectParticipation = await GetHighestParticipation(spec);

            return(ProjectActionPolicy.TaskMooving(projectParticipation.ParticipationType));
        }
Beispiel #13
0
        public async Task <bool> IsAllowedStatusCRUD(Specification <ProjectParticipation> spec)
        {
            ProjectParticipation projectParticipation = await GetHighestParticipation(spec);

            return(ProjectActionPolicy.StatusCRUD(projectParticipation.ParticipationType));
        }