AppStartPageRepository.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.Repository.Interface.AppStartPage;
  8. using GxPress.Request.AppStartPage;
  9. using Microsoft.Extensions.Options;
  10. namespace GxPress.Repository.Implement.AppStartPage
  11. {
  12. public class AppStartPageRepository : IAppStartPageRepository
  13. {
  14. private readonly Repository<Entity.tede2.AppStartPage.AppStartPage> _repository;
  15. private readonly IMapper _mapper;
  16. private readonly string _connectionString;
  17. private readonly string _databaseTypestr;
  18. public AppStartPageRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  19. {
  20. _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
  21. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  22. var databaseType =
  23. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  24. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  25. _repository = new Repository<Entity.tede2.AppStartPage.AppStartPage>(database);
  26. _mapper = mapper;
  27. }
  28. public IDatabase Database => _repository.Database;
  29. public string TableName => _repository.TableName;
  30. public List<TableColumn> TableColumns => _repository.TableColumns;
  31. /// <summary>
  32. /// 获取 APP启动 1IOS 2Android
  33. /// </summary>
  34. /// <param name="appTypeId"></param>
  35. /// <returns></returns>
  36. public async Task<Entity.tede2.AppStartPage.AppStartPage> GetAsync(int appTypeId)
  37. {
  38. return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.AppStartPage.AppStartPage.AppTypeId), appTypeId).Where(nameof(Entity.tede2.AppStartPage.AppStartPage.IsDisable), false).OrderByDesc(nameof(Entity.tede2.AppStartPage.AppStartPage.CreatedDate)));
  39. }
  40. /// <summary>
  41. /// 查询
  42. /// </summary>
  43. /// <returns></returns>
  44. public async Task<IEnumerable<Entity.tede2.AppStartPage.AppStartPage>> GetAllAsync()
  45. {
  46. var result= await _repository.GetAllAsync(Q.OrderByDesc(nameof(Entity.tede2.AppStartPage.AppStartPage.CreatedDate)));
  47. foreach (var item in result)
  48. {
  49. item.ImageUrl=StringUtils.AddDomain(item.ImageUrl);
  50. }
  51. return result;
  52. }
  53. /// <summary>
  54. /// 删除
  55. /// </summary>
  56. /// <param name="id"></param>
  57. /// <returns></returns>
  58. public async Task<bool> DeleteAsync(int id)
  59. {
  60. return await _repository.DeleteAsync(id);
  61. }
  62. /// <summary>
  63. /// 修改
  64. /// </summary>
  65. /// <param name="model"></param>
  66. /// <returns></returns>
  67. public async Task<bool> UpdateAsync(AppStartPageUpdateRequest request)
  68. {
  69. var model = await _repository.GetAsync(request.Id);
  70. if (!string.IsNullOrEmpty(request.ImageUrl))
  71. model.ImageUrl = StringUtils.RemoveDomain(request.ImageUrl);
  72. if (request.IsDisable > 0)
  73. model.IsDisable = request.IsDisable == 1;
  74. if (request.Second > 0)
  75. model.Second = request.Second;
  76. if (!string.IsNullOrEmpty(request.Title))
  77. model.Title = request.Title;
  78. if (request.TypeId > 0)
  79. model.TypeId = request.TypeId;
  80. if (!string.IsNullOrEmpty(request.Url))
  81. model.Url = request.Url;
  82. if (request.AdminId > 0)
  83. model.AdminId = request.AdminId;
  84. if (request.AppTypeId > 0)
  85. model.AppTypeId = request.AppTypeId;
  86. if (!string.IsNullOrEmpty(request.Creator))
  87. model.Creator = request.Creator;
  88. if (request.DataId > 0)
  89. model.DataId = request.DataId;
  90. if (request.DataTypeId > 0)
  91. model.DataTypeId = request.DataTypeId;
  92. return await _repository.UpdateAsync(model);
  93. }
  94. /// <summary>
  95. /// 添加
  96. /// </summary>
  97. /// <param name="model"></param>
  98. /// <returns></returns>
  99. public async Task<bool> InsertAsync(Entity.tede2.AppStartPage.AppStartPage model)
  100. {
  101. return await _repository.InsertAsync(model) > 0;
  102. }
  103. }
  104. }