public async Task <IActionResult> UpdateFromApi() { var mamc = from m in _context.MAmc orderby m.UniqueId select m; var fundM = new MainFundModel { AmcSelectList = new SelectList(await mamc.ToListAsync(), "UniqueId", "NameTh"), }; return(View(fundM)); }
// GET: MFunds public async Task <IActionResult> Index(string QueryAmc, string QueryFundKeyword) { //var applicationDbContext = _context.MFund.Include(m => m.MAmc); //return View(await applicationDbContext.ToListAsync()); var mamc = from m in _context.MAmc orderby m.UniqueId select m; var funds = from m in _context.MFund.Include(m => m.MAmc) select m; if (string.IsNullOrEmpty(QueryFundKeyword)) { if (string.IsNullOrEmpty(QueryAmc)) { QueryAmc = "0"; } funds = funds.Where(x => x.MAmcId == int.Parse(QueryAmc)); } else { if (!string.IsNullOrEmpty(QueryAmc)) { funds = funds.Where(x => x.MAmcId == int.Parse(QueryAmc)); } funds = funds.Where(x => x.NameTh.ToUpper().Contains(QueryFundKeyword) || x.NameEn.ToUpper().Contains(QueryFundKeyword) || x.Abbr.ToUpper().Contains(QueryFundKeyword)); } funds = funds.OrderBy(x => x.MAmc.ID).ThenBy(x => x.Abbr); var fundM = new MainFundModel { MFunds = await funds.ToListAsync(), AmcSelectListFilter = new SelectList(await mamc.ToListAsync(), "ID", "NameTh"), }; return(View(fundM)); }