コード例 #1
0
        public async Task <bool> MultiEdit(List <Assets> assetsList)
        {
            var result = await DB.UseTranAsync(async() =>
            {
                foreach (var assets in assetsList)
                {
                    //if (Assets.Validate(assets).All(validateResult => validateResult.IsSuccess))
                    AssetsDb.Update(a => new Assets {
                        ParentId = assets.ParentId
                    }, it => it.AssetsId == assets.AssetsId);
                }
            });

            return(result.IsSuccess);
        }
コード例 #2
0
        public async Task <bool> Edit(Assets assets)
        {
            if (Assets.Validate(assets).All(validateResult => validateResult.IsSuccess))
            {
                if (assets.AssetsId.IsEmpty())
                {
                    var current = AssetsDb.GetSingle(ass => ass.AssetsName == assets.AssetsName);
                    return(current.IsNull() ? await AssetsDb.AsInsertable(assets).ExecuteCommandAsync() > 0 : false);
                }
                else
                {
                    return(await AssetsDb.AsUpdateable(assets).ExecuteCommandAsync() > 0);
                }
            }

            return(false);
        }
コード例 #3
0
        public async Task <bool> EditMenu(Menu menu)
        {
            var result = false;

            if (Menu.Validate(menu).All(validateResult => validateResult.IsSuccess))
            {
                if (menu.MenuId.IsEmpty() && MenuDb.GetSingle(m => m.Title == menu.Title).IsNull())
                {
                    menu.MenuId = Guid.NewGuid();
                    result      = DB.UseTranAsync(async() =>
                    {
                        await DB.Insertable(menu).ExecuteCommandAsync();
                        await DB.Insertable(new Assets
                        {
                            AssetsName   = menu.Title,
                            AssetsStatus = Keys.EnableStatus,
                            AssetsType   = Keys.Assests.MenuType,
                            ItemId       = menu.MenuId,
                            SystemId     = menu.SystemId
                        }).ExecuteCommandAsync();
                    }).IsCompletedSuccessfully;
                }
                else
                {
                    var assets = await SearchAssets(ass => ass.ItemId == menu.MenuId);

                    if (assets.Count() > 0)
                    {
                        var asset = assets.FirstOrDefault();
                        asset.AssetsName = menu.Title;
                        result           = await AssetsDb.AsUpdateable(asset).ExecuteCommandAsync() > 0;
                    }

                    result = await MenuDb.AsUpdateable(menu).ExecuteCommandAsync() > 0;
                }
            }

            return(result);
        }
コード例 #4
0
        public async Task <bool> EditInterface(Interface inter)
        {
            var result = false;

            if (Interface.Validate(inter).All(validateResult => validateResult.IsSuccess))
            {
                if (inter.InterfaceId.IsEmpty() && InterfaceDb.GetSingle(m => m.Title == inter.Title).IsNull())
                {
                    result = DB.UseTranAsync(async() =>
                    {
                        await DB.Insertable(inter).ExecuteCommandAsync();
                        await DB.Insertable(new Assets
                        {
                            AssetsName   = inter.Title,
                            AssetsStatus = Keys.EnableStatus,
                            AssetsType   = Keys.Assests.MenuType,
                            ItemId       = inter.InterfaceId,
                            SystemId     = Keys.System.DefaultSystemId
                        }).ExecuteCommandAsync();
                    }).IsCompletedSuccessfully;
                }
                else
                {
                    var assets = await SearchAssets(ass => ass.ItemId == inter.InterfaceId);

                    if (assets.Count() > 0)
                    {
                        var asset = assets.FirstOrDefault();
                        asset.AssetsName = inter.Title;
                        result           = await AssetsDb.AsUpdateable(asset).ExecuteCommandAsync() > 0;
                    }

                    result = await InterfaceDb.AsUpdateable(inter).ExecuteCommandAsync() > 0;
                }
            }
            return(false);
        }
コード例 #5
0
        public async Task <IEnumerable <Assets> > SearchAssets(Expression <Func <Assets, bool> > whereExpressions)
        {
            var query = whereExpressions == null?AssetsDb.AsQueryable() : AssetsDb.AsQueryable().Where(whereExpressions);

            return(await query.ToListAsync());
        }
コード例 #6
0
 public async Task <Assets> GetById(Guid assetId)
 {
     return(await AssetsDb.AsQueryable().FirstAsync(asset => asset.AssetsId == assetId));
 }