Exemplo n.º 1
0
        public ActionResult EditExternalMethod(Guid?id, Guid?ViewId, MetaViewExternalMethodModel model, string button)
        {
            if (string.IsNullOrEmpty(button))
            {
                return(View(model));
            }

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

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

                MetaViewExternalMethodModel.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.MetaViewId }));
            }
            else
            {
                return(RedirectToAction("EditExternalMethod", new { id = model.Id }));
            }
        }
Exemplo n.º 2
0
        public ActionResult EditExternalMethod(Guid?id, Guid?ViewId)
        {
            MetaViewExternalMethodModel model = null;

            if (id.HasValue)
            {
                var att = MetaViewHelper.GetExternalMethod(id.Value);
                if (att == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                MetaViewExternalMethodModel.CreateMap();
                model = Mapper.Map <MetaViewExternalMethod, MetaViewExternalMethodModel>(att);
                return(View(model));
            }
            else if (ViewId.HasValue)
            {
                MetaView item = MetaViewHelper.Get(ViewId.Value);
                if (item != null)
                {
                    return(View(new MetaViewExternalMethodModel
                    {
                        MetaViewId = item.Id,
                        MetaViewCaption = item.Caption,
                    }));
                }
                else
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }
            }
            else
            {
                return(MessageHelper.FormedContentObjectNotFound());
            }
        }