HotelDataRepository.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Groups;
  4. using OASystem.Domain.Dtos.Resource;
  5. using OASystem.Domain.Entities.Resource;
  6. using OASystem.Domain.ViewModels.Resource;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace OASystem.Infrastructure.Repositories.Resource
  13. {
  14. public class HotelDataRepository:BaseRepository<Res_HotelData,HotelDataView>
  15. {
  16. private readonly IMapper _mapper;
  17. public HotelDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  18. {
  19. _mapper= mapper;
  20. }
  21. public async Task<Result> OperationHotelData(OperationHotelDto dto)
  22. {
  23. Result result = new Result() { Code = -2, Msg = "未知错误" };
  24. if (dto.Status == 1)//添加
  25. {
  26. string selectSql = string.Format(@"select * from Res_HotelData where Name='{0}' and IsDel='{1}'"
  27. , dto.Name, 0);
  28. var HotelData = await _sqlSugar.SqlQueryable<Res_HotelData>(selectSql).FirstAsync();//查询是否存在
  29. if (HotelData != null)
  30. {
  31. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  32. }
  33. else//不存在,可添加
  34. {
  35. Res_HotelData _HotelDataDto = _mapper.Map<Res_HotelData>(dto);
  36. int id = await AddAsyncReturnId(_HotelDataDto);
  37. if (id == 0)
  38. {
  39. return result = new Result() { Code = -1, Msg = "添加失败!" };
  40. }
  41. return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  42. }
  43. }
  44. else if (dto.Status == 2)//修改
  45. {
  46. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_HotelData
  47. {
  48. City = dto.City,
  49. Name = dto.Name,
  50. Level = dto.Level,
  51. Address = dto.Address,
  52. Tel = dto.Tel,
  53. Fax = dto.Fax,
  54. Contact = dto.Contact,
  55. ContactPhone = dto.ContactPhone,
  56. OtherInformation = dto.OtherInformation,
  57. Remark = dto.Remark,
  58. });
  59. if (!res)
  60. {
  61. return result = new Result() { Code = -1, Msg = "修改失败!" };
  62. }
  63. return result = new Result() { Code = 0, Msg = "修改成功!" };
  64. }
  65. else
  66. {
  67. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  68. }
  69. }
  70. }
  71. }