HotelDataRepository.cs 3.8 KB

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