Пример #1
0
        public async Task <IActionResult> Create([FromBody] Participant dto)
        {
            ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

            Participant created = await _participantService.CreateAsync(dto, user, ModelState.AddModelError);

            if (created == null)
            {
                return(BadRequest(ModelState));
            }

            return(CreatedAtAction(
                       nameof(Get),
                       new { id = dto.ID },
                       dto
                       ));
        }
Пример #2
0
        public async Task <IActionResult> Create([FromBody] Chatroom dto)
        {
            ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

            Chatroom created = await _chatroomService.CreateAsync(dto, user, ModelState.AddModelError);

            Participant participant = await _participantService.CreateAsync(
                new Participant { ChatroomID = created.ID, UserID = user.Id, }, user, ModelState.AddModelError);

            if (created == null || participant == null)
            {
                return(BadRequest(ModelState));
            }

            return(CreatedAtAction(
                       nameof(Get),
                       new { id = created.ID },
                       created
                       ));
        }
Пример #3
0
        public async Task SeedAsync()
        {
            var users = await _userService.BrowseAsync();

            if (users.Any())
            {
                _logger.LogTrace("Data was already initialized.");
                return;
            }
            _logger.LogTrace("Initializing data...");

            for (var i = 1; i <= 5; i++)
            {
                var userId   = Guid.NewGuid();
                var courseId = Guid.NewGuid();
                var username = $"user{i}";
                await _userService.RegisterAsync(userId, $"user{i}@test.com", username, "secret", "Wroclaw", "user");

                _logger.LogTrace($"Adding user with username: '******'.");
                await _courseService.CreateAsync(courseId, $"Nauka angielskiego '{listOfSubjects[i-1]}'", 5, "Radlin", "Opis...", "Biologia 1", "Szkola podstawowa", "Biologia");

                _logger.LogTrace($"Adding course for: '{listOfSubjects[i-1]}'.");
                await _leaderService.CreateAsync(userId);

                _logger.LogTrace($"Adding leader for: '{username}'.");
                await _participantService.CreateAsync(userId);

                _logger.LogTrace($"Adding participant for: '{username}'.");
            }

            for (var i = 1; i <= 3; i++)
            {
                var userId   = Guid.NewGuid();
                var username = $"admin{i}";
                _logger.LogTrace($"Adding admin with username: '******'.");
                await _userService.RegisterAsync(userId, $"admin{i}@test.com", username, "secret", "Wroclaw", "admin");
            }
            _logger.LogTrace("Data was initialized.");
        }
Пример #4
0
        //
        // Summary:
        //     get remain a question by session id for client
        //
        // Returns:
        //      question model
        //
        // Params:
        //      question model with list of mixed sub question and choise
        //

        public async Task <QuestionParams> GetRemainByParticipantAsync(Guid?participantid)
        {
            //get participant session
            var participant = await _participantService.GetAsync(participantid.GetValueOrDefault());

            if (participantid == null)
            {
                //no history answer for participant
                //throw new ParticipantNotFoundException();

                var pp = new Participant()
                {
                    Name  = "t5hany6adol",
                    Email = "*****@*****.**"
                };

                participant = await _participantService.CreateAsync(pp);
            }

            //prepaire data
            var questions = await _questionRepository.ListAsync();

            var subQuestions = await _subQuestionRepository.ListAsync();

            var choises = await _choiseService.ListChoiseAsync();

            //get list of answer to compare with remain
            var recentAnswers = await _answerService.ListByParticipantAsync(participant.Id);

            if (recentAnswers.Any())
            {
                var temp = subQuestions.Where(c => recentAnswers.Select(y => y.SubQuestionId).ToArray().Contains(c.Id));

                //get remain question by subquestionid
                questions = questions.Where(c => !temp.GroupBy(y => y.QuestionId).Select(x => x.Key).Contains(c.Id));
            }

            //complete session with choise and subquestion by order
            var pickedQuestion = questions.OrderBy(c => c.Order).FirstOrDefault();

            //get subquestion and assign full choise
            var selectSubQuestions = subQuestions.Where(c => c.QuestionId == pickedQuestion.Id)
                                     .Select(c => { c.Choises = choises.Where(w => w.Id == c.ChoiseId).ToList(); return(c); }).ToList();

            //assign choise
            var entity = new QuestionParams()
            {
                Id    = pickedQuestion.Id,
                Title = pickedQuestion.Title,

                ParticipantId = participant.Id,

                Order = pickedQuestion.Order,

                SubQuestions = selectSubQuestions,
                By           = pickedQuestion.By,

                Date = pickedQuestion.Date
            };


            return(entity);
        }