LocalGuideDataRepository.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using AutoMapper;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Dtos.Resource;
  4. using OASystem.Domain.Entities.Groups;
  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 LocalGuideDataRepository : BaseRepository<Res_LocalGuideData, LocalGuideDataView>
  15. {
  16. private readonly IMapper _mapper;
  17. public LocalGuideDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  18. {
  19. _mapper=mapper;
  20. }
  21. public async Task<Result> LocalGuideOperation(LocalGuideOperationDto dto)
  22. {
  23. Result result = new Result() { Code = -2, Msg = "未知错误" };
  24. try
  25. {
  26. if (dto.Status == 1)//添加
  27. {
  28. string selectSql = string.Format(@"select * from Res_LocalGuideData where UnitArea='{0}' and UnitName='{1}' and Contact='{2}' and ContactTel='{3}'"
  29. , dto.UnitArea, dto.UnitName, dto.Contact, dto.ContactTel);
  30. var LocalGuideData = await _sqlSugar.SqlQueryable<Res_LocalGuideData>(selectSql).FirstAsync();//查询是否存在
  31. if (LocalGuideData != null)
  32. {
  33. return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  34. }
  35. else//不存在,可添加
  36. {
  37. Res_LocalGuideData _LocalGuideDat = _mapper.Map<Res_LocalGuideData>(dto);
  38. int id = await AddAsyncReturnId(_LocalGuideDat);
  39. if (id == 0)
  40. {
  41. return result = new Result() { Code = -1, Msg = "添加失败!" };
  42. }
  43. result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
  44. }
  45. }
  46. else if(dto.Status == 2)//修改
  47. {
  48. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_LocalGuideData
  49. {
  50. UnitArea = dto.UnitArea,
  51. UnitName = dto.UnitName,
  52. Address = dto.Address,
  53. Contact = dto.Contact,
  54. ContactTel = dto.ContactTel,
  55. ContactEmail = dto.ContactEmail,
  56. ContactFax = dto.ContactFax,
  57. OtherInfo = dto.OtherInfo,
  58. Score = dto.Score,
  59. SuitScore = dto.SuitScore,
  60. ServeScore = dto.ServeScore,
  61. TalkProScore = dto.TalkProScore,
  62. TimeScore = dto.TimeScore,
  63. FitScore = dto.FitScore,
  64. StrainScore = dto.StrainScore,
  65. LocalAndChineseScore = dto.LocalAndChineseScore,
  66. Remark = dto.Remark,
  67. });
  68. if (!res)
  69. {
  70. return result = new Result() { Code = -1, Msg = "修改失败!" };
  71. }
  72. result = new Result() { Code = 0, Msg = "修改成功!" };
  73. }
  74. else
  75. {
  76. return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. return result = new Result() { Code = -2, Msg = "程序错误!" };
  82. }
  83. return result;
  84. }
  85. }
  86. }