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.Entities; using Volo.Abp.Domain.Repositories; namespace Shentun.Peis { internal class EntityHelper { /// /// 创建最大显示顺序 /// /// /// /// public static async Task CreateMaxDisplayOrder(IRepository repository) where TEntity: class, IEntity,IDisplayOrder { int? maxDisplayOrder = await repository.MaxAsync(o => (int?)o.DisplayOrder); return (maxDisplayOrder ?? 0) + 1; } /// /// 检查同名 /// /// /// /// /// /// /// /// public static async Task CheckSameName(IRepository repository,string name, TEntity updatedEntity = null) where TEntity : class, IEntity, IDisplayName { Check.NotNullOrWhiteSpace(name, nameof(name)); TEntity existEntity; if (updatedEntity == null) { existEntity = await repository.FindAsync(o => o.DisplayName == name); } else { existEntity = await repository.FindAsync(o => o.Id.ToString() != updatedEntity.Id.ToString() && o.DisplayName == name); } if (existEntity != null) { throw new UserFriendlyException($"名称:'{name}'已存在"); } } } }