| | |
| | | ? await menuRep.AsQueryable().FirstOrDefaultAsync(it => it.Id == request.Id, cancellationToken) |
| | | : new Menu(); |
| | | if (menu == null) throw Oops.Oh(EnumUserErrorCodeType.s100, "菜单"); |
| | | |
| | | if (request.Id.HasValue && menu.Code != request.Code) |
| | | { |
| | | throw Oops.Oh(EnumUserErrorCodeType.s200, "编号不可修改"); |
| | | } |
| | | |
| | | request.Adapt(menu); |
| | | |
| | | if (menu.ParentId.HasValue) |
| | | { |
| | | menu.Path = await menuRep.AsQueryable().AsNoTracking().Where(it => it.Id == menu.ParentId).Select(it => it.Path).FirstOrDefaultAsync(); |
| | | menu.Path = $"{menu.Path}/{menu.Code}"; |
| | | } |
| | | else |
| | | { |
| | | menu.Path = "/"; |
| | | } |
| | | |
| | | var result = request.Id == null |
| | | ? await menuRep.InsertNowAsync(menu, cancellationToken: cancellationToken) |
| | | : await menuRep.UpdateNowAsync(menu, cancellationToken: cancellationToken); |
| | | ? await menuRep.InsertAsync(menu, cancellationToken: cancellationToken) |
| | | : await menuRep.UpdateAsync(menu); |
| | | |
| | | await menuRep.SaveNowAsync(cancellationToken); |
| | | |
| | | return menu.Id; |
| | | } |
| | | } |