コード例 #1
0
        public ActionResult Edit(Guid id, MetadataEntityModel model, string button)
        {
            using (DBEntities context = Settings.CreateDataContext())
            {
                Validate(context, model);

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

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

                Mapper.CreateMap <MetadataEntityModel, MetadataEntity>().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 }));
                }
            }
        }
コード例 #2
0
        public ActionResult Edit(Guid?id)
        {
            if (id.HasValue)
            {
                MetadataEntity obj = MetadataEntityHelper.Get(id.Value);
                if (obj == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                Mapper.CreateMap <MetadataEntity, MetadataEntityModel>();
                MetadataEntityModel model = Mapper.Map <MetadataEntity, MetadataEntityModel>(obj);
                return(View(model));
            }
            else
            {
                return(View(new MetadataEntityModel
                {
                    SchemaName = "dbo"
                }));
            }
        }
コード例 #3
0
 private void Validate(DBEntities context, MetadataEntityModel model)
 {
     //string res = MetadataEntityValidator.CheckTableName(context, model.Id, model.TableName);
     //if (res.Length > 0)
     //    ModelState.AddModelError("TableName", res);
 }