Exemplo n.º 1
0
 private void Validate(DBEntities context, MetaViewModel model)
 {
     if (model.MasterEntityId == Guid.Empty)
         ModelState.AddModelError("MasterEntityId", "Поле Модель обязательно для заполнения");
     //string res = MetaViewValidator.CheckTableName(context, model.Id, model.TableName);
     //if (res.Length > 0)
     //    ModelState.AddModelError("TableName", res);
 }
Exemplo n.º 2
0
 public static List<MetaViewColumnModel> GetColumnsForView(MetaViewModel model)
 {
     return GetColumnsForView(model.Id, model.MasterEntityId, null);
 }
Exemplo n.º 3
0
        public ActionResult Edit(Guid id, MetaViewModel model, List<MetaViewColumnModel> columns, string button)
        {
            using (DBEntities context = Settings.CreateDataContext())
            {
                Validate(context, model);

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

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

                MetaViewModel.CreateMap();

                Mapper.Map(model, target);
                if(columns != null)
                    SyncViewColumns(target, columns, context);

                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});
            }
        }