5 changed files with 180 additions and 13 deletions
-
29src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs
-
14src/Shentun.Peis.Application/PayModes/PayModeAppService.cs
-
10src/Shentun.Peis.Domain/CardTypes/CardType.cs
-
93src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs
-
47src/Shentun.Peis.Domain/PayModes/PayModeManager.cs
@ -0,0 +1,93 @@ |
|||
using Shentun.Peis.Models; |
|||
using Shentun.Utilities; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using TencentCloud.Sqlserver.V20180328.Models; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Domain.Services; |
|||
|
|||
namespace Shentun.Peis.CardTypes |
|||
{ |
|||
public class CardTypeManager : DomainService |
|||
{ |
|||
private readonly IRepository<CardType, Guid> _repository; |
|||
private readonly IRepository<CardRegister, Guid> _cardRegisterRepository; |
|||
public CardTypeManager(IRepository<CardType, Guid> repository, |
|||
IRepository<CardRegister, Guid> cardRegisterRepository) |
|||
{ |
|||
_repository = repository; |
|||
_cardRegisterRepository = cardRegisterRepository; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 创建
|
|||
/// </summary>
|
|||
/// <param name="entity"></param>
|
|||
/// <returns></returns>
|
|||
public async Task<CardType> CreateAsync( |
|||
CardType entity |
|||
) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); |
|||
await EntityHelper.CheckSameName<CardType, Guid>(_repository, entity.DisplayName); |
|||
return new CardType( |
|||
GuidGenerator.Create() |
|||
) |
|||
{ |
|||
DisplayName = entity.DisplayName, |
|||
DisplayOrder = await EntityHelper.CreateMaxDisplayOrder<CardType>(_repository), |
|||
CardModeId = entity.CardModeId, |
|||
Discount = entity.Discount, |
|||
ExpiryDay = entity.ExpiryDay, |
|||
Remark = entity.Remark |
|||
}; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 更新
|
|||
/// </summary>
|
|||
/// <param name="sourceEntity"></param>
|
|||
/// <param name="targetEntity"></param>
|
|||
/// <returns></returns>
|
|||
public async Task UpdateAsync( |
|||
CardType sourceEntity, |
|||
CardType targetEntity |
|||
) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName)); |
|||
if (sourceEntity.DisplayName != targetEntity.DisplayName) |
|||
{ |
|||
|
|||
await EntityHelper.CheckSameName<CardType, Guid>(_repository, sourceEntity.DisplayName, targetEntity); |
|||
targetEntity.DisplayName = sourceEntity.DisplayName; |
|||
} |
|||
targetEntity.CardModeId = sourceEntity.CardModeId; |
|||
targetEntity.Discount = sourceEntity.Discount; |
|||
targetEntity.ExpiryDay = sourceEntity.ExpiryDay; |
|||
targetEntity.Remark = sourceEntity.Remark; |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
public async Task CheckAndDeleteAsync(CardType entity) |
|||
{ |
|||
|
|||
var queryable = await _cardRegisterRepository.GetQueryableAsync(); |
|||
var item = queryable.Where(o => o.CardTypeId.Equals(entity.Id)).FirstOrDefault(); |
|||
if (item != null) |
|||
{ |
|||
throw new BusinessException("", $"卡类别\"{entity.DisplayName}\"已在卡登记\"{item.CustomerName}\"中使用,不能删除"); |
|||
} |
|||
|
|||
await _repository.DeleteAsync(entity); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using Shentun.Peis.Models; |
|||
using Shentun.Utilities; |
|||
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.PayModes |
|||
{ |
|||
public class PayModeManager : DomainService |
|||
{ |
|||
private readonly IRepository<PayMode> _repository; |
|||
|
|||
public PayModeManager( |
|||
IRepository<PayMode> repository |
|||
) |
|||
{ |
|||
_repository = repository; |
|||
} |
|||
|
|||
public async Task UpdateAsync( |
|||
PayMode sourceEntity, |
|||
PayMode targetEntity |
|||
) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName)); |
|||
|
|||
|
|||
if (sourceEntity.DisplayName != targetEntity.DisplayName) |
|||
{ |
|||
PayMode existEntity = await _repository.FindAsync(o => o.Id != targetEntity.Id && o.DisplayName == sourceEntity.DisplayName); |
|||
if (existEntity != null) |
|||
{ |
|||
throw new UserFriendlyException($"名称:'{sourceEntity.DisplayName}'已存在"); |
|||
} |
|||
|
|||
targetEntity.DisplayName = sourceEntity.DisplayName; |
|||
targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(targetEntity.DisplayName); |
|||
} |
|||
targetEntity.IsActive = sourceEntity.IsActive; |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue