Ejemplo n.º 1
0
        public JsonResult SaveQuestionResponse(JsonResponse response)
        {
            var query         = new QuestionnaireById(response.QuestionnaireId);
            var questionnaire = _repository.Find(query);

            var questionQuery  = new QuestionById(response.QuestionId);
            var questionResult = _repository.Find(questionQuery);

            Response item;

            if (questionResult.IsTextBased)
            {
                item = questionnaire.Responses
                       .SingleOrDefault(
                    x =>
                    x.QuestionId == response.QuestionId &&
                    x.QuestionnaireId == response.QuestionnaireId);
            }
            else
            {
                item = questionnaire.Responses
                       .SingleOrDefault(
                    x =>
                    x.QuestionId == response.QuestionId &&
                    x.QuestionnaireId == response.QuestionnaireId && x.Value == response.Value);
            }

            if (item == null)
            {
                item = new Response {
                    Created = DateTime.Now, CreatedBy = User.Identity.Name.ToUpper()
                };
            }

            item.QuestionnaireId = response.QuestionnaireId;
            item.QuestionId      = response.QuestionId;
            item.Comment         = response.Comment;

            item.ModifiedBy = User.Identity.Name.ToUpper();
            item.Modified   = DateTime.Now;
            item.Value      = response.Value;
            item.IsSelected = response.IsSelected;

            if (item.ResponseId == 0)
            {
                _repository.Context.Add(item);
            }
            else
            {
                _repository.Context.Update(item);
            }

            _repository.Context.Commit();


            return(Json("Success"));
        }
Ejemplo n.º 2
0
        public JsonResult SaveQuestionResponses(JsonQuestionResponse question)
        {
            var query = new QuestionnaireById(question.QuestionnaireId);
            var questionnaire = _repository.Find(query);

            var questionQuery = new QuestionById(question.QuestionId);
            var questionResult = _repository.Find(questionQuery);

            foreach (var item in question.Responses)
            {
                Response response;

                if (questionResult.IsTextBased)
                {
                    response = questionnaire.Responses
                        .SingleOrDefault(x => x.QuestionId == item.QuestionId && x.QuestionnaireId == item.QuestionnaireId);
                }
                else
                {
                    response = questionnaire.Responses
                        .SingleOrDefault(x => x.QuestionId == item.QuestionId && x.QuestionnaireId == item.QuestionnaireId && x.Value == item.Value);
                }

                if (response == null)
                {
                    response = new Response
                    {
                        QuestionnaireId = question.QuestionnaireId,
                        QuestionId = question.QuestionId,
                        Comment = item.Comment,
                        Created = DateTime.Now,
                        CreatedBy = User.Identity.Name.ToUpper(),
                        ModifiedBy = User.Identity.Name.ToUpper(),
                        Modified = DateTime.Now,
                        Value = item.Value,
                        IsSelected = item.IsSelected
                    };

                    _repository.Context.Add(response);
                }
                else
                {
                    var originalIsSelected = response.IsSelected;
                    var originalValue = response.Value;

                    response.ModifiedBy = User.Identity.Name;
                    response.Modified = DateTime.Now;
                    response.Value = item.Value;
                    response.IsSelected = item.IsSelected;
                    response.Comment = item.Comment;

                    _repository.Context.Update(response);

                    if (originalIsSelected != item.IsSelected || originalValue != item.Value)
                    {
                        var responseAudit = new ResponseAudit
                                            {
                                                ResponseId = response.ResponseId,
                                                Response = response,
                                                OldIsSelectedValue = originalIsSelected,
                                                NewIsSelectedValue = item.IsSelected,
                                                OldResponseValue = originalValue,
                                                NewResponseValue = item.Value,
                                                Created = DateTime.Now,
                                                CreatedBy = User.Identity.Name.ToUpper()
                                            };
                        _repository.Context.Add(responseAudit);
                    }
                }

                _repository.Context.Commit();

            }

            return Json("Success");
        }
Ejemplo n.º 3
0
        public JsonResult SaveQuestionResponse(JsonResponse response)
        {
            var query = new QuestionnaireById(response.QuestionnaireId);
            var questionnaire = _repository.Find(query);

            var questionQuery = new QuestionById(response.QuestionId);
            var questionResult = _repository.Find(questionQuery);

            Response item;

            if (questionResult.IsTextBased)
            {
                item = questionnaire.Responses
                                    .SingleOrDefault(
                                        x =>
                                        x.QuestionId == response.QuestionId &&
                                        x.QuestionnaireId == response.QuestionnaireId);
            }
            else
            {
                item = questionnaire.Responses
                                    .SingleOrDefault(
                                        x =>
                                        x.QuestionId == response.QuestionId &&
                                        x.QuestionnaireId == response.QuestionnaireId && x.Value == response.Value);
            }

            if (item == null)
            {
                item = new Response {Created = DateTime.Now, CreatedBy = User.Identity.Name.ToUpper()};
            }

            item.QuestionnaireId = response.QuestionnaireId;
            item.QuestionId = response.QuestionId;
            item.Comment = response.Comment;

            item.ModifiedBy = User.Identity.Name.ToUpper();
            item.Modified = DateTime.Now;
            item.Value = response.Value;
            item.IsSelected = response.IsSelected;

            if (item.ResponseId == 0)
                _repository.Context.Add(item);
            else
                _repository.Context.Update(item);

            _repository.Context.Commit();

            return Json("Success");
        }
Ejemplo n.º 4
0
        public JsonResult SaveQuestionResponses(JsonQuestionResponse question)
        {
            var query         = new QuestionnaireById(question.QuestionnaireId);
            var questionnaire = _repository.Find(query);

            var questionQuery  = new QuestionById(question.QuestionId);
            var questionResult = _repository.Find(questionQuery);

            foreach (var item in question.Responses)
            {
                Response response;

                if (questionResult.IsTextBased)
                {
                    response = questionnaire.Responses
                               .SingleOrDefault(x => x.QuestionId == item.QuestionId && x.QuestionnaireId == item.QuestionnaireId);
                }
                else
                {
                    response = questionnaire.Responses
                               .SingleOrDefault(x => x.QuestionId == item.QuestionId && x.QuestionnaireId == item.QuestionnaireId && x.Value == item.Value);
                }

                if (response == null)
                {
                    response = new Response
                    {
                        QuestionnaireId = question.QuestionnaireId,
                        QuestionId      = question.QuestionId,
                        Comment         = item.Comment,
                        Created         = DateTime.Now,
                        CreatedBy       = User.Identity.Name.ToUpper(),
                        ModifiedBy      = User.Identity.Name.ToUpper(),
                        Modified        = DateTime.Now,
                        Value           = item.Value,
                        IsSelected      = item.IsSelected
                    };

                    _repository.Context.Add(response);
                }
                else
                {
                    var originalIsSelected = response.IsSelected;
                    var originalValue      = response.Value;

                    response.ModifiedBy = User.Identity.Name;
                    response.Modified   = DateTime.Now;
                    response.Value      = item.Value;
                    response.IsSelected = item.IsSelected;
                    response.Comment    = item.Comment;

                    _repository.Context.Update(response);

                    if (originalIsSelected != item.IsSelected || originalValue != item.Value)
                    {
                        var responseAudit = new ResponseAudit
                        {
                            ResponseId         = response.ResponseId,
                            Response           = response,
                            OldIsSelectedValue = originalIsSelected,
                            NewIsSelectedValue = item.IsSelected,
                            OldResponseValue   = originalValue,
                            NewResponseValue   = item.Value,
                            Created            = DateTime.Now,
                            CreatedBy          = User.Identity.Name.ToUpper()
                        };
                        _repository.Context.Add(responseAudit);
                    }
                }

                _repository.Context.Commit();
            }

            return(Json("Success"));
        }