sozsoft-platform/api/modules/Sozsoft.Languages/Sozsoft.Languages.Application/LanguageKeyAppService.cs
2026-10-05 15:58:59 +03:00

57 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Sozsoft.Languages.Entities;
using Sozsoft.Languages.Localization;
using Sozsoft.Languages.Permissions;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Validation;
namespace Sozsoft.Languages;
[Authorize]
public class LanguageKeyAppService : CrudAppService<
LanguageKey,
LanguageKeyDto,
Guid,
PagedAndSortedResultRequestDto>,
ILanguageKeyAppService
{
private readonly IRepository<LanguageKey, Guid> _repository;
public LanguageKeyAppService(
IRepository<LanguageKey, Guid> repository
) : base(repository)
{
LocalizationResource = typeof(LanguagesResource);
ObjectMapperContext = typeof(LanguagesApplicationModule);
GetPolicyName = LanguagesPermissions.LanguageText.Default;
GetListPolicyName = LanguagesPermissions.LanguageText.Default;
CreatePolicyName = LanguagesPermissions.LanguageText.Create;
UpdatePolicyName = LanguagesPermissions.LanguageText.Update;
DeletePolicyName = LanguagesPermissions.LanguageText.Delete;
_repository = repository;
}
public override async Task<LanguageKeyDto> CreateAsync(LanguageKeyDto input)
{
var recordExists = await _repository.AnyAsync(
a => a.ResourceName == input.ResourceName
&& a.Key == input.Key);
if (recordExists)
{
var validationErrors = new ValidationResult(
L["Error:UniqueControl"],
new string[] { "ResourceName", "Key" }
);
throw new AbpValidationException(new List<ValidationResult> { validationErrors });
}
return await base.CreateAsync(input);
}
}