CountryFeeRepository.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. _CountryFeeCost.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  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. int id = await AddAsyncReturnId(_CountryFeeCost);
  44. if (id == 0)
  45. {
  46. return result = new Result() { Code = -1, Msg = "添加失败!" };
  47. }
  48. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  49. }
  50. }
  51. else if (dto.Status == 2)//修改
  52. {
  53. var update = await _sqlSugar.Updateable(_CountryFeeCost)
  54. .IgnoreColumns(it => new { it.Id, it.DeleteUserId, it.DeleteTime, it.CreateUserId, it.CreateTime, it.IsDel })
  55. .Where(it => it.Id == _CountryFeeCost.Id)
  56. .ExecuteCommandAsync();
  57. //bool res = await UpdateAsync(a => a.Id == dto.Id, a => _CountryFeeCost);
  58. if (update < 1)
  59. {
  60. return result = new Result() { Code = -1, Msg = "修改失败!" };
  61. }
  62. result = new Result() { Code = 0, Msg = "修改成功!" };
  63. }
  64. else
  65. {
  66. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  67. }
  68. return result;
  69. }
  70. }
  71. }