Ejemplo n.º 1
0
        public IActionResult CreateForm(FormManager vm)
        {
            try
            {
                var entity = new Form(vm.Form.Name, vm.Form.Code);

                var attrs = vm.Attributes.Select(x => new FormAttribute(
                                                     entity, x.Name, x.ComponentType, x.Title, x.Value,
                                                     x.Info, x.Detail, x.IsNumeric, x.Order, x.Repeat
                                                     )).ToList();

                SetMessage(Messenger.Created(formRepo.Create(entity)), MsgType.Success);

                formAttRepo.CreateRange(attrs);

                if (vm.Tabulations.Any())
                {
                    vm.Tabulations.ForEach(x => { formManager.Register(entity.Id, x); });
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                SetMessage(e.Message, MsgType.Error); return(RedirectToAction("Index"));
            }
        }