Пример #1
0
        public ActionResult Copy(HomeCopyViewModel model)
        {
            var sourceQuestionniareQuery = new QuestionnaireById(model.SourceQuestionnaireId);
            var source = _repository.Find(sourceQuestionniareQuery);

            var targetQuestionniareQuery = new QuestionnaireById(model.TargetQuestionId);
            var target = _repository.Find(targetQuestionniareQuery);

            target.Status = QuestionnaireStatus.InProgress;

            while (target.Responses.Count > 0)
            {
                var response = target.Responses.FirstOrDefault();

                while (response != null && response.ResponseAudits.Count > 0)
                {
                    var responseAudit = response.ResponseAudits.FirstOrDefault();
                    _repository.Context.Remove(responseAudit);
                }
                _repository.Context.Remove(response);
            }

            _repository.Context.Update(target);
            _repository.Context.Commit();

            foreach (var response in source.Responses)
            {
                target.Responses.Add(new Response
                                     {
                                         Questionnaire = target,
                                         QuestionnaireId = target.QuestionnaireId,
                                         Comment = response.Comment,
                                         IsSelected = response.IsSelected,
                                         Value = response.Value,
                                         Created = DateTime.Now,
                                         CreatedBy = User.Identity.Name.ToUpper(),
                                         Modified = DateTime.Now,
                                         ModifiedBy = User.Identity.Name.ToUpper(),
                                         Question = response.Question,
                                         QuestionId = response.QuestionId
                                     });
            }

            _repository.Context.Update(target);
            _repository.Context.Commit();

            TempData["Message"] = "Results successfully copied!";

            return RedirectToAction("Index");
        }
Пример #2
0
        public ActionResult Copy(int id)
        {
            var model = new HomeCopyViewModel();

            var sourceQuestionnaireQuery = new QuestionnaireById(id);
            var sourceQuestionnaire = _repository.Find(sourceQuestionnaireQuery);
            model.SourceQuestionnaire = sourceQuestionnaire;
            model.SourceQuestionnaireId = sourceQuestionnaire.QuestionnaireId;

            var availableQuestionnaireQuery = new QuestionnaireByOwnerAndStatus(User.Identity.Name, QuestionnaireStatus.Complete);
            var availableQuestionnaires = _repository.Find(availableQuestionnaireQuery).AsEnumerable();
            model.AvailableQuestionnaires = ToQuestionniareSelectList(availableQuestionnaires);

            return View(model);
        }