Esempio n. 1
0
        public ActionResult Edit(Guid id, MetaFormModel model, string button)
        {
            using (DBEntities context = Settings.CreateDataContext())
            {
                Validate(context, model);

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                MetaForm target = null;
                if (model.Id != Guid.Empty)
                {
                    target = MetaFormHelper.Get(model.Id, context);
                    if (target == null)
                    {
                        ModelState.AddModelError("", Resources.Resource.RowNotFound);
                        return(View(model));
                    }
                }
                else
                {
                    target    = new MetaForm();
                    target.Id = Guid.NewGuid();
                    context.AddToMetaForm(target);
                }

                MetaFormModel.CreateMap();
                Mapper.Map(model, target);

                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    var sb = new StringBuilder(Resources.Resource.SaveError + ": " + ex.Message);
                    if (ex.InnerException != null)
                    {
                        sb.AppendLine(ex.InnerException.Message);
                    }
                    ModelState.AddModelError("", sb.ToString());
                    return(View(model));
                }

                if (button == "SaveAndExit")
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Edit", new { target.Id }));
                }
            }
        }
Esempio n. 2
0
        private void SetShowImportExportOptions(MetaFormModel form)
        {
            var model = FormModelRepository.GetFormModel(form.Id, FormModelType.All);

            if (model.IsEmpty || string.IsNullOrEmpty(model.MainViewName))
            {
                return;
            }

            var viewNames = model.Blocks.Select(b => b.ViewName).Distinct().ToList();

            using (var context = Settings.CreateDataContext())
            {
                var containsForbidden = context.MetaView.Any(mv => !mv.MasterEntity.IsAvailableForImportExport && viewNames.Contains(mv.Name));

                form.ShowImportExportOptions = !containsForbidden;
            }
        }
Esempio n. 3
0
        public ActionResult Edit(Guid?id)
        {
            if (id.HasValue)
            {
                MetaForm obj = MetaFormHelper.Get(id.Value);
                if (obj == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                MetaFormModel.CreateMap();
                MetaFormModel model = Mapper.Map <MetaForm, MetaFormModel>(obj);


                //SetShowImportExportOptions(model);
                model.ShowImportExportOptions = true;
                return(View(model));
            }
            else
            {
                return(View(new MetaFormModel()));
            }
        }
Esempio n. 4
0
 private void Validate(DBEntities context, MetaFormModel model)
 {
     //string res = MetaFormValidator.CheckTableName(context, model.Id, model.TableName);
     //if (res.Length > 0)
     //    ModelState.AddModelError("TableName", res);
 }