Esempio n. 1
0
        public async Task <ActionResult> CreateSurvey([FromBody] SurveyModel survey)
        {
            var result = await _repository
                         .Create(survey)
                         .ConfigureAwait(false);

            _logger.LogInformation($"Survey created with Id={survey.SurveyId }");
            return(Ok(result));
        }
Esempio n. 2
0
        public async Task Create(Survey survey)
        {
            survey.Id = survey.GenerateGuid();

            foreach (var option in survey.Options)
            {
                option.Id = survey.GenerateGuid();
            }

            await _repository.Create(survey);
        }
Esempio n. 3
0
        private Survey CreateSurveyOnInputBasis(Entity.Command command)
        {
            var survey = _repository.Create();

            survey.Player   = _player;
            survey.Question = _textFactory.CreateText(GetQuestionOption(command));
            survey.Choices  = GetChoices(command).Select(choice => _textFactory.CreateText(choice)).ToList();
            survey.Votes    = new List <Domain.Entity.Vote>();

            return(survey);
        }
Esempio n. 4
0
        public OperationResult.SeeOther Post(NewSurveyResource resource)
        {
            var s = repository.Create(resource.Name, resource.Title, resource.Description);
            var r = new SurveyResource {
                Id = s.Id, Name = s.Name, Title = s.Title, Description = s.Description
            };

            return(new OperationResult.SeeOther {
                RedirectLocation = r.CreateUri()
            });
        }
Esempio n. 5
0
        public async Task <ISurvey> CreateNewSurvey(ISurvey surveyDto)
        {
            try
            {
                var survey = Mappings.Mapper.Map <Entities.Survey>(surveyDto);
                survey.Id = Guid.NewGuid();
                var preservedEntity = await _surveyRepository.Create(survey);

                surveyDto.Id = preservedEntity.Id;
                return(surveyDto);
            }
            catch (Exception e)
            {
                _logger.Error(e, "SurveyManagementService.CreateNewSurvey");
                throw;
            }
        }
Esempio n. 6
0
        public async Task GivenSurvey_WhenCreate_ThenCreateSuccessful()
        {
            //?Given
            var survey = GetSurvey();

            var surveyEntity = GetSurveyEntity();

            _mockMapper.Setup(x => x.Map <SurveyEntity>(It.IsAny <Survey>()))
            .Returns(surveyEntity)
            .Verifiable();

            //?When
            await _surveyRepository.Create(survey);

            //?Then
            _mockMapper.Verify();
            _mockService.Verify();
            _mockService.Verify(t => t.Create(It.IsAny <string>(), It.Is <SurveyEntity>(e => MessageeIsWellCreated(e, survey))), Times.Once);
        }
Esempio n. 7
0
        public Survey CreateSurvey(List <int> surveyQuestions, List <Grade> surveyAnswers, int appointmentId)
        {
            if (!CheckIfExistsById(appointmentId))
            {
                return(null);
            }
            Survey survey = new Survey();

            survey.AppointmentId   = appointmentId;
            survey.Date            = DateTime.Now;
            survey.SurveyQuestions = surveyQuestions;
            survey.SurveyAnswers   = surveyAnswers;
            Survey createdSurvey = surveyRepository.Create(survey);
            bool   update        = surveyQuestionRepository.UpdateSurveyQuestion(createdSurvey);

            if (!update)
            {
                return(null);
            }
            return(createdSurvey);
        }
Esempio n. 8
0
        public async Task <JsonResult> Save(string id, string title, string description, string[][] lines, string image, string addedimage)
        {
            Survey survey;

            survey = surveyRepository.GetItems().Include(x => x.SurveyQuestion).FirstOrDefault(x => x.Id == id);
            byte[] dataimage      = Convert.FromBase64String(image);
            byte[] addeddataimage = Convert.FromBase64String(addedimage == null ? "" : addedimage);
            if (id == null || survey == null)
            {
                var user = UserHelper.GetUser(HttpContext, userRepository);
                survey = await surveyRepository.Create(new Survey { Title = title, Description = description, DateCreated = DateTime.UtcNow, CreatedById = user.Id, Image = dataimage, AddedImage = addeddataimage });

                id = survey.Id;
            }
            else
            {
                survey.Title       = title;
                survey.Description = description;
                survey.Image       = dataimage;
                survey.AddedImage  = addeddataimage;
                await surveyRepository.Update(survey);

                List <SurveyQuestion> questions = new List <SurveyQuestion>();
                foreach (var question in survey.SurveyQuestion)
                {
                    bool found = false;
                    for (int i = 0; !found && i < lines.Length; i++)
                    {
                        if (lines[i][0] == question.Id)
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        questions.Add(question);
                    }
                }

                foreach (var question in questions)
                {
                    await RemoveQuestion(question.Id);
                }
            }

            for (int i = 0; i < lines.Length; i++)
            {
                SurveyQuestion question = await surveyQuestionRepository.GetItem(lines[i][0]);

                if (question == null)
                {
                    question = await surveyQuestionRepository.Create(new SurveyQuestion
                    {
                        SurveyId     = id,
                        QuestionText = lines[i][1],
                        Type         = int.Parse(lines[i][2]),
                        HasOwnAnswer = bool.Parse(lines[i][3]),
                        IsRequired   = bool.Parse(lines[i][4]),
                        Order        = i
                    });
                }
                else
                {
                    question.QuestionText = lines[i][1];
                    question.Type         = int.Parse(lines[i][2]);
                    question.HasOwnAnswer = bool.Parse(lines[i][3]);
                    question.IsRequired   = bool.Parse(lines[i][4]);
                    question.Order        = i;
                    await surveyQuestionRepository.Update(question);
                }

                List <Option> options = new List <Option>();

                foreach (var option in optionRepository.GetItems().Where(x => x.QuestionId == question.Id))
                {
                    bool found = false;
                    for (int j = 5; !found && j < lines[i].Length; j += 2)
                    {
                        if (lines[i][j] == option.Id)
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        options.Add(option);
                    }
                }

                foreach (var option in options)
                {
                    await optionRepository.Delete(option);
                }

                for (int j = 5, ord = 0; j < lines[i].Length; j += 2, ord++)
                {
                    var option = await optionRepository.GetItem(lines[i][j]);

                    if (option == null)
                    {
                        await optionRepository.Create(new Option { QuestionId = question.Id, Text = lines[i][j + 1], Order = ord });
                    }
                    else
                    {
                        option.Text  = lines[i][j + 1];
                        option.Order = ord;
                        await optionRepository.Update(option);
                    }
                }
            }
            return(Json(new { id }));
        }
Esempio n. 9
0
        public IActionResult Create(SurveyViewModel surveyViewModel)
        {
            _surveyRepository.Create(surveyViewModel.Survey);

            return(RedirectToAction("List"));
        }