TpntStoreRepository.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Ropin.Inspection.Model;
  2. using Ropin.Inspection.Model.Entities;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Ropin.Inspection.Repository
  9. {
  10. public class TpntStoreRepository : RepositoryBase<TPNT_Store, Guid>, ITpntStoreRepository
  11. {
  12. public TpntStoreRepository(InspectionDbContext dbContext) : base(dbContext)
  13. {
  14. }
  15. public IList<TPNT_Type> GetAllPntType()
  16. {
  17. return DbContext.Set<TPNT_Type>().ToList();
  18. }
  19. public Task<TpntStoreViewModel> GetStoreByCodeAsync(string code)
  20. {
  21. MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("code", code) };
  22. string sql = @"SELECT C.*,D.C_Name AS TypeName,G.C_Code AS ProvCode,G.C_Name AS ProvName,F.C_Code AS CityCode,F.C_Name AS CityName,E.C_Code AS AreaCode,E.C_Name AS AreaName FROM TPNT_Store C
  23. INNER JOIN TPNT_Type D ON D.C_Code = C.C_TypeCode
  24. INNER JOIN TBDM_Area E on E.C_Code = C.C_AreaCode
  25. INNER JOIN TBDM_City F ON F.C_Code = E.C_CityCode
  26. INNER JOIN TBDM_Prov G ON G.C_Code = F.C_ProvCode
  27. WHERE C.C_Code = @code";
  28. IEnumerable<TpntStoreViewModel> result = EntityFrameworkCoreExtensions.GetList<TpntStoreViewModel>(DbContext.Database, sql, parameters);
  29. return Task.FromResult(result.FirstOrDefault());
  30. }
  31. }
  32. }