1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using Admin.Core.Common.Input;
- using Admin.Core.Common.Output;
- using Admin.Core.Model.Admin;
- using Admin.Core.Repository.Admin;
- using Admin.Core.Service.Admin.Organization.Input;
- using Admin.Core.Service.Admin.Organization.Output;
- using System.Threading.Tasks;
- namespace Admin.Core.Service.Admin.Organization
- {
- public class OrganizationService : BaseService, IOrganizationService
- {
- private readonly IOrganizationRepository _organizationRepository;
- public OrganizationService(IOrganizationRepository organizationRepository)
- {
- _organizationRepository = organizationRepository;
- }
- public async Task<IResponseOutput> GetAsync(long id)
- {
- var result = await _organizationRepository.GetAsync<OrganizationGetOutput>(id);
- return ResponseOutput.Ok(result);
- }
- public async Task<IResponseOutput> PageAsync(PageInput<OrganizationEntity> input)
- {
- var key = input.Filter?.Name;
- var list = await _organizationRepository.Select
- .WhereIf(key.NotNull(), a => a.Name.Contains(key) || a.Code.Contains(key))
- .Count(out var total)
- .OrderByDescending(true, c => c.Id)
- .Page(input.CurrentPage, input.PageSize)
- .ToListAsync<OrganizationListOutput>();
- var data = new PageOutput<OrganizationListOutput>()
- {
- List = list,
- Total = total
- };
- return ResponseOutput.Ok(data);
- }
- public async Task<IResponseOutput> AddAsync(OrganizationAddInput input)
- {
- var dictionary = Mapper.Map<OrganizationEntity>(input);
- var id = (await _organizationRepository.InsertAsync(dictionary)).Id;
- return ResponseOutput.Result(id > 0);
- }
- public async Task<IResponseOutput> UpdateAsync(OrganizationUpdateInput input)
- {
- if (!(input?.Id > 0))
- {
- return ResponseOutput.NotOk();
- }
- var entity = await _organizationRepository.GetAsync(input.Id);
- if (!(entity?.Id > 0))
- {
- return ResponseOutput.NotOk("数据字典不存在!");
- }
- Mapper.Map(input, entity);
- await _organizationRepository.UpdateAsync(entity);
- return ResponseOutput.Ok();
- }
- public async Task<IResponseOutput> DeleteAsync(long id)
- {
- var result = false;
- if (id > 0)
- {
- result = (await _organizationRepository.DeleteAsync(m => m.Id == id)) > 0;
- }
- return ResponseOutput.Result(result);
- }
- public async Task<IResponseOutput> SoftDeleteAsync(long id)
- {
- var result = await _organizationRepository.SoftDeleteAsync(id);
- return ResponseOutput.Result(result);
- }
- }
- }
|