示例#1
0
        public ActionResult EditBlock(Guid?id, Guid?FormId, MetaFormBlockModel model, string button)
        {
            if (string.IsNullOrEmpty(button))
            {
                return(View(model));
            }

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

            using (DBEntities context = Settings.CreateDataContext())
            {
                MetaFormBlock target = null;
                if (model.Id != Guid.Empty)
                {
                    target = MetaFormHelper.GetBlock(model.Id, context);
                    if (target == null)
                    {
                        ModelState.AddModelError("", Resources.Resource.RowNotFound);
                        return(View(model));
                    }
                }
                else
                {
                    target    = new MetaFormBlock();
                    target.Id = model.Id = Guid.NewGuid();
                    context.AddToMetaFormBlock(target);
                }

                MetaFormBlockModel.CreateMap();
                target = Mapper.Map(model, target);

                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", Resources.Resource.SaveError + ": " + ex.Message);
                }
            }

            if (button == "SaveAndExit")
            {
                return(RedirectToAction("Edit", new { id = model.MetaFormId }));
            }
            else
            {
                return(RedirectToAction("EditBlock", new { id = model.Id }));
            }
        }
示例#2
0
        public ActionResult EditBlock(Guid?id, Guid?FormId)
        {
            MetaFormBlockModel model = null;

            if (id.HasValue)
            {
                MetaFormBlock att = MetaFormHelper.GetBlock(id.Value);
                if (att == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                MetaFormBlockModel.CreateMap();
                model = Mapper.Map <MetaFormBlock, MetaFormBlockModel>(att);
                return(View(model));
            }
            else if (FormId.HasValue)
            {
                MetaForm item = MetaFormHelper.Get(FormId.Value);
                if (item != null)
                {
                    return(View(new MetaFormBlockModel
                    {
                        MetaFormId = item.Id,
                        MetaFormCaption = item.Caption,
                    }));
                }
                else
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }
            }
            else
            {
                return(MessageHelper.FormedContentObjectNotFound());
            }
        }