You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6 KiB

2 years ago
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NUglify.Helpers;
using Volo.Abp.Caching;
using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Basedata.Domain;
using Win_in.Sfs.Basedata.Domain.Shared;
namespace Win_in.Sfs.Basedata.Application;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories;
using Win_in.Sfs.Shared;
[Authorize]
[Route($"{BasedataConsts.RootPath}dict")]
public class DictAppService : SfsBaseDataWithCodeAppServiceBase<Dict, DictDTO, SfsBaseDataRequestInputBase, DictEditInput, DictImportInput>, IDictAppService
{
private readonly IDictManager _dictManager;
private new readonly IDictRepository _repository;
public DictAppService(IDictRepository repository, IDistributedCache<DictDTO> cache, IDictManager dictManager) : base(repository, cache)
{
_repository = repository;
this._dictManager = dictManager;
// base.CreatePolicyName = DictPermissions.Create;
// base.UpdatePolicyName = DictPermissions.Update;
// base.DeletePolicyName = DictPermissions.Delete;
}
[HttpPost]
[Route("")]
public override async Task<DictDTO> CreateAsync(DictEditInput input)
{
var entity = ObjectMapper.Map<DictEditInput, Dict>(input);
entity.SetId(Guid.NewGuid());
entity.Items.ForEach(item =>
{
item.MasterId = entity.Id;
});
entity = await _repository.InsertAsync(entity).ConfigureAwait(false);
return ObjectMapper.Map<Dict, DictDTO>(entity);
}
[HttpPut]
[Route("{id}")]
public override Task<DictDTO> UpdateAsync(Guid id, DictEditInput input)
{
return base.UpdateAsync(id, input);
}
[HttpPost("update")]
public virtual async Task UpdateAsync(DictEditInput input)
{
var entity = ObjectMapper.Map<DictEditInput, Dict>(input);
//var dic=await _repository.GetAsync(r => r.Code == entity.Code);
// if (dic != null)
// {
// await _repository.DeleteAsync(dic);
// }
// await _repository.InsertAsync(entity);
await _repository.UpdateAsync(entity).ConfigureAwait(false);
}
protected override async Task<DictDTO> GetFromRepositoryAsync(string code)
{
var displayName = typeof(DictDTO).GetNameOfDisplay();
var query = await _repository.WithDetailsAsync().ConfigureAwait(false);
var entity = await query.Where(p => p.Code == code).FirstOrDefaultAsync().ConfigureAwait(false);
return ObjectMapper.Map<Dict, DictDTO>(entity);
}
}