Пример #1
0
        public ActionResult EditAttribute(Guid?id, Guid?EntityId, byte?TypeId)
        {
            MetadataEntityAttributeModel model = null;

            if (id.HasValue)
            {
                MetadataEntityAttribute att = MetadataEntityHelper.GetAttribute(id.Value);
                if (att == null)
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }

                MetadataEntityAttributeModel.CreateMap();
                model = Mapper.Map <MetadataEntityAttribute, MetadataEntityAttributeModel>(att);
                return(View(model));
            }
            else if (EntityId.HasValue)
            {
                MetadataEntity item = MetadataEntityHelper.Get(EntityId.Value);
                if (item != null)
                {
                    if (!TypeId.HasValue)
                    {
                        TypeId = 0;
                    }

                    MetadataEntityAttributeType type =
                        MetadataEntityHelper.CurrentTypeList.FirstOrDefault(c => c.Id == TypeId.Value) ??
                        new MetadataEntityAttributeType
                    {
                        Id   = 255,
                        Name = "Не определена"
                    };
                    return(View(new MetadataEntityAttributeModel
                    {
                        EntityId = item.Id,
                        EntityCaption = item.Caption,
                        TypeId = type.Id,
                        //AttributeTypeName = type.Name
                    }));
                }
                else
                {
                    return(MessageHelper.FormedContentObjectNotFound());
                }
            }
            else
            {
                return(MessageHelper.FormedContentObjectNotFound());
            }
        }
Пример #2
0
        public ActionResult EditAttribute(Guid?id, Guid?EntityId, MetadataEntityAttributeModel model, string button)
        {
            if (string.IsNullOrEmpty(button))
            {
                return(View(model));
            }


            Validate(model);

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

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

                MetadataEntityAttributeModel.CreateMap();
                target = Mapper.Map(model, target);
                // UpdateExtention(model, target, context);

                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    string errorMsg;
                    if (ex.InnerException != null)
                    {
                        errorMsg = string.Format("{0} {1}", ex.Message, ex.InnerException.Message);
                    }
                    else
                    {
                        errorMsg = ex.Message;
                    }

                    ModelState.AddModelError("", Resources.Resource.SaveError + ": " + errorMsg);
                    return(View(model));
                }
            }

            if (button == "SaveAndExit")
            {
                return(RedirectToAction("Edit", new { id = model.EntityId }));
            }
            else
            {
                return(RedirectToAction("EditAttribute", new { id = model.Id }));
            }
        }
Пример #3
0
        public ActionResult EditAttribute(Guid? id, Guid? EntityId, MetadataEntityAttributeModel model, string button)
        {
            if (string.IsNullOrEmpty(button))
                return View(model);

            Validate(model);

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

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

                MetadataEntityAttributeModel.CreateMap();
                target = Mapper.Map(model, target);
               // UpdateExtention(model, target, context);

                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    string errorMsg;
                    if (ex.InnerException != null)
                        errorMsg = string.Format("{0} {1}", ex.Message, ex.InnerException.Message);
                    else
                        errorMsg = ex.Message;

                    ModelState.AddModelError("", Resources.Resource.SaveError + ": " + errorMsg);
                    return View(model);
                }
            }

            if (button == "SaveAndExit")
                return RedirectToAction("Edit", new {id = model.EntityId});
            else
            {
                return RedirectToAction("EditAttribute", new {id = model.Id});
            }
        }