CountryFeeRepository.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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<Result> OperationCountryFeeCost(OperationCountryFeeCostDto dto)
  21. {
  22. Result result = new Result() { Code = -2, Msg = "未知错误" };
  23. try
  24. {
  25. if (dto.Status == 1)//添加
  26. {
  27. string selectSql = string.Format(@"select * from Res_CountryFeeCost where VisaContinent='{0}' and VisaCountry='{1}' and IsDel='{2}'"
  28. , dto.VisaContinent,dto.VisaCountry, 0);
  29. var CountryFeeCost = await _sqlSugar.SqlQueryable<Res_CountryFeeCost>(selectSql).FirstAsync();//查询是否存在
  30. if (CountryFeeCost != null)
  31. {
  32. return result = new Result() { Code = -1, Msg = "该国家已存在,请勿重复添加!" };
  33. }
  34. else//不存在,可添加
  35. {
  36. Res_CountryFeeCost _CountryFeeCost = _mapper.Map<Res_CountryFeeCost>(dto);
  37. int id = await AddAsyncReturnId(_CountryFeeCost);
  38. if (id == 0)
  39. {
  40. return result = new Result() { Code = -1, Msg = "添加失败!" };
  41. }
  42. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  43. }
  44. }
  45. else if (dto.Status == 2)//修改
  46. {
  47. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_CountryFeeCost
  48. {
  49. VisaContinent = dto.VisaContinent,
  50. VisaCountry = dto.VisaCountry,
  51. IsVisaExemption = dto.IsVisaExemption,
  52. IsVisaOnArrival = dto.IsVisaOnArrival,
  53. IsElectronicSignature = dto.IsElectronicSignature,
  54. VisaPrice = dto.VisaPrice,
  55. VisaPriceDesc = dto.VisaPriceDesc,
  56. VisaType = dto.VisaType,
  57. VisaTime = dto.VisaTime,
  58. IsUrgent = dto.IsUrgent,
  59. UrgentTime = dto.UrgentTime,
  60. UrgentPrice = dto.UrgentPrice,
  61. UrgentPriceDesc = dto.UrgentPriceDesc,
  62. VisaAddress = dto.VisaAddress,
  63. Remark = dto.Remark
  64. });
  65. if (!res)
  66. {
  67. return result = new Result() { Code = -1, Msg = "修改失败!" };
  68. }
  69. result = new Result() { Code = 0, Msg = "修改成功!" };
  70. }
  71. else
  72. {
  73. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. return result = new Result() { Code = -2, Msg = "程序错误!" };
  79. }
  80. return result;
  81. }
  82. }
  83. }