110 lines
3.9 KiB
C#
110 lines
3.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
using Kurs.Settings.Localization;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.Extensions.Localization;
|
||
using Volo.Abp.Domain.Repositories;
|
||
using Volo.Abp.Domain.Services;
|
||
using Volo.Abp.Settings;
|
||
using SettingDefinition = Kurs.Settings.Entities.SettingDefinition;
|
||
|
||
namespace Kurs.Settings;
|
||
|
||
public class KursSettingDefinitionManager : DomainService
|
||
{
|
||
private readonly IRepository<SettingDefinition, Guid> repository;
|
||
private readonly IStringLocalizer<SettingsResource> l;
|
||
private readonly ISettingProvider settingProvider;
|
||
private readonly IAuthorizationService authorizationService;
|
||
|
||
public KursSettingDefinitionManager(
|
||
IRepository<SettingDefinition, Guid> repository,
|
||
IStringLocalizer<SettingsResource> l,
|
||
ISettingProvider settingProvider,
|
||
IAuthorizationService authorizationService
|
||
)
|
||
{
|
||
this.repository = repository;
|
||
this.l = l;
|
||
this.settingProvider = settingProvider;
|
||
this.authorizationService = authorizationService;
|
||
//TODO: Bu sekilde settingleri alip vt ile Code uzerinden kiyaslayip insert eden seeder yazalim
|
||
//var settingDefinitions = _settingDefinitionManager.GetAll();
|
||
}
|
||
|
||
public virtual async Task<List<SettingGroupValueObject>> GetGroupedSettingDefinitionsAsync()
|
||
{
|
||
//Add Group
|
||
// Add Sub Group
|
||
// Add SettingDefinition
|
||
var result = new List<SettingGroupValueObject>();
|
||
|
||
var settingDefinitions = await repository.GetListAsync();
|
||
|
||
SettingGroupValueObject mainGroup = null;
|
||
|
||
//MainGroupKey bilgisini gruplu şekilde alıyoruz.
|
||
foreach (var group in settingDefinitions
|
||
.OrderBy(o => o.Order)
|
||
.GroupBy(g => new { g.MainGroupKey }))
|
||
{
|
||
mainGroup = new SettingGroupValueObject(
|
||
group.Key.MainGroupKey,
|
||
l[group.Key.MainGroupKey],
|
||
new Dictionary<string, List<SettingDefinitionWithValue>>());
|
||
|
||
//SubGrupları Group bazında filtreleyip SubGroupları Gruplu şekilde dönüyoruz.
|
||
foreach (var subGroup in settingDefinitions
|
||
.Where(a => a.MainGroupKey == group.Key.MainGroupKey)
|
||
.OrderBy(o => o.Order)
|
||
.GroupBy(g => new { g.SubGroupKey }))
|
||
{
|
||
//Her subgroupun altındaki itemler
|
||
foreach (var item in subGroup.ToList())
|
||
{
|
||
if (!await authorizationService.IsGrantedAsync(item.RequiredPermissionName))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (!mainGroup.GroupedSettingDefinitions.ContainsKey(subGroup.Key.SubGroupKey))
|
||
{
|
||
mainGroup.GroupedSettingDefinitions.Add(subGroup.Key.SubGroupKey, new List<SettingDefinitionWithValue>());
|
||
}
|
||
|
||
var value = await settingProvider.GetOrNullAsync(item.Code);
|
||
var itemWithValue = new SettingDefinitionWithValue(item, value);
|
||
mainGroup.GroupedSettingDefinitions[subGroup.Key.SubGroupKey].Add(itemWithValue);
|
||
}
|
||
}
|
||
|
||
if (mainGroup.GroupedSettingDefinitions.Count() > 0)
|
||
{
|
||
result.Add(mainGroup);
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
//private async Task<bool> CheckPermissionsAsync(List<string> permissions)
|
||
//{
|
||
// //TODO: permisson tanimli degilse hata firlatma
|
||
// var results = new List<bool>();
|
||
// try
|
||
// {
|
||
// foreach (var item in permissions)
|
||
// {
|
||
// results.Add(await authorizationService.IsGrantedAsync(item));
|
||
// }
|
||
// }
|
||
// catch
|
||
// {
|
||
// results.Add(false);
|
||
// }
|
||
|
||
// return results.Any(a => a);
|
||
//}
|
||
}
|