Exemple #1
0
        public async Task <IResultModel> Sync(ButtonSyncModel model)
        {
            if (model.Buttons == null || !model.Buttons.Any())
            {
                return(ResultModel.Failed("请选择按钮"));
            }

            var menu = await _menuRepository.GetAsync(model.MenuId);

            if (menu == null)
            {
                return(ResultModel.Failed("菜单不存在"));
            }

            foreach (var info in model.Buttons)
            {
                if (info.Name.IsNull())
                {
                    return(ResultModel.Failed("按钮名称不能为空"));
                }

                if (info.Code.IsNull())
                {
                    return(ResultModel.Failed($"按钮({info.Name})编码不能为空"));
                }
            }

            using (var tran = _buttonRepository.BeginTransaction())
            {
                foreach (var button in model.Buttons)
                {
                    button.MenuId = model.MenuId;
                    button.Code   = button.Code.ToLower();

                    if (!await _buttonRepository.Exists(button, tran))
                    {
                        if (!await _buttonRepository.AddAsync(button, tran))
                        {
                            tran.Rollback();
                            return(ResultModel.Failed("同步失败"));
                        }
                    }
                    else
                    {
                        if (!await _buttonRepository.UpdateForSync(button, tran))
                        {
                            tran.Rollback();
                            return(ResultModel.Failed("同步失败"));
                        }
                    }
                }

                tran.Commit();
            }

            return(ResultModel.Success());
        }
Exemple #2
0
 public Task <IResultModel> Sync(ButtonSyncModel model)
 {
     return(_service.Sync(model));
 }