CountryFeeRepository.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Resource;
  4. using OASystem.Domain.Entities.Resource;
  5. using OASystem.Domain.ViewModels.Resource;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace OASystem.Infrastructure.Repositories.Resource
  12. {
  13. public class CountryFeeRepository : BaseRepository<Res_CountryFeeCost, CountryFeeCostView>
  14. {
  15. private readonly IMapper _mapper;
  16. public CountryFeeRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  17. {
  18. _mapper = mapper;
  19. }
  20. public async Task<Res_CountryFeeCost> _InfoByCountryName(string CountryName)
  21. {
  22. Res_CountryFeeCost _CountryFeeCost = new Res_CountryFeeCost();
  23. if (string.IsNullOrEmpty(CountryName)) return _CountryFeeCost;
  24. _CountryFeeCost = _sqlSugar.Queryable< Res_CountryFeeCost >().Where(it => it.VisaCountry.Equals(CountryName)).First();
  25. return _CountryFeeCost;
  26. }
  27. public async Task<Result> OperationCountryFeeCost(OperationCountryFeeCostDto dto)
  28. {
  29. Result result = new Result() { Code = -2, Msg = "未知错误" };
  30. try
  31. {
  32. if (dto.Status == 1)//添加
  33. {
  34. string selectSql = string.Format(@"select * from Res_CountryFeeCost where VisaContinent='{0}' and VisaCountry='{1}' and IsDel='{2}'"
  35. , dto.VisaContinent,dto.VisaCountry, 0);
  36. var CountryFeeCost = await _sqlSugar.SqlQueryable<Res_CountryFeeCost>(selectSql).FirstAsync();//查询是否存在
  37. if (CountryFeeCost != null)
  38. {
  39. return result = new Result() { Code = -1, Msg = "该国家已存在,请勿重复添加!" };
  40. }
  41. else//不存在,可添加
  42. {
  43. Res_CountryFeeCost _CountryFeeCost = _mapper.Map<Res_CountryFeeCost>(dto);
  44. int id = await AddAsyncReturnId(_CountryFeeCost);
  45. if (id == 0)
  46. {
  47. return result = new Result() { Code = -1, Msg = "添加失败!" };
  48. }
  49. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  50. }
  51. }
  52. else if (dto.Status == 2)//修改
  53. {
  54. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_CountryFeeCost
  55. {
  56. VisaContinent = dto.VisaContinent,
  57. VisaCountry = dto.VisaCountry,
  58. IsVisaExemption = dto.IsVisaExemption,
  59. IsVisaOnArrival = dto.IsVisaOnArrival,
  60. IsElectronicSignature = dto.IsElectronicSignature,
  61. VisaPrice = dto.VisaPrice,
  62. VisaPriceDesc = dto.VisaPriceDesc,
  63. VisaType = dto.VisaType,
  64. VisaTime = dto.VisaTime,
  65. IsUrgent = dto.IsUrgent,
  66. UrgentTime = dto.UrgentTime,
  67. UrgentPrice = dto.UrgentPrice,
  68. UrgentPriceDesc = dto.UrgentPriceDesc,
  69. VisaAddress = dto.VisaAddress,
  70. Remark = dto.Remark,
  71. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  72. });
  73. if (!res)
  74. {
  75. return result = new Result() { Code = -1, Msg = "修改失败!" };
  76. }
  77. result = new Result() { Code = 0, Msg = "修改成功!" };
  78. }
  79. else
  80. {
  81. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. return result = new Result() { Code = -2, Msg = ex.Message };
  87. }
  88. return result;
  89. }
  90. }
  91. }