Ejemplo n.º 1
0
        protected void CreateAnswers(Guid itemId, string idcode, string text, string value)
        {
            var answer5 = _context.FormItemAnswers.FirstOrDefault(s => s.IdCode == idcode);
              if (answer5 == null)
              {
              answer5 = new DformItemAnswerEntity
                            {
                                Id = Guid.NewGuid(),

                            };
               _context.FormItemAnswers.Add(answer5);
              }
              answer5.Text = text;
              answer5.Value = value;
              answer5.FormItemId = itemId;
              answer5.IdCode = idcode;
              _context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void SaveFormItemAnswers(DformItemAnswerEntity entity)
        {
            var answer5 = _context.FormItemAnswers.FirstOrDefault(s => s.Id == entity.Id);
            if (answer5 == null)
            {
                answer5 = new DformItemAnswerEntity
                {
                    Id = Guid.NewGuid(),

                };
                _context.FormItemAnswers.Add(answer5);
            }
            answer5.Text = entity.Text;
            answer5.Value = entity.Value;
            answer5.FormItemId = entity.FormItemId;
            answer5.IdCode = entity.Value;
            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public BasicResponse Save(FormItemDTO dto)
        {
            var response = new BasicResponse();
            try
            {
                var entity = new DformItemEntity()
                {

                    Id = dto.Id,
                    FormId = dto.FormId,
                    HelpText = dto.HelpText,
                    IdCode = "",
                    IsRequired = dto.IsRequired,
                    Label = dto.Label,
                    Section = dto.Section,
                    ValidationRegex = dto.ValidationRegex,
                    ValidationText = dto.ValidationText,
                    Order = dto.Order,
                    FormItemType = (DformItemType)dto.FormItemTypeId,

                };
                _formRepository.SaveFormItem(entity);
               // entity = _formRepository.QueryFormItem(new QueryFormItem {Id = entity.Id}).Result.FirstOrDefault();
                _formRepository.DeleteFormItemRespondent(entity.Id);
                foreach(var respondent in dto.RespondentTypes)
                {
                    var respondentItem = new DformItemRespondentTypeEntity
                                             {
                                                 Id = dto.Id,
                                                 FormItemId = entity.Id,
                                                 FormRespondentTypeId = respondent
                                             };
                    _formRepository.SaveFormItemRespondent(respondentItem);

                }
                _formRepository.DeleteFormItemAnswers(entity.Id);
                foreach (var ans in dto.PossibleOptions)
                {
                    var respondentItem = new DformItemAnswerEntity()
                    {
                        Id = dto.Id,
                       Text =ans.Text,
                       FormItemId = entity.Id,
                       Value = ans.Value,

                    };
                    _formRepository.SaveFormItemAnswers(respondentItem);

                }
                response.Status = true;
                response.Info = "Success";

            }

            catch (Exception ex)
            {
                response.Status = false;
                if (ex is DomainValidationException)
                {
                    var dex = ex as DomainValidationException;
                    response.Info = dex.FormatException();
                }
                else
                {
                    response.Status = false;
                    response.Info = ex.Message;
                }

            }
            return response;
        }