コード例 #1
0
        private async Task UpdateMeaningOfSignaturesInternalAsync(int reviewId, int userId, ReviewPackageRawData reviewRawData,
                                                                  IEnumerable <MeaningOfSignatureParameter> meaningOfSignatureParameters, IMeaningOfSignatureUpdateStrategy updateStrategy)
        {
            var meaningOfSignatureParamList = meaningOfSignatureParameters.ToList();

            var participantIds = meaningOfSignatureParamList.Select(mos => mos.ParticipantId).ToList();

            var possibleMeaningOfSignatures = await _reviewsRepository.GetPossibleMeaningOfSignaturesForParticipantsAsync(reviewId, userId, participantIds);

            if (reviewRawData.Reviewers == null)
            {
                throw new BadRequestException("Could not update meaning of signature because participant is not in review.", ErrorCodes.UserNotInReview);
            }

            foreach (var participantId in participantIds)
            {
                var participant = reviewRawData.Reviewers.FirstOrDefault(r => r.UserId == participantId);

                if (participant == null)
                {
                    throw new BadRequestException("Could not update meaning of signature because participant is not in review.", ErrorCodes.UserNotInReview);
                }

                if (participant.Permission != ReviewParticipantRole.Approver)
                {
                    throw new BadRequestException("Could not update meaning of signature because participant is not an approver.", ErrorCodes.ParticipantIsNotAnApprover);
                }

                var meaningOfSignatureUpdates = updateStrategy.GetMeaningOfSignatureUpdates(participantId, possibleMeaningOfSignatures, meaningOfSignatureParamList).ToList();


                if (!meaningOfSignatureUpdates.Any())
                {
                    participant.SelectedRoleMoSAssignments = new List <ParticipantMeaningOfSignature>();

                    return;
                }

                if (participant.SelectedRoleMoSAssignments == null)
                {
                    participant.SelectedRoleMoSAssignments = new List <ParticipantMeaningOfSignature>();
                }

                foreach (var meaningOfSignatureUpdate in meaningOfSignatureUpdates)
                {
                    var meaningOfSignature = meaningOfSignatureUpdate.MeaningOfSignature;

                    var participantMeaningOfSignature = participant.SelectedRoleMoSAssignments.FirstOrDefault(pmos => pmos.RoleId == meaningOfSignature.RoleId);

                    if (participantMeaningOfSignature == null)
                    {
                        if (!meaningOfSignatureUpdate.Adding)
                        {
                            continue;
                        }

                        participantMeaningOfSignature = new ParticipantMeaningOfSignature();

                        participant.SelectedRoleMoSAssignments.Add(participantMeaningOfSignature);
                    }
                    else if (!meaningOfSignatureUpdate.Adding)
                    {
                        participant.SelectedRoleMoSAssignments.Remove(participantMeaningOfSignature);

                        continue;
                    }

                    participantMeaningOfSignature.ParticipantId           = participantId;
                    participantMeaningOfSignature.ReviewId                = reviewId;
                    participantMeaningOfSignature.MeaningOfSignatureId    = meaningOfSignature.MeaningOfSignatureId;
                    participantMeaningOfSignature.MeaningOfSignatureValue = meaningOfSignature.MeaningOfSignatureValue;
                    participantMeaningOfSignature.RoleId           = meaningOfSignature.RoleId;
                    participantMeaningOfSignature.RoleName         = meaningOfSignature.RoleName;
                    participantMeaningOfSignature.RoleAssignmentId = meaningOfSignature.RoleAssignmentId;
                    participantMeaningOfSignature.GroupId          = meaningOfSignature.GroupId;
                }
            }
        }