public List <Model.Gost> get(GostiSearchRequest search) { //var list = _context.Gost.ToList(); // Normlni get bez uslova za pretragom //return _mapper.Map<List<Model.Gost>>(list); var query = _context.Gost.Include(g => g.Grad).AsQueryable(); if (search != null) { if (search.gradID.HasValue) { query = query.Where(v => v.GradId == search.gradID.Value); } } if (!string.IsNullOrWhiteSpace(search?.ime)) { query = query.Where(x => x.Ime.StartsWith(search.ime)); } if (!string.IsNullOrWhiteSpace(search?.prezime)) { query = query.Where(x => x.Prezime.StartsWith(search.prezime)); } var list = query.ToList(); return(_mapper.Map <List <Model.Gost> >(list)); }
private async void btnPrikazi_Click(object sender, EventArgs e) { var search = new GostiSearchRequest() // Ovo sluzi za pretragu gostiju po imenu i prezimenu { ime = txtPretraga.Text, prezime = txtPrezime.Text }; var result = await _service.get <List <Model.Gost> >(search); // Dovaljamo sve goste sa api servisa dgwGosti.DataSource = result; // data grid view popunjavamo sa dobavljenom listom }
public ActionResult <List <Model.Gost> > Get([FromQuery] GostiSearchRequest search) { return(_service.get(search)); }