Example #1
0
 public IActionResult CreateEntity(CreateEntityModel model)
 {
     if (ModelState.IsValid)
     {
         model.Name = model.Name.Trim();
         var entity = new Schema.Domain.Entity();
         model.CopyTo(entity);
         entity.EntityId       = Guid.NewGuid();
         entity.IsCustomizable = true;
         entity.CreatedBy      = CurrentUser.SystemUserId;
         entity.OrganizationId = CurrentUser.OrganizationId;
         if (model.EntityGroupId.NotEmpty())
         {
             entity.EntityGroups = model.EntityGroupId.SerializeToJson();
         }
         if (_entityCreater.Create(entity, model.DefaultAttributes))
         {
             //创建默认按钮
             if (model.DefaultButtons.NotEmpty())
             {
                 _eventPublisher.Publish(new CreateDefaultButtonsEvent(entity, model.DefaultButtons));
             }
             //创建默认表单
             if (model.CreateDefaultForm)
             {
                 _eventPublisher.Publish(new CreateDefaultFormEvent(entity));
             }
             //创建默认视图
             if (model.CreateDefaultView)
             {
                 _eventPublisher.Publish(new CreateDefaultViewEvent(entity));
             }
             return(CreateSuccess(new { id = entity.EntityId }));
         }
         return(CreateFailure());
     }
     return(CreateFailure(GetModelErrors()));
 }
Example #2
0
        public IActionResult Post(CreateEntityModel model)
        {
            if (ModelState.IsValid)
            {
                if (_entityFinder.FindByName(model.Name) != null)
                {
                    return(JError(T["name_already_exists"]));
                }
                model.Name = model.Name.Trim();
                var entity = new Schema.Domain.Entity();
                model.CopyTo(entity);
                entity.SolutionId     = _solutionId.Value;
                entity.IsCustomizable = true;
                entity.EntityId       = Guid.NewGuid();
                entity.CreatedBy      = CurrentUser.SystemUserId;
                entity.CreatedOn      = DateTime.Now;
                entity.OrganizationId = CurrentUser.OrganizationId;
                _entityCreater.Create(entity);

                return(CreateSuccess(new { id = entity.EntityId }));
            }
            return(CreateFailure(GetModelErrors()));
        }