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 _repository; public ReportFormatManager(IRepository repository) { _repository = repository; } public async Task GetDefaultAsync(string reportId) { var ent = (await _repository.GetListAsync()).Where(m => m.ReportId == reportId && m.IsDefault.Equals('Y')).FirstOrDefault(); return ent; } public async Task CreateAsync( ReportFormat entity ) { Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); await EntityHelper.CheckEqualsId(_repository, entity.Id); await EntityHelper.CheckEqualsName(_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(_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 UptList = new List(); 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); } } } }