diff --git a/src/Shentun.Peis.Application.Contracts/CardTypes/CreateCardTypeDto.cs b/src/Shentun.Peis.Application.Contracts/CardTypes/CreateCardTypeDto.cs
index 133e08d..47786ae 100644
--- a/src/Shentun.Peis.Application.Contracts/CardTypes/CreateCardTypeDto.cs
+++ b/src/Shentun.Peis.Application.Contracts/CardTypes/CreateCardTypeDto.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.CardTypes
@@ -9,18 +10,22 @@ namespace Shentun.Peis.CardTypes
///
/// 名称
///
+ [Required(ErrorMessage ="名称不能为空")]
public string DisplayName { get; set; }
///
/// 卡模式 (0:充值卡,1:积分卡)
///
+ [Required(ErrorMessage = "卡模式不能为空")]
public char CardModeId { get; set; }
///
/// 折扣
///
+ [Required(ErrorMessage = "折扣不能为空")]
public int Discount { get; set; }
///
/// 有效期
///
+ [Required(ErrorMessage = "有效期不能为空")]
public int ExpiryDay { get; set; }
///
diff --git a/src/Shentun.Peis.Application.Contracts/CardTypes/UpdateCardTypeDto.cs b/src/Shentun.Peis.Application.Contracts/CardTypes/UpdateCardTypeDto.cs
index 439980e..64aa6f5 100644
--- a/src/Shentun.Peis.Application.Contracts/CardTypes/UpdateCardTypeDto.cs
+++ b/src/Shentun.Peis.Application.Contracts/CardTypes/UpdateCardTypeDto.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Shentun.Peis.CardTypes
@@ -9,18 +10,22 @@ namespace Shentun.Peis.CardTypes
///
/// 名称
///
+ [Required(ErrorMessage = "名称不能为空")]
public string DisplayName { get; set; }
///
/// 卡模式 (0:充值卡,1:积分卡)
///
+ [Required(ErrorMessage = "卡模式不能为空")]
public char CardModeId { get; set; }
///
/// 折扣
///
+ [Required(ErrorMessage = "折扣不能为空")]
public int Discount { get; set; }
///
/// 有效期
///
+ [Required(ErrorMessage = "有效期不能为空")]
public int ExpiryDay { get; set; }
///
diff --git a/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs b/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs
index d6bbdcd..8780d2c 100644
--- a/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs
+++ b/src/Shentun.Peis.Application/CardTypes/CardTypeAppService.cs
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using Shentun.Peis.Asbitems;
using Shentun.Peis.GuideTypes;
using Shentun.Peis.Models;
using System;
@@ -13,6 +14,7 @@ using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Identity;
+using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.CardTypes
{
@@ -28,13 +30,16 @@ namespace Shentun.Peis.CardTypes
{
private readonly IRepository _cardTypeRepository;
private readonly IRepository _userRepository;
+ private readonly CardTypeManager _manager;
public CardTypeAppService(
IRepository cardTypeRepository,
- IRepository userRepository) : base(cardTypeRepository)
+ IRepository userRepository,
+ CardTypeManager manager) : base(cardTypeRepository)
{
this._cardTypeRepository = cardTypeRepository;
this._userRepository = userRepository;
+ this._manager = manager;
}
@@ -110,9 +115,14 @@ namespace Shentun.Peis.CardTypes
///
///
[HttpPost("api/app/cardtype/create")]
- public override Task CreateAsync(CreateCardTypeDto input)
+ public override async Task CreateAsync(CreateCardTypeDto input)
{
- return base.CreateAsync(input);
+ var createEntity = ObjectMapper.Map(input);
+ var entity = await _manager.CreateAsync(createEntity);
+ entity = await Repository.InsertAsync(entity);
+ var dto = ObjectMapper.Map(entity);
+ return dto;
+
}
///
@@ -122,9 +132,13 @@ namespace Shentun.Peis.CardTypes
///
///
[HttpPost("api/app/cardtype/update")]
- public override Task UpdateAsync(Guid id, UpdateCardTypeDto input)
+ public override async Task UpdateAsync(Guid id, UpdateCardTypeDto input)
{
- return base.UpdateAsync(id, input);
+ var entity = await Repository.GetAsync(id);
+ var sourceEntity = ObjectMapper.Map(input);
+ await _manager.UpdateAsync(sourceEntity, entity);
+ entity = await Repository.UpdateAsync(entity);
+ return ObjectMapper.Map(entity);
}
///
diff --git a/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs b/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs
index f126481..d53786a 100644
--- a/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs
+++ b/src/Shentun.Peis.Application/PayModes/PayModeAppService.cs
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.HelperDto;
using Shentun.Peis.Models;
+using Shentun.Peis.Patients;
using Shentun.Peis.PayModes;
using Shentun.Utilities;
using System;
@@ -13,6 +14,7 @@ using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
+using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.PayModes
{
@@ -25,10 +27,14 @@ namespace Shentun.Peis.PayModes
public class PayModeAppService : ApplicationService
{
private readonly IRepository _repository;
+ private readonly PayModeManager _manager;
- public PayModeAppService(IRepository repository)
+ public PayModeAppService(
+ IRepository repository,
+ PayModeManager manager)
{
this._repository = repository;
+ this._manager = manager;
}
@@ -65,30 +71,11 @@ namespace Shentun.Peis.PayModes
///
public async Task UpdateAsync(string Id, UpdatePayModeDto input)
{
- Check.NotNullOrWhiteSpace(input.DisplayName, nameof(input.DisplayName));
-
- PayMode existEntity = await _repository.FindAsync(o => o.Id != Id && o.DisplayName == input.DisplayName);
- if (existEntity != null)
- {
- throw new UserFriendlyException($"名称:'{input.DisplayName}'已存在");
- }
-
- var ent = await _repository.GetAsync(m => m.Id == Id);
- if (ent != null)
- {
-
- ent.DisplayName = input.DisplayName;
- ent.SimpleCode = LanguageConverter.GetPYSimpleCode(input.DisplayName);
- ent.IsActive = input.IsActive;
- var newent = await _repository.UpdateAsync(ent);
-
- return ObjectMapper.Map(newent);
- }
- else
- {
- return ObjectMapper.Map(ent);
- }
-
+ var entity = await _repository.GetAsync(m => m.Id == Id);
+ var sourceEntity = ObjectMapper.Map(input);
+ _manager.UpdateAsync(sourceEntity, entity);
+ entity = await _repository.UpdateAsync(entity);
+ return ObjectMapper.Map(entity);
}
diff --git a/src/Shentun.Peis.Domain/CardTypes/CardType.cs b/src/Shentun.Peis.Domain/CardTypes/CardType.cs
index 23c4da2..8faa215 100644
--- a/src/Shentun.Peis.Domain/CardTypes/CardType.cs
+++ b/src/Shentun.Peis.Domain/CardTypes/CardType.cs
@@ -12,7 +12,7 @@ namespace Shentun.Peis.Models
/// 会员卡类别
///
[Table("card_type")]
- public class CardType : AuditedEntity, IHasConcurrencyStamp
+ public class CardType : AuditedEntity, IDisplayName, IDisplayOrder, IHasConcurrencyStamp
{
public CardType()
{
diff --git a/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs b/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs
new file mode 100644
index 0000000..81cbcab
--- /dev/null
+++ b/src/Shentun.Peis.Domain/CardTypes/CardTypeManager.cs
@@ -0,0 +1,74 @@
+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 _repository;
+
+ public CardTypeManager(IRepository Repository)
+ {
+ _repository = Repository;
+ }
+
+
+ ///
+ /// 创建
+ ///
+ ///
+ ///
+ public async Task CreateAsync(
+ CardType entity
+ )
+ {
+ Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName));
+ await EntityHelper.CheckSameName(_repository, entity.DisplayName);
+ return new CardType
+ {
+ DisplayName = entity.DisplayName,
+ DisplayOrder = await EntityHelper.CreateMaxDisplayOrder(_repository),
+ CardModeId = entity.CardModeId,
+ Discount = entity.Discount,
+ ExpiryDay = entity.ExpiryDay,
+ Remark = entity.Remark
+ };
+ }
+ ///
+ /// 更新
+ ///
+ ///
+ ///
+ ///
+ public async Task UpdateAsync(
+ CardType sourceEntity,
+ CardType targetEntity
+ )
+ {
+ Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName));
+ if (sourceEntity.DisplayName != targetEntity.DisplayName)
+ {
+ await EntityHelper.CheckSameName(_repository, sourceEntity.DisplayName, targetEntity);
+ targetEntity.DisplayName = sourceEntity.DisplayName;
+ }
+
+
+
+ targetEntity.CardModeId = sourceEntity.CardModeId;
+ targetEntity.Discount = sourceEntity.Discount;
+ targetEntity.ExpiryDay = sourceEntity.ExpiryDay;
+ targetEntity.Remark = sourceEntity.Remark;
+
+ }
+ }
+}
diff --git a/src/Shentun.Peis.Domain/PayModes/PayModeManager.cs b/src/Shentun.Peis.Domain/PayModes/PayModeManager.cs
new file mode 100644
index 0000000..9ee54d8
--- /dev/null
+++ b/src/Shentun.Peis.Domain/PayModes/PayModeManager.cs
@@ -0,0 +1,54 @@
+using AutoMapper.Internal.Mappers;
+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.Domain.Repositories;
+using Volo.Abp;
+using Volo.Abp.Domain.Services;
+
+namespace Shentun.Peis.PayModes
+{
+ public class PayModeManager : DomainService
+ {
+
+ private readonly IRepository _repository;
+
+ public PayModeManager(IRepository repository)
+ {
+ _repository = repository;
+ }
+
+ ///
+ /// 更新
+ ///
+ ///
+ ///
+ ///
+ public async void UpdateAsync(
+ PayMode sourceEntity,
+ PayMode targetEntity
+ )
+ {
+ Check.NotNullOrWhiteSpace(sourceEntity.DisplayName, nameof(sourceEntity.DisplayName));
+
+ PayMode existEntity = await _repository.FindAsync(o => o.Id != targetEntity.Id && o.DisplayName == sourceEntity.DisplayName);
+ if (existEntity != null)
+ {
+ throw new UserFriendlyException($"名称:'{sourceEntity.DisplayName}'已存在");
+ }
+
+ if (sourceEntity.DisplayName != targetEntity.DisplayName)
+ {
+ targetEntity.DisplayName = sourceEntity.DisplayName;
+ targetEntity.SimpleCode = LanguageConverter.GetPYSimpleCode(sourceEntity.DisplayName);
+ }
+
+ targetEntity.IsActive = sourceEntity.IsActive;
+
+ }
+ }
+}