コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FormContent")] FormJson formJson)
        {
            if (id != formJson.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(formJson);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FormJsonExists(formJson.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(formJson));
        }
コード例 #2
0
        /// <summary>
        /// Get json form.
        /// </summary>
        /// <param name="id">Form id.</param>
        /// <returns>Json form.</returns>
        public FormJson Get(int id)
        {
            var form = this.db.Form.GetById(id);

            if (form == null)
            {
                return(null);
            }

            FormJson formJson = new FormJson()
            {
                FormId = form.FormId, FormTitle = form.FormTitle, Description = form.Description
            };

            foreach (var item in this.db.Field.GetFields(form.FormId))
            {
                formJson.Fields.Add(new FieldJson()
                {
                    FieldId = item.FieldId, FieldTitle = item.FieldTitle, Type = item.Type, Question = item.Question, Required = item.Required
                });
            }

            var ip = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.GetValue(1).ToString();

            this.db.AuditInfo.Create(new AuditInfo()
            {
                ClientIp = ip, FormId = id, Time = DateTime.Now
            });

            return(formJson);
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,FormContent")] FormJson formJson)
        {
            if (ModelState.IsValid)
            {
                _context.Add(formJson);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(formJson));
        }
コード例 #4
0
        public void should_Read_Form_Json()
        {
            var forms = new FormJson().Read();

            Assert.IsTrue(forms.Count > 0);

            foreach (var form in forms)
            {
                Console.WriteLine(form);
            }
        }
コード例 #5
0
        public async Task <IActionResult> SaveFormDetails([Bind("Id,FormContent")] FormJson formDetails)
        {
            FormDetails obj = new FormDetails();

            obj.Id = formDetails.Id;
            obj.FromDetailsEntered = formDetails.FormContent;
            if (ModelState.IsValid)
            {
                _context.Add(obj);
                await _context.SaveChangesAsync();

                return(View(obj));
            }
            return(View(obj));
        }