Ejemplo n.º 1
0
        public async Task <IActionResult> PutColumn(int id, Column column)
        {
            if (id != column.Id)
            {
                return(BadRequest());
            }

            _context.Entry(column).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ColumnExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutFormDataItems(string id, FormDataItems formDataItems)
        {
            if (id != formDataItems.user_id)
            {
                return(BadRequest());
            }

            _context.Entry(formDataItems).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FormDataItemsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public int save(FormViewModel form)
        {
            var formEntity = new Form {
                Name = form.Name, FormId = form.FormId
            };

            using (var db = new FormContext())
            {
                db.Entry(formEntity).State = formEntity.FormId == 0 ?
                                             EntityState.Added :
                                             EntityState.Modified;
                db.SaveChanges();
            }
            var questions = form.Questions != null?form.Questions.Select(q => new Question
            {
                FormId     = formEntity.FormId,
                QuestionId = q.QuestionId,
                Order      = q.Order,
                Type       = q.Type,
                Name       = q.Name,
                Label      = q.Label,
                Options    = q.Options != null ? q.Options.Select(o => new Option {
                    QuestionId = q.QuestionId,
                    OptionId   = o.OptionId,
                    Label      = o.Label,
                    Value      = o.Label
                }).ToList() : new List <Option>()
            }).ToList() : new List <Question>();

            using (var db = new FormContext())
            {
                questions.ForEach(q => {
                    db.Entry(q).State = q.QuestionId == 0 ?
                                        EntityState.Added :
                                        EntityState.Modified;
                    q.Options.ToList().ForEach(o => db.Entry(o).State = o.OptionId == 0 ?
                                                                        EntityState.Added :
                                                                        EntityState.Modified);
                });
                db.SaveChanges();
            }

            return(formEntity.FormId);
        }