Beispiel #1
0
 public bool Create(Infrastructure.Entitys.Role m)
 {
     return(Factory.GetDbContext((db) =>
     {
         return db.Insertable <Infrastructure.Entitys.Role>(new
         {
             m.RoleId,
             m.RoleName,
             m.RoleDescription,
             m.IsValid
         })
         .IgnoreColumns(true)
         .ExecuteCommand() > 0;
     }));
 }
Beispiel #2
0
        public Task <bool> Handle(Models.CommandModels.Role.CreateCommandModel request, CancellationToken cancellationToken)
        {
            if (!request.VerifyData())
            {
                // 错误信息收集
                NotifyValidationErrors(request);
                // 返回,结束当前线程
                return(Task.FromResult(false));
            }

            Infrastructure.Entitys.Role entity = new Infrastructure.Entitys.Role()
            {
                RoleId          = request.RoleId.ToString(),
                RoleName        = request.RoleName,
                RoleDescription = request.RoleDescription,
                IsValid         = request.IsValid
            };

            var existingEntity = _REPOSITORY.QueryByName(entity.RoleName);

            if (existingEntity != null && !string.IsNullOrWhiteSpace(existingEntity.RoleId))
            {
                _Bus.RaiseEvent(new Notifications.DomainNotification("Role", "权限名称重复!"), "Role");
                return(Task.FromResult(false));
            }
            //提交
            if (_REPOSITORY.Create(entity))
            {
                var eventResult = _Bus.RaiseEvent(new Domain.Models.EventModels.Role.CreateEventModel(entity.RoleId.StringToGuid(), entity.RoleName, entity.RoleDescription, entity.IsValid, request.PermissionIds), "Role");
                return(Task.FromResult(eventResult.Result));
            }
            else
            {
                _Bus.RaiseEvent(new Notifications.DomainNotification("Role", "数据写入失败!"), "Role");
                return(Task.FromResult(false));
            }
        }