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