Пример #1
0
        /// <summary>
        /// Save inputs on form
        /// </summary>
        /// <param name="inputs">Input information on the form</param>
        public IHttpActionResult Post([FromBody] IEnumerable <InputModel> inputs)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Form form = new Form();

            inputs.ToList().ForEach(p =>// Yeni bir form oluşturulup inputları eklendi
            {
                string options = String.Empty;
                if (p.Options != null)
                {
                    options = String.Join(",", p.Options);
                }

                form.Inputs.Add(new Input// TODO: burada bir mapping işlemi yapılmalı
                {
                    FormId      = form.FormId,
                    Type        = p.Type,
                    Label       = p.Label,
                    Description = p.Description,
                    Required    = p.Required,
                    Placeholder = p.Placeholder,
                    Options     = options
                });
            });

            _formBuilderDbContext.Forms.Add(form);
            _formBuilderDbContext.SaveChanges();
            return(Ok());
        }
 public IActionResult Index(FormSubmit answer)
 {
     answer.CreatedDate = DateTime.Now;
     _dbContext.FormSubmits.Add(answer);
     _dbContext.SaveChanges();
     return(View());
 }
        /// <summary>
        /// Save form answers
        /// </summary>
        /// <param name="inputs">Responses to the completed form</param>
        public IHttpActionResult Post([FromBody] List <AnswerModel> userAnswers)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            List <Answer> answers = userAnswers.Select(p => new Answer
            {
                InputId    = p.InputId,
                UserAnswer = p.UserAnswer
            }).ToList();

            _formBuilderDbContext.Answers.AddRange(answers);
            _formBuilderDbContext.SaveChanges();
            return(Ok());
        }