public async Task SaveForm(MenuAuthorizeEntity entity) { if (entity.Id.IsNullOrZero()) { await entity.Create(); await this.BaseRepository().Insert(entity); } else { await this.BaseRepository().Update(entity); } }
public async Task SaveForm(RoleEntity entity) { var db = await this.BaseRepository().BeginTrans(); try { if (entity.Id.IsNullOrZero()) { await entity.Create(); await db.Insert(entity); } else { await db.Delete <MenuAuthorizeEntity>(t => t.AuthorizeId == entity.Id); await entity.Modify(); await db.Update(entity); } // 角色对应的菜单、页面和按钮权限 if (!string.IsNullOrEmpty(entity.MenuIds)) { foreach (long menuId in TextHelper.SplitToArray <long>(entity.MenuIds, ',')) { MenuAuthorizeEntity menuAuthorizeEntity = new MenuAuthorizeEntity(); menuAuthorizeEntity.AuthorizeId = entity.Id; menuAuthorizeEntity.MenuId = menuId; menuAuthorizeEntity.AuthorizeType = AuthorizeTypeEnum.Role.ParseToInt(); await menuAuthorizeEntity.Create(); await db.Insert(menuAuthorizeEntity); } } await db.CommitTrans(); } catch { await db.RollbackTrans(); throw; } }