예제 #1
0
        public Participant ProgressParticipant(string evaluationId, Progression newProgression)
        {
            string      azureUniqueId = _authService.GetOID();
            Evaluation  evaluation    = _evaluationService.GetEvaluation(evaluationId);
            Participant participant   = _participantService.GetParticipant(azureUniqueId, evaluation);

            Participant progressedParticipant = _participantService.ProgressParticipant(participant, newProgression);

            return(progressedParticipant);
        }
        //private readonly IParticipantService _participantService;
        //public ParticipantController(IParticipantService participantService)
        //{
        //    this._participantService = participantService;
        //}
        //public ParticipantController()
        //    : this(new ParticipantService(new ParticipantRepository()))
        //{
        //    CacheManager.SetProvider(new CacheProvider());
        //}


        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            IParticipantService _participantService = new ParticipantService(new ParticipantRepository());
            Participant         participantModel    = new Participant();
            Hash baseCrypt = new Hash();

            var    user     = _participantService.GetParticipant(context.UserName, context.UserName);
            string password = baseCrypt.GetHash(context.Password, user.Salt, CypherType.SHA512);

            var participant = _participantService.Authenticate(context.UserName, password, user.Salt);

            if (participant == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim(ClaimTypes.Sid, participant.Id.ToString()));
            identity.AddClaim(new Claim("sub", context.UserName));
            identity.AddClaim(new Claim("role", "user"));
            identity.AddClaim(new Claim("participant_Id", participant.Id.ToString()));

            context.Validated(identity);
        }
예제 #3
0
        public void GetAzureIdNotExists()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);
            string             azureUniqueId      = "get_azure_unique_id_not_exists";

            Assert.Throws <NotFoundInDBException>(() => participantService.GetParticipant(azureUniqueId, evaluation));
        }
예제 #4
0
        public void AssertIsFacilitator(string evaluationId)
        {
            string      oid         = GetOID();
            Evaluation  evaluation  = _evaluationService.GetEvaluation(evaluationId);
            Participant participant = _participantService.GetParticipant(oid, evaluation);

            if (participant.Role != Role.Facilitator)
            {
                throw new UnauthorizedAccessException($"Current user is not Facilitator");
            }
        }
예제 #5
0
        public void GetExist()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);
            Participant        participantCreate  = participantService.Create("GetExist_id", evaluation, Organization.Engineering, Role.Participant);

            Participant participantGet = participantService.GetParticipant(participantCreate.Id);

            Assert.Equal(participantCreate, participantGet);
        }
예제 #6
0
        public void GetAzureId()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);
            string             azureUniqueId      = "GetAzureId_id";
            Participant        participantCreated = participantService.Create(azureUniqueId, evaluation, Organization.Engineering, Role.Participant);

            Participant participantGet = participantService.GetParticipant(azureUniqueId, evaluation);

            Assert.Equal(participantCreated, participantGet);
        }
예제 #7
0
        public void Delete()
        {
            EvaluationService evaluationService = new EvaluationService(_context);
            Evaluation        evaluation        = evaluationService.GetAll().First();

            ParticipantService participantService = new ParticipantService(_context);

            Participant participantCreate = participantService.Create("Delete_id", evaluation, Organization.Engineering, Role.Participant);

            participantService.Remove(participantCreate.Id);

            Assert.Throws <NotFoundInDBException>(() => participantService.GetParticipant(participantCreate.Id));
        }
        public async Task <ParticipantDto> GetParticipant(int participantId)
        {
            try
            {
                ParticipantDto result = await ParticipantService.GetParticipant(participantId);

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #9
0
        public Participant ProgressParticipant(string evaluationId, Progression newProgression)
        {
            string      azureUniqueId = _authService.GetOID();
            Evaluation  evaluation    = _evaluationService.GetEvaluation(evaluationId);
            Participant participant   = _participantService.GetParticipant(azureUniqueId, evaluation);

            Role[] canBePerformedBy = { Role.Facilitator, Role.OrganizationLead, Role.Participant };
            AssertCanPerformMutation(evaluation, canBePerformedBy);

            Participant progressedParticipant = _participantService.ProgressParticipant(participant, newProgression);

            return(progressedParticipant);
        }
예제 #10
0
        public Answer SetAnswer(string questionId, Severity severity, string text)
        {
            string azureUniqueId = _authService.GetOID();

            IQueryable <Question> queryableQuestion = _questionService.GetQuestion(questionId);
            Question    question    = queryableQuestion.First();
            Evaluation  evaluation  = queryableQuestion.Select(q => q.Evaluation).First();
            Participant participant = _participantService.GetParticipant(azureUniqueId, evaluation);

            Answer answer;

            try
            {
                answer = _answerService.GetAnswer(question, participant, evaluation.Progression);
                _answerService.UpdateAnswer(answer, severity, text);
            }
            catch (NotFoundInDBException)
            {
                answer = _answerService.Create(participant, question, severity, text);
            }

            return(answer);
        }
예제 #11
0
        public void GetDoesNotExists()
        {
            ParticipantService participantService = new ParticipantService(_context);

            Assert.Throws <NotFoundInDBException>(() => participantService.GetParticipant("some_participant_id_that_does_not_exist"));
        }