49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
|
|
using Kurs.Languages.Entities;
|
|||
|
|
using Kurs.Languages.Localization;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel.DataAnnotations;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using Volo.Abp.Application.Dtos;
|
|||
|
|
using Volo.Abp.Application.Services;
|
|||
|
|
using Volo.Abp.Domain.Repositories;
|
|||
|
|
using Volo.Abp.Validation;
|
|||
|
|
|
|||
|
|
namespace Kurs.Languages;
|
|||
|
|
|
|||
|
|
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);
|
|||
|
|
_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);
|
|||
|
|
}
|
|||
|
|
}
|