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

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

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

                Mapper.CreateMap <FormBlockTemplateModel, MetaFormBlockTemplate>().ForMember("Id", f => f.Ignore());
                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 }));
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult GetTemplateParam(Guid id)
        {
            string result = string.Empty;
            MetaFormBlockTemplate item = MetaFormBlockTemplateHelper.Get(id);

            if (item != null)
            {
                result = item.Params;
            }
            return(Json(result));
        }
        public ActionResult Edit(Guid id, FormBlockTemplateModel model, string button)
        {
            using (DBEntities context = Settings.CreateDataContext())
            {
                Validate(context, model);

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

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

                Mapper.CreateMap<FormBlockTemplateModel, MetaFormBlockTemplate>().ForMember("Id", f => f.Ignore());
                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});
            }
        }
Exemplo n.º 4
0
        public ActionResult Edit(Guid?id)
        {
            if (id.HasValue)
            {
                MetaFormBlockTemplate obj = MetaFormBlockTemplateHelper.Get(id.Value);
                if (obj == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                Mapper.CreateMap <MetaFormBlockTemplate, FormBlockTemplateModel>();
                FormBlockTemplateModel model = Mapper.Map <MetaFormBlockTemplate, FormBlockTemplateModel>(obj);
                return(View(model));
            }
            else
            {
                return(View(new FormBlockTemplateModel()));
            }
        }