Ejemplo n.º 1
0
        public UpdateResult Create(Model.Models.Survey survey)
        {
            UpdateResult result = new UpdateResult();

            try
            {
                _surveyRepository.Add(survey);
                Save();

                foreach (Question question in survey.Questions)
                {
                    question.SurveyId = survey.Id;
                    _questionRepository.Add(question);
                }

                Save();

                foreach (Question question in survey.Questions)
                {
                    foreach (Answer answer in question.Answers)
                    {
                        answer.QuestionId = question.Id;
                        _answerRepository.Add(answer);
                    }
                }

                Save();
            }
            catch (Exception exception)
            {
                result.State       = 4;
                result.KeyLanguage = UpdateResult.ERROR_WHEN_UPDATED;
            }
            return(result);
        }
        public async Task <SurveyModel> Handle(CreateSurveyCommand request, CancellationToken cancellationToken)
        {
            var survey = new Survey(request.SurveyTopic, request.NumberOfRespondents, request.RespondentType);

            foreach (var option in request.SurveyOptions)
            {
                if (option.PreferredNumberOfVotes.HasValue)
                {
                    survey.AddSurveyOption(option.OptionText, option.PreferredNumberOfVotes.Value);
                }
                else
                {
                    survey.AddSurveyOption(option.OptionText);
                }
            }

            IVoteDistribution voteDistribution;

            if (request.SurveyOptions.Any(option => option.PreferredNumberOfVotes > 0))
            {
                voteDistribution = new FixedVoteDistribution();
            }
            else
            {
                voteDistribution = new RandomVoteDistribution();
            }

            var result = survey.CalculateOutcome(voteDistribution);

            _surveyRepository.Add(result);

            await _surveyRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

            return(_mapper.Map <SurveyModel>(result));
        }
Ejemplo n.º 3
0
        public bool Save(Survey element)
        {
            if (element.Id == 0)
            {
                var surveyTemplate = _surveyTemplateRepo.GetById(element.SurveyTemplateId);
                var customer       = _customerRepo.Find(element.CustomerId);
                foreach (var sectionGroup in surveyTemplate.SectionGroup)
                {
                    var address = new Address()
                    {
                        Recipient = customer.Name, AddressLine1 = customer.Address
                    };
                    var answergroup = new AnswerGroup()
                    {
                        SectionGroupId = sectionGroup.Id,
                        SurveyId       = element.Id,
                        IsUsed         = sectionGroup.IsMandatory ? true : false,
                        Address        = address,
                    };

                    if (answergroup.IsUsed)
                    {
                        foreach (var section in sectionGroup.Section.OrderBy(item => item.SortOrder))
                        {
                            var answerSection = new AnswerSection()
                            {
                                SectionId = section.Id,
                                Order     = element.AnswerGroup.Count + 1
                            };

                            foreach (var question in section.Question.OrderBy(item => item.SortOrder))
                            {
                                var answer = new Answer()
                                {
                                    OptionId      = null,
                                    InHighlighted = false,
                                    IsFinal       = false,
                                    IsValid       = false,
                                    QuestionId    = question.Id,
                                    OptionGroupId = question.OptionGroupId
                                };
                                answerSection.Answer.Add(answer);
                            }
                            answergroup.AnswerSection.Add(answerSection);
                        }
                    }
                    element.AnswerGroup.Add(answergroup);
                }

                element = _surveyRepo.Add(element);
            }
            else
            {
                element = _surveyRepo.Update(element);
            }

            return(true);
        }
Ejemplo n.º 4
0
        public void Handle(AddSurveyCommand message)
        {
            var survey = message.surveyToAdd;

            if (survey == null || !SurveyVallid(survey))
            {
                bus.Reply(new NotValidMessage("Survey Not Valid"));
            }
            else
            {
                repository.Add(message.surveyToAdd);
            }
        }
        public void InsertData()
        {
            const long surveyId = 1;

            if (_surveyRepository.Exists(surveyId))
            {
                return;
            }
            //To Do
            var create = _surveyDesignFactory.Invoke(surveyId: surveyId, useDatabaseIds: true);
            var survey = create.Survey("Simple Survey", "f6e021af-a6a0-4039-83f4-152595b4671a");

            _surveyRepository.Add(survey);
            _surveyContextProvider.Get().SaveChanges();
        }
        public Survey CreateSurvey(SurveyViewModel surveyModel)
        {
            using (var unitOfWork = _unitOfWorkFactory.Create())
            {
                var userId        = Guid.NewGuid().ToString();
                var surveyFactory = _surveyDesignFactory.Invoke(useDatabaseIds: true);
                var survey        = surveyFactory.Survey(surveyModel.Name, userId);

                _surveyRepository.Add(survey);
                unitOfWork.SavePoint();

                unitOfWork.Commit();
                return(survey);
            }
        }
Ejemplo n.º 7
0
        public int AddSurvey([FromBody] SurveyModel survey)
        {
            Survey sur = new Survey
            {
                Title          = survey.Title,
                Description    = survey.Description,
                Code           = GenerateCode(),
                OrganisationID = survey.OrganisationID,
                StartDate      = CheckStartDate(survey.StartDate),
                EndDate        = CheckEndDate(survey.EndDate)
            };
            var surveyid = _sr.Add(sur);

            return(surveyid.ID);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Add(CreateSurveyViewModel model)
        {
            if (ModelState.IsValid)
            {
                Survey survey = new Survey();
                User   user   = await userManager.FindByNameAsync(model.Username);

                survey.UserId    = user.Id;
                survey.Username  = User.Identity.Name;
                survey.Company   = dbContext.Companies.Where(c => c.Title == model.CompanyName).FirstOrDefault();
                survey.CompanyId = dbContext.Companies.Where(c => c.Title == model.CompanyName).FirstOrDefault().Id;
                survey.Content   = model.Content;

                dbContext.SaveChanges();
                surveyRepository.Add(survey);

                return(RedirectToAction("Details", "Survey", new { id = survey.Id }));
            }

            return(View(model));
        }
Ejemplo n.º 9
0
        public int Add(Survey item)
        {
            if (item == null)
            {
                return(0);
            }

            if (string.IsNullOrEmpty(item.Title) || string.IsNullOrEmpty(item.Description))
            {
                return(0);
            }

            if (item.Title.Count() > 200 || item.Description.Count() > 500)
            {
                return(0);
            }

            int id = _repository.Add(item);

            return(id);
        }
Ejemplo n.º 10
0
 public async Task Add(Survey survey)
 {
     await repository.Add(survey);
 }