CountryFeeRepository.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. Res_CountryFeeCost _CountryFeeCost = _mapper.Map<Res_CountryFeeCost>(dto);
  31. if (dto.Status == 1)//添加
  32. {
  33. string selectSql = string.Format(@"select * from Res_CountryFeeCost where VisaContinent='{0}' and VisaCountry='{1}' and IsDel='{2}'"
  34. , dto.VisaContinent, dto.VisaCountry, 0);
  35. var CountryFeeCost = await _sqlSugar.SqlQueryable<Res_CountryFeeCost>(selectSql).FirstAsync();//查询是否存在
  36. if (CountryFeeCost != null)
  37. {
  38. return result = new Result() { Code = -1, Msg = "该国家已存在,请勿重复添加!" };
  39. }
  40. else//不存在,可添加
  41. {
  42. int id = await AddAsyncReturnId(_CountryFeeCost);
  43. if (id == 0)
  44. {
  45. return result = new Result() { Code = -1, Msg = "添加失败!" };
  46. }
  47. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  48. }
  49. }
  50. else if (dto.Status == 2)//修改
  51. {
  52. _CountryFeeCost.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  53. bool res = await UpdateAsync(a => a.Id == dto.Id, a => _CountryFeeCost);
  54. if (!res)
  55. {
  56. return result = new Result() { Code = -1, Msg = "修改失败!" };
  57. }
  58. result = new Result() { Code = 0, Msg = "修改成功!" };
  59. }
  60. else
  61. {
  62. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  63. }
  64. return result;
  65. }
  66. }
  67. }