54 lines
1.6 KiB
C#
54 lines
1.6 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.Entities;
|
|||
|
|
using Volo.Abp.Domain.Repositories;
|
|||
|
|
using Volo.Abp.Validation;
|
|||
|
|
|
|||
|
|
namespace Kurs.Languages;
|
|||
|
|
|
|||
|
|
public class LanguageAppService : CrudAppService<
|
|||
|
|
Language,
|
|||
|
|
LanguageDto,
|
|||
|
|
Guid,
|
|||
|
|
PagedAndSortedResultRequestDto>,
|
|||
|
|
ILanguageAppService
|
|||
|
|
{
|
|||
|
|
public LanguageAppService(IRepository<Language, Guid> repository) : base(repository)
|
|||
|
|
{
|
|||
|
|
LocalizationResource = typeof(LanguagesResource);
|
|||
|
|
ObjectMapperContext = typeof(LanguagesApplicationModule);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override async Task<LanguageDto> CreateAsync(LanguageDto input)
|
|||
|
|
{
|
|||
|
|
var recordExists = await Repository.AnyAsync(a => a.CultureName == input.CultureName);
|
|||
|
|
if (recordExists)
|
|||
|
|
{
|
|||
|
|
var validationErrors = new ValidationResult(
|
|||
|
|
L["Error:UniqueControl"],
|
|||
|
|
new string[] { "CultureName" }
|
|||
|
|
);
|
|||
|
|
throw new AbpValidationException(new List<ValidationResult> { validationErrors });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return await base.CreateAsync(input);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task<LanguageDto> GetLanguageByCultureNameAsync(string CultureName)
|
|||
|
|
{
|
|||
|
|
var item = await Repository.FirstOrDefaultAsync(a => a.CultureName == CultureName);
|
|||
|
|
if (item is null)
|
|||
|
|
{
|
|||
|
|
throw new EntityNotFoundException(L["RecordNotFound"]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return ObjectMapper.Map<Language, LanguageDto>(item);
|
|||
|
|
}
|
|||
|
|
}
|