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.
82 lines
2.6 KiB
82 lines
2.6 KiB
using Shentun.Peis.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Domain.Services;
|
|
|
|
namespace Shentun.Peis.ReportFormats
|
|
{
|
|
public class ReportFormatManager : DomainService
|
|
{
|
|
private readonly IRepository<ReportFormat, string> _repository;
|
|
public ReportFormatManager(IRepository<ReportFormat, string> repository)
|
|
{
|
|
_repository = repository;
|
|
}
|
|
|
|
public async Task<ReportFormat> GetDefaultAsync(string reportId)
|
|
{
|
|
var ent = (await _repository.GetListAsync()).Where(m => m.ReportId == reportId && m.IsDefault.Equals('Y')).FirstOrDefault();
|
|
|
|
return ent;
|
|
}
|
|
|
|
public async Task<ReportFormat> CreateAsync(
|
|
ReportFormat entity
|
|
)
|
|
{
|
|
Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName));
|
|
await EntityHelper.CheckEqualsId<ReportFormat, string>(_repository, entity.Id);
|
|
await EntityHelper.CheckEqualsName<ReportFormat, string>(_repository, entity.DisplayName);
|
|
var var = new ReportFormat()
|
|
{
|
|
DisplayName = entity.DisplayName,
|
|
IsDefault= entity.IsDefault,
|
|
ReportId= entity.ReportId
|
|
};
|
|
var.SetId(entity.Id);
|
|
return var;
|
|
}
|
|
|
|
public async Task UpdateAsync(
|
|
ReportFormat sourceEntity,
|
|
ReportFormat targetEntity
|
|
)
|
|
{
|
|
Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName));
|
|
if (sourceEntity.DisplayName != targetEntity.DisplayName)
|
|
{
|
|
await EntityHelper.CheckEqualsName<ReportFormat, string>(_repository, sourceEntity.DisplayName, targetEntity);
|
|
targetEntity.DisplayName = sourceEntity.DisplayName;
|
|
}
|
|
}
|
|
|
|
public async Task UpdateDefaultAsync(string id)
|
|
{
|
|
var entity = await _repository.GetAsync(id);
|
|
if (entity != null)
|
|
{
|
|
entity.IsDefault = 'Y';
|
|
|
|
List<ReportFormat> UptList = new List<ReportFormat>();
|
|
UptList = await _repository.GetListAsync(o => o.ReportId == entity.ReportId && o.Id != id && o.IsDefault == 'Y');
|
|
foreach (var upt in UptList)
|
|
{
|
|
upt.IsDefault = 'N';
|
|
}
|
|
|
|
UptList.Add(entity);
|
|
|
|
|
|
await _repository.UpdateManyAsync(UptList);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|