HotelDataRepository.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using AutoMapper;
  2. using MySqlX.XDevAPI.Common;
  3. using OASystem.Domain;
  4. using OASystem.Domain.AesEncryption;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Dtos.Resource;
  7. using OASystem.Domain.Entities.Resource;
  8. using OASystem.Domain.ViewModels.Resource;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using XAct.Users;
  15. using Result = OASystem.Domain.Result;
  16. namespace OASystem.Infrastructure.Repositories.Resource
  17. {
  18. public class HotelDataRepository:BaseRepository<Res_HotelData,HotelDataView>
  19. {
  20. private readonly IMapper _mapper;
  21. public HotelDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  22. {
  23. _mapper= mapper;
  24. }
  25. public async Task<Result> _Info(int portType, int id)
  26. {
  27. if (id< 1) return new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  28. string sql = string.Format(@"SELECT
  29. Id,
  30. City,
  31. [Name],
  32. [Level],
  33. [Address],
  34. Tel,
  35. Fax,
  36. Contact,
  37. ContactPhone,
  38. OtherInformation,
  39. Remark
  40. FROM
  41. Res_HotelData
  42. WHERE
  43. IsDel = 0
  44. AND Id = {0}", id);
  45. if (portType == 1 || portType == 2 || portType == 3)
  46. {
  47. var info = await _sqlSugar.SqlQueryable<HotelDataInfoView>(sql).FirstAsync();
  48. EncryptionProcessor.DecryptProperties(info);// 解密属性
  49. if (info != null) return new Result() { Code = 0, Msg = "操作成功!",Data = info };
  50. return new Result() { Code = -1, Msg = "暂无数据!" };
  51. }
  52. return new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  53. }
  54. public async Task<Result> OperationHotelData(OperationHotelDto dto)
  55. {
  56. Result result = new Result() { Code = -2, Msg = "未知错误" };
  57. if (dto.Status == 1)//添加
  58. {
  59. string selectSql = string.Format(@"select * from Res_HotelData where Name='{0}' and IsDel='{1}'"
  60. , dto.Name, 0);
  61. var HotelData = await _sqlSugar.Queryable<Res_HotelData>().Where(x => x.IsDel == 0 && x.Name.Contains(dto.Name)).FirstAsync();//查询是否存在
  62. if (HotelData != null)
  63. {
  64. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  65. }
  66. else//不存在,可添加
  67. {
  68. var _HotelDataDto = _mapper.Map<Res_HotelData>(dto);
  69. EncryptionProcessor.EncryptProperties(_HotelDataDto);// 加密属性
  70. int id = await AddAsyncReturnId(_HotelDataDto);
  71. if (id == 0)
  72. {
  73. return result = new Result() { Code = -1, Msg = "添加失败!" };
  74. }
  75. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  76. }
  77. }
  78. else if (dto.Status == 2)//修改
  79. {
  80. var updateInfo = new Res_HotelData
  81. {
  82. City = dto.City,
  83. Name = dto.Name,
  84. Level = dto.Level,
  85. Address = dto.Address,
  86. Tel = dto.Tel,
  87. Fax = dto.Fax,
  88. Contact = dto.Contact,
  89. ContactPhone = dto.ContactPhone,
  90. OtherInformation = dto.OtherInformation,
  91. Remark = dto.Remark,
  92. };
  93. EncryptionProcessor.EncryptProperties(updateInfo);// 加密属性
  94. bool res = await UpdateAsync(a => a.Id == dto.Id, a => updateInfo);
  95. if (!res)
  96. {
  97. return result = new Result() { Code = -1, Msg = "修改失败!" };
  98. }
  99. return result = new Result() { Code = 0, Msg = "修改成功!" };
  100. }
  101. else
  102. {
  103. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  104. }
  105. }
  106. }
  107. }