AppChannelRepository.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using AutoMapper;
  4. using Datory;
  5. using GxPress.Common.AppOptions;
  6. using GxPress.Common.Tools;
  7. using GxPress.EnumConst;
  8. using GxPress.Repository.Interface.AppChannel;
  9. using GxPress.Result.AppChannel;
  10. using Microsoft.Extensions.Options;
  11. namespace GxPress.Repository.Implement.AppChannel
  12. {
  13. public class AppChannelRepository : IAppChannelRepository
  14. {
  15. private readonly Repository<Entity.tede2.AppChannel.AppChannel> _repository;
  16. private readonly IMapper _mapper;
  17. public AppChannelRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  18. {
  19. var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  20. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  21. _repository = new Repository<Entity.tede2.AppChannel.AppChannel>(database);
  22. _mapper = mapper;
  23. }
  24. public IDatabase Database => _repository.Database;
  25. public string TableName => _repository.TableName;
  26. public List<TableColumn> TableColumns => _repository.TableColumns;
  27. /// <summary>
  28. /// 获取详情
  29. /// </summary>
  30. /// <param name="id"></param>
  31. /// <returns></returns>
  32. public async Task<Entity.tede2.AppChannel.AppChannel> GetAsync(int id)
  33. {
  34. var result = await _repository.GetAsync(id);
  35. if (result != null)
  36. result.ImageUrls = StringUtils.AddDomain(result.ImageUrls);
  37. return result;
  38. }
  39. /// <summary>
  40. /// 查询
  41. /// </summary>
  42. /// <returns></returns>
  43. public async Task<IEnumerable<AppChannelResult>> GetAllAsync(AppChannelConst channelTypeValue)
  44. {
  45. var result = await _repository.GetAllAsync<AppChannelResult>(Q.Where(nameof(Entity.tede2.AppChannel.AppChannel.ChannelTypeValue), channelTypeValue).OrderBy(nameof(Entity.tede2.AppChannel.AppChannel.Sort)));
  46. foreach (var item in result)
  47. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  48. return result;
  49. }
  50. /// <summary>
  51. /// 删除
  52. /// </summary>
  53. /// <param name="id"></param>
  54. /// <returns></returns>
  55. public async Task<bool> DeleteAsync(int id)
  56. {
  57. return await _repository.DeleteAsync(id);
  58. }
  59. /// <summary>
  60. /// 修改
  61. /// </summary>
  62. /// <param name="model"></param>
  63. /// <returns></returns>
  64. public async Task<bool> UpdateAsync(Entity.tede2.AppChannel.AppChannel request)
  65. {
  66. var model = await _repository.GetAsync(request.Id);
  67. if (!string.IsNullOrEmpty(request.ImageUrls))
  68. model.ImageUrls = StringUtils.RemoveDomain(request.ImageUrls);
  69. model.IsDisable = request.IsDisable;
  70. model.TypeValue = request.TypeValue;
  71. model.Name = request.Name;
  72. model.Sort = request.Sort;
  73. model.IsDisable = request.IsDisable;
  74. return await _repository.UpdateAsync(model);
  75. }
  76. /// <summary>
  77. /// 添加
  78. /// </summary>
  79. /// <param name="model"></param>
  80. /// <returns></returns>
  81. public async Task<bool> InsertAsync(Entity.tede2.AppChannel.AppChannel model)
  82. {
  83. if (!string.IsNullOrEmpty(model.ImageUrls))
  84. model.ImageUrls = StringUtils.RemoveDomain(model.ImageUrls);
  85. return await _repository.InsertAsync(model) > 0;
  86. }
  87. }
  88. }