Beispiel #1
0
        public async Task <IResultModel> BindBtn(MenuButtonBindModel model)
        {
            if (!await _menuRepository.ExistsAsync(m => m.Id == model.MenuId))
            {
                return(ResultModel.Failed("菜单不存在"));
            }

            try
            {
                _dbContext.Db.BeginTran();

                await _menuButtonRepository.DeleteAsync(m => m.MenuId == model.MenuId, _dbContext.Db);

                model.Buttons.ForEach(m => { m.MenuId = model.MenuId; });

                await _menuButtonRepository.InsertRangeAsync(model.Buttons, _dbContext.Db);

                _dbContext.Db.CommitTran();
            }
            catch (Exception ex)
            {
                _dbContext.Db.RollbackTran();
                return(ResultModel.Failed(ex.Message));
            }

            return(ResultModel.Success());
        }
 /// <summary>
 /// 删除按钮,若有子项则不能删除
 /// </summary>
 /// <param name="id">按钮Id</param>
 public Task <int> Delete(string id)
 {
     if (menuButtonRepo.IQueryable().Count(t => t.ParentId.Equals(id)) > 0)
     {
         throw new Exception("删除失败!操作的对象包含了下级数据。");
     }
     else
     {
         return(menuButtonRepo.DeleteAsync(t => t.Id == id));
     }
 }