/// <summary> /// 番組検索 /// </summary> /// <param name="cond"></param> /// <returns></returns> public List <Entities.Program> Search(ProgramSearchCondition cond) { var wheres = new List <string>(); //var q = Db.Programs.Where(p => p.Id != null); if (!string.IsNullOrWhiteSpace(cond.StationId)) { wheres.Add("StationId = @StationId"); // q = q.Where(p => p.StationId == cond.StationId); } if (cond.From != null) { wheres.Add("End > @From"); //q = q.Where(p => p.End > cond.From); } if (cond.To != null) { wheres.Add("Start < @To"); //q = q.Where(p => p.Start < cond.To); } if (!string.IsNullOrWhiteSpace(cond.Keyword)) { wheres.Add("( Title LIKE @Keyword OR Cast LIKE @Keyword OR Description LIKE @Keyword)"); /* * q = q.Where(p => * p.Title.Contains(cond.Keyword) || p.Cast.Contains(cond.Keyword) || * p.Description.Contains(cond.Keyword));*/ } var where = wheres.Any() ? $"WHERE {string.Join(" AND ", wheres)}" : ""; var query = $@"SELECT * FROM Programs {where} ORDER BY StationId, Start"; var res = SqliteConnection.Query <Entities.Program>(query, cond); // var res = q.OrderBy(p => p.StationId).ThenBy(p => p.Start).ToList(); return(res.ToList()); }
public async Task <ApiResponse> Index([FromBody] ProgramSearchCondition cond) { return(await Execute(() => { using (SqliteConnection) { var pModel = new ProgramModel(SqliteConnection); var res = pModel.Search(cond); if (!res.Any() && string.IsNullOrWhiteSpace(cond.Keyword) && cond.Refresh) { RefreshPrograms(cond.StationId); res = pModel.Search(cond); } Result.Data = new { programs = res, range = pModel.GetRange(cond.StationId) }; Result.Result = true; } })); }