MiddleLableRepository.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.Entity.Navigations;
  8. using GxPress.Repository.Interface.Navigation;
  9. using GxPress.Request.Navigation;
  10. using Microsoft.Extensions.Options;
  11. namespace GxPress.Repository.Implement.Navigation
  12. {
  13. public class MiddleLableRepository : IMiddleLableRepository
  14. {
  15. private readonly Repository<Entity.Navigations.MiddleLable> _repository;
  16. private readonly IMapper _mapper;
  17. private readonly string _connectionString;
  18. private readonly string _databaseTypestr;
  19. public MiddleLableRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  20. {
  21. _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
  22. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  23. var databaseType =
  24. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  25. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  26. _repository = new Repository<Entity.Navigations.MiddleLable>(database);
  27. _mapper = mapper;
  28. }
  29. public IDatabase Database => _repository.Database;
  30. public string TableName => _repository.TableName;
  31. public List<TableColumn> TableColumns => _repository.TableColumns;
  32. public async Task<Entity.Navigations.MiddleLable> GetAsync(int id)
  33. {
  34. return await _repository.GetAsync(id);
  35. }
  36. public async Task<bool> DeleteAsync(int id)
  37. {
  38. return await _repository.DeleteAsync(id);
  39. }
  40. public async Task<int> InsertAsync(Entity.Navigations.MiddleLable note)
  41. {
  42. return await _repository.InsertAsync(note);
  43. }
  44. public async Task<bool> UpdateAsync(MiddleLableUpRequest request)
  45. {
  46. if (request.Id > 0)
  47. {
  48. var model = await GetAsync(request.Id);
  49. if (request.IsDisable > 0)
  50. model.IsDisable = request.IsDisable == 1;
  51. if (!string.IsNullOrEmpty(request.LabelId))
  52. model.LabelId = request.LabelId;
  53. if (!string.IsNullOrEmpty(request.Name))
  54. model.Name = request.Name;
  55. if (!string.IsNullOrEmpty(request.LabelId))
  56. model.LabelId = request.LabelId;
  57. if (request.Sort > 0)
  58. model.Sort = request.Sort;
  59. if (request.IsSearch > 0)
  60. model.IsSearch = request.IsSearch == 1;
  61. if (request.IsSlide > 0)
  62. model.IsSlide = request.IsSlide == 1;
  63. if (request.TypeId > 0)
  64. model.TypeId = request.TypeId;
  65. return await _repository.UpdateAsync(model);
  66. }
  67. return false;
  68. }
  69. public async Task<bool> UpdateAsync(SqlKata.Query query)
  70. {
  71. return await _repository.UpdateAsync(query) > 0;
  72. }
  73. public async Task<IEnumerable<Entity.Navigations.MiddleLable>> GetAllAsync()
  74. {
  75. return await _repository.GetAllAsync(Q.Where(nameof(Entity.Navigations.MiddleLable.IsDisable), false).OrderByDesc(nameof(Entity.Navigations.MiddleLable.Sort)));
  76. }
  77. }
  78. }