CountryFeeRepository.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  65. });
  66. if (!res)
  67. {
  68. return result = new Result() { Code = -1, Msg = "修改失败!" };
  69. }
  70. result = new Result() { Code = 0, Msg = "修改成功!" };
  71. }
  72. else
  73. {
  74. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  75. }
  76. }
  77. catch (Exception ex)
  78. {
  79. return result = new Result() { Code = -2, Msg = ex.Message };
  80. }
  81. return result;
  82. }
  83. }
  84. }