using Ropin.Inspection.Model.Entities; using Ropin.Inspection.Model.SearchModel.LGS; using Ropin.Inspection.Model.ViewModel.LGS; using Ropin.Inspection.Repository.LGS.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Ropin.Inspection.Repository.LGS { public class LGSLargeScreenRepository : RepositoryBase, ILGSLargeScreenRepository { public LGSLargeScreenRepository(InspectionDbContext dbContext) : base(dbContext) { } public Task> GetConditionAsync(LargeScreenSearch searchModel) { MySqlConnector.MySqlParameter[] parameters = new[] { new MySqlConnector.MySqlParameter("Status", searchModel?.C_Status), new MySqlConnector.MySqlParameter("name", "%"+searchModel?.C_Name+"%"), new MySqlConnector.MySqlParameter("StoreCode", searchModel?.C_StoreCode), new MySqlConnector.MySqlParameter("Id ", searchModel?.C_ID) }; StringBuilder sql = new StringBuilder(); sql.Append(@"select * from ( select l.*,s.C_Name as C_StoreName from TLGS_LargeScreen l LEFT JOIN TPNT_Store s on (l.C_StoreCode=s.C_Code) ) tab where 1=1"); if (!string.IsNullOrEmpty(searchModel.C_Status)) { sql.Append(" and C_Status=@Status "); } if (!string.IsNullOrEmpty(searchModel.C_Name)) { sql.Append(" and C_Name like @name"); } if (!string.IsNullOrEmpty(searchModel.C_StoreCode)) { sql.Append(" and C_StoreCode=@StoreCode "); } if (!string.IsNullOrEmpty(searchModel.C_ID)) { sql.Append(" and C_ID=@Id "); } sql.Append(" order by D_CreateOn desc "); IEnumerable recordItemlist = EntityFrameworkCoreExtensions.GetList(DbContext.Database, sql.ToString(), parameters); searchModel.TotalCount = recordItemlist.First() != null ? recordItemlist.ToList().Count : 0; if (recordItemlist.Count() == 1 && recordItemlist.First() == null) { recordItemlist = null; } return Task.FromResult(searchModel.IsPagination ? recordItemlist?.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize) : recordItemlist); } } }