CountryFeeRepository.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using AutoMapper;
  2. using OASystem.Domain.Dtos.Resource;
  3. using OASystem.Domain.Entities.Resource;
  4. using OASystem.Domain.ViewModels.Resource;
  5. namespace OASystem.Infrastructure.Repositories.Resource
  6. {
  7. public class CountryFeeRepository : BaseRepository<Res_CountryFeeCost, CountryFeeCostView>
  8. {
  9. private readonly IMapper _mapper;
  10. public CountryFeeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  11. {
  12. _mapper = mapper;
  13. }
  14. public async Task<Res_CountryFeeCost> InfoByCountryName(string countryName)
  15. {
  16. if (string.IsNullOrEmpty(countryName)) return null;
  17. return await _sqlSugar.Queryable<Res_CountryFeeCost>()
  18. .FirstAsync(it => it.VisaCountry == countryName);
  19. }
  20. public async Task<JsonView> OperationCountryFeeCost(OperationCountryFeeCostDto dto)
  21. {
  22. var result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "未知错误" };
  23. var countryFeeCost = _mapper.Map<Res_CountryFeeCost>(dto);
  24. countryFeeCost.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  25. if (dto.Status == 1)//添加
  26. {
  27. var exists = await _sqlSugar.Queryable<Res_CountryFeeCost>()
  28. .AnyAsync(x => x.IsDel == 0 &&
  29. x.VisaFeeType == dto.VisaFeeType &&
  30. x.VisaContinent == dto.VisaContinent &&
  31. x.VisaCountry == dto.VisaCountry);
  32. if (exists)
  33. {
  34. result.Msg = "该国家已存在,请勿重复添加!";
  35. return result;
  36. }
  37. else//不存在,可添加
  38. {
  39. int id = await AddAsyncReturnId(countryFeeCost);
  40. if (id == 0)
  41. {
  42. result.Msg = "添加失败!";
  43. return result;
  44. }
  45. result.Code = StatusCodes.Status200OK;
  46. result.Msg = "添加成功!";
  47. }
  48. }
  49. else if (dto.Status == 2)//修改
  50. {
  51. var update = await _sqlSugar
  52. .Updateable(countryFeeCost)
  53. .IgnoreColumns(it => new { it.Id, it.DeleteUserId, it.DeleteTime, it.CreateUserId, it.CreateTime, it.IsDel })
  54. .Where(it => it.Id == countryFeeCost.Id)
  55. .ExecuteCommandAsync();
  56. //bool res = await UpdateAsync(a => a.Id == dto.Id, a => _CountryFeeCost);
  57. if (update < 1)
  58. {
  59. result.Msg = "修改失败!";
  60. return result;
  61. }
  62. result.Code = StatusCodes.Status200OK;
  63. result.Msg = "修改成功!";
  64. }
  65. else
  66. {
  67. result.Msg = "请传入Status参数,1添加 2修改!";
  68. }
  69. return result;
  70. }
  71. }
  72. }