Browse Source

性别设置修改支持简码输入

bjmzak
DESKTOP-G961P6V\Zhh 2 years ago
parent
commit
8736f5470c
  1. 4
      src/Shentun.Peis.Application.Contracts/Sexs/UpdateSexDto.cs
  2. 23
      src/Shentun.Peis.Application/Sexs/SexAppService.cs
  3. 1
      src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs
  4. 51
      test/Shentun.Peis.Application.Tests/SexAppServiceTest.cs

4
src/Shentun.Peis.Application.Contracts/Sexs/UpdateSexDto.cs

@ -11,8 +11,8 @@ namespace Shentun.Peis.Sexs
{ {
[Required] [Required]
public string DisplayName { get; set; } public string DisplayName { get; set; }
//[Required]
//public string SimpleCode { get; set; }
[Required]
public string SimpleCode { get; set; }
} }

23
src/Shentun.Peis.Application/Sexs/SexAppService.cs

@ -56,27 +56,22 @@ namespace Shentun.Peis.Sexs
/// <param name="input">修改参数</param> /// <param name="input">修改参数</param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task<SexDto> UpdateAsync(char Id, UpdateSexDto input)
public async Task<SexDto> UpdateAsync(char Id, UpdateSexDto input)
{ {
var ent = await _repository.GetAsync(m => m.Id == Id); var ent = await _repository.GetAsync(m => m.Id == Id);
if (ent != null)
{
if (DateHelper.IsNullOrEmpty(input.DisplayName))
throw new UserFriendlyException("名称不能为空");
if (DateHelper.IsNullOrEmpty(input.DisplayName))
throw new UserFriendlyException("名称不能为空");
ent.DisplayName = input.DisplayName;
ent.SimpleCode = LanguageConverter.GetPYSimpleCode(input.DisplayName);
ent.DisplayName = input.DisplayName;
ent.SimpleCode = input.SimpleCode;
var newent = await _repository.UpdateAsync(ent);
return ObjectMapper.Map<Sex, SexDto>(newent);
var newent = await _repository.UpdateAsync(ent);
return ObjectMapper.Map<Sex, SexDto>(newent);
}
else
{
return ObjectMapper.Map<Sex, SexDto>(ent);
}
} }

1
src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs

@ -36,6 +36,7 @@ namespace Shentun.Peis.MedicalReportTypes
{ {
Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName));
await EntityHelper.CheckSameName<MedicalReportType, Guid>(_repository, entity.DisplayName); await EntityHelper.CheckSameName<MedicalReportType, Guid>(_repository, entity.DisplayName);
return new MedicalReportType( return new MedicalReportType(
GuidGenerator.Create() GuidGenerator.Create()
) )

51
test/Shentun.Peis.Application.Tests/SexAppServiceTest.cs

@ -0,0 +1,51 @@
using Microsoft.EntityFrameworkCore;
using Shentun.Peis.GuideTypes;
using Shentun.Peis.Models;
using Shentun.Peis.Sexs;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Uow;
using Xunit;
using Xunit.Abstractions;
namespace Shentun.Peis
{
public class SexAppServiceTest:PeisApplicationTestBase
{
private readonly IRepository<Sex> _repository;
private readonly SexAppService _appService;
private readonly ITestOutputHelper _output;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public SexAppServiceTest(ITestOutputHelper testOutputHelper)
{
_output = testOutputHelper;
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>();
_repository = GetRequiredService<IRepository<Sex>>();
_appService = GetRequiredService<SexAppService>();
}
[Fact]
public async Task UpdateAsync()
{
var dto = new UpdateSexDto() {
DisplayName = "未知",
SimpleCode = "A",
};
try
{
await _appService.UpdateAsync('U', dto);
}
catch (Exception ex)
{
_output.WriteLine(ex.ToString());
}
}
}
}
Loading…
Cancel
Save