MiddleLableRepository.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.Navigation;
  8. using GxPress.Request.Navigation;
  9. using Microsoft.Extensions.Options;
  10. namespace GxPress.Repository.Implement.Navigation
  11. {
  12. public class MiddleLableRepository : IMiddleLableRepository
  13. {
  14. private readonly Repository<Entity.Navigations.MiddleLable> _repository;
  15. private readonly IMapper _mapper;
  16. private readonly string _connectionString;
  17. private readonly string _databaseTypestr;
  18. public MiddleLableRepository(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.Navigations.MiddleLable>(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. public async Task<Entity.Navigations.MiddleLable> GetAsync(int id)
  32. {
  33. return await _repository.GetAsync(id);
  34. }
  35. public async Task<bool> DeleteAsync(int id)
  36. {
  37. return await _repository.DeleteAsync(id);
  38. }
  39. public async Task<int> InsertAsync(Entity.Navigations.MiddleLable note)
  40. {
  41. return await _repository.InsertAsync(note);
  42. }
  43. public async Task<bool> UpdateAsync(MiddleLableUpRequest request)
  44. {
  45. if (request.Id > 0)
  46. {
  47. var model = await GetAsync(request.Id);
  48. if (request.IsDisable > 0)
  49. model.IsDisable = request.IsDisable == 1;
  50. if (!string.IsNullOrEmpty(request.Name))
  51. model.Name = request.Name;
  52. if (request.Sort > 0)
  53. model.Sort = request.Sort;
  54. if (request.IsSearch > 0)
  55. model.IsSearch = request.IsSearch == 1;
  56. if (request.IsSlide > 0)
  57. model.IsSlide = request.IsSlide == 1;
  58. if (request.TypeId > 0)
  59. model.TypeId = request.TypeId;
  60. return await _repository.UpdateAsync(model);
  61. }
  62. return false;
  63. }
  64. public async Task<bool> UpdateAsync(SqlKata.Query query)
  65. {
  66. return await _repository.UpdateAsync(query) > 0;
  67. }
  68. public async Task<IEnumerable<Entity.Navigations.MiddleLable>> GetAllAsync()
  69. {
  70. return await _repository.GetAllAsync(Q.Where(nameof(Entity.Navigations.MiddleLable.IsDisable), false).OrderByDesc(nameof(Entity.Navigations.MiddleLable.Sort)));
  71. }
  72. }
  73. }