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.
83 lines
2.6 KiB
83 lines
2.6 KiB
1 year ago
|
using System;
|
||
|
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
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;
|
||
|
using Win_in.Sfs.Shared;
|
||
|
|
||
|
|
||
|
namespace Win_in.Sfs.Basedata.Application;
|
||
|
|
||
|
[Authorize]
|
||
|
[Route($"{BasedataConsts.RootPath}kitting")]
|
||
|
|
||
|
public class KittingAppService : SfsBaseDataWithCodeAppServiceBase<Kitting, KittingDTO, SfsBaseDataRequestInputBase, KittingEditInput, KittingImportInput>, IKittingAppService
|
||
|
{
|
||
|
private new readonly IKittingRepository _repository;
|
||
|
private readonly IKittingManager _manager;
|
||
|
|
||
|
public KittingAppService(IKittingRepository repository, IDistributedCache<KittingDTO> cache, IKittingManager manager) : base(repository,cache)
|
||
|
{
|
||
|
_repository = repository;
|
||
|
_manager = manager;
|
||
|
//base.CreatePolicyName = KittingPermissions.Create;
|
||
|
//base.UpdatePolicyName = KittingPermissions.Update;
|
||
|
//base.DeletePolicyName = KittingPermissions.Delete;
|
||
|
}
|
||
|
[HttpPost]
|
||
|
[Route("")]
|
||
|
public override async Task<KittingDTO> CreateAsync(KittingEditInput input)
|
||
|
{
|
||
|
var entity = ObjectMapper.Map<KittingEditInput, Kitting>(input);
|
||
|
|
||
|
entity.SetId(Guid.NewGuid());
|
||
|
|
||
|
entity.Details.ForEach(item =>
|
||
|
{
|
||
|
item.MasterId = entity.Id;
|
||
|
});
|
||
|
|
||
|
entity = await _repository.InsertAsync(entity).ConfigureAwait(false);
|
||
|
|
||
|
return ObjectMapper.Map<Kitting, KittingDTO>(entity);
|
||
|
}
|
||
|
|
||
|
[HttpPut]
|
||
|
[Route("{id}")]
|
||
|
public override Task<KittingDTO> UpdateAsync(Guid id, KittingEditInput input)
|
||
|
{
|
||
|
return base.UpdateAsync(id, input);
|
||
|
}
|
||
|
|
||
|
[HttpPost("update")]
|
||
|
public virtual async Task UpdateAsync(KittingEditInput input)
|
||
|
{
|
||
|
var entity = ObjectMapper.Map<KittingEditInput, Kitting>(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<KittingDTO> GetFromRepositoryAsync(string code)
|
||
|
{
|
||
|
var displayName = typeof(KittingDTO).GetNameOfDisplay();
|
||
|
|
||
|
var query = await _repository.WithDetailsAsync().ConfigureAwait(false);
|
||
|
|
||
|
var entity = await query.Where(p => p.Code == code).FirstOrDefaultAsync().ConfigureAwait(false);
|
||
|
|
||
|
return ObjectMapper.Map<Kitting, KittingDTO>(entity);
|
||
|
}
|
||
|
}
|