예제 #1
0
        public async Task <IActionResult> Edit(CreateSurveyModel model, int surveyId)
        {
            if (ModelState.IsValid)
            {
                //var surveyItem = await _repository.GetAsync(surveyId);
                var dateTime   = DateTime.UtcNow;
                var dateOffset = dateTime.AddMinutes(model.NeedToBeFinishedFor.TotalMinutes);
                await _repository.Update(new Survey
                {
                    Id                       = surveyId,
                    Title                    = model.Title,
                    Text                     = model.Text,
                    Limit                    = model.Limit,
                    CreatedAt                = model.CreatedAt,
                    NeedToBeFinishedFor      = dateOffset,
                    NeedToBeFinishedForStart = dateTime,
                    Score                    = model.Score,
                    IsActive                 = model.IsActive,
                    NumberOfUser             = model.NumberOfUser
                });

                return(RedirectToAction("Index", "Survey"));
            }

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Create(CreateSurveyModel model)
        {
            var id = 0;

            if (ModelState.IsValid)
            {
                var dateTime   = DateTime.UtcNow;
                var dateOffset = dateTime.AddMinutes(model.NeedToBeFinishedFor.TotalMinutes);
                id = await _repository.AddAsync(new Survey
                {
                    Title                    = model.Title,
                    Text                     = model.Text,
                    CreatedAt                = dateTime,
                    Limit                    = model.Limit,
                    NeedToBeFinishedFor      = dateOffset,
                    NeedToBeFinishedForStart = dateTime,
                    Score                    = model.Score,
                    IsActive                 = false
                });


                return(RedirectToAction("CreateAdditionalInfo", "Survey", new { surveyId = id }));
            }


            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int surveyId)
        {
            var survey = await _repository.GetAsync(surveyId);

            var createQuestions = new List <CreateQuestionModel>();

            survey.Survey.Questionary.ToList().ForEach(
                arr => createQuestions.Add(new CreateQuestionModel
            {
                Id          = arr.Id,
                Question    = arr.Question,
                RightAnswer = arr.RightAnswer,
                SurveyId    = surveyId
            })
                );
            var offset            = survey.Survey.NeedToBeFinishedFor - survey.Survey.NeedToBeFinishedForStart;
            var createSurveyModel = new CreateSurveyModel
            {
                Limit = survey.Survey.Limit,
                Id    = survey.Survey.Id,
                Title = survey.Survey.Title,
                Text  = survey.Survey.Text,
                NeedToBeFinishedFor = offset,
                CreatedAt           = survey.Survey.CreatedAt.LocalDateTime,
                Score            = survey.Survey.Score,
                Questionaries    = createQuestions,
                AdditionalInfoId = survey.Survey.AdditionalInfo?.Id,
                NumberOfUser     = survey.Survey.NumberOfUser,
                IsActive         = survey.Survey.IsActive
            };

            return(View(createSurveyModel));
        }
예제 #4
0
        public async Task <IActionResult> Delete(CreateSurveyModel model)
        {
            if (ModelState.IsValid)
            {
                await _repository.AddAsync(new Survey
                {
                    Title     = model.Title,
                    Text      = model.Text,
                    CreatedAt = DateTime.UtcNow
                });

                return(RedirectToAction("Index", "Survey"));
            }

            return(View(model));
        }
예제 #5
0
 public IEnumerable <CreateSurveyModel> Post([FromBody] CreateSurveyModel survery)
 {
     _surveryStorage.Survey.Add(survery);
     //return CreatedAtAction("Payment Added, ID = ", new { id = paymentModel.PaymentId });
     return(_surveryStorage.Survey);
 }
 public Task <Result <Guid> > Add(CreateSurveyModel model)
 => _surveyBiz.Add(model);
        public Task <Result <Guid> > Add(CreateSurveyModel model)
        => Result <Guid> .TryAsync(async() =>
        {
            var isAdmin = generalDataService.User.Permissions.Any(p => p == (int)PermissionType.Admin);
            if (!isAdmin)
            {
                return(Result <Guid> .Failed(Error.WithData(1000, new [] { "not admin" })));
            }
            var validationCheckbox = true;
            var survey             = new Survey
            {
                Id           = Guid.NewGuid(),
                Name         = model.Name,
                Description  = model.Description,
                CreatedBy    = generalDataService.User.Id,
                CreationDate = DateTime.Now,
                ModifiedDate = DateTime.Now,
                Enabled      = model.Enabled.Value,
                Question     = model.Questions.Select(q =>
                {
                    if (q.Answers.Any(a => a.Type == AnswerType.Checkbox) && q.MustAnsweredNumber != null &&
                        q.MustAnsweredNumber.Any())
                    {
                        validationCheckbox = false;
                    }
                    return(new Question
                    {
                        Id = Guid.NewGuid(),
                        Text = q.Text,
                        ModifiedDate = DateTime.Now,
                        Number = q.Number,
                        Answer = q.Answers.Select(a => new Answer
                        {
                            Id = Guid.NewGuid(),
                            Text = a.Text,
                            ModifiedDate = DateTime.Now,
                            Type = (byte)a.Type,
                            Number = a.Number,
                            Action = a.Actions?.Select(action => new DataAccess.EFModels.Action
                            {
                                Id = Guid.NewGuid(), Type = (byte)action.Type, Value = action.Value
                            })
                                     .ToList(),
                        }).ToList()
                    });
                }).ToList()
            };

            if (!validationCheckbox)
            {
                return(Result <Guid> .Failed(Error.WithData(1000, new [] { "must answer questions cant have checkbox answers" })));
            }
            survey.Question?.ToList().ForEach(question =>
            {
                var mustAnsweredNumber = model.Questions?.FirstOrDefault(q => q.Number == question.Number)?
                                         .MustAnsweredNumber;

                question.MustAnswered = survey.Question.SelectMany(q => q.Answer)
                                        .Where(a => mustAnsweredNumber != null && mustAnsweredNumber.Contains(a.Number)).Select(ma =>
                                                                                                                                new MustAnswered
                {
                    Id = Guid.NewGuid(), AnswerId = ma.Id, QuestionId = question.Id
                }).ToList();
            });
            _repository.Add(survey);
            await _repository.CommitAsync();

            return(Result <Guid> .Successful(survey.Id));
        });