public async Task Init() { SearchMobileServiceRequest req = new SearchMobileServiceRequest(); req.KorisnikId = APIService.KorisnikId; if (SelectedVrstaStatusa != null) { req.VrstaStatusaId = SelectedVrstaStatusa.StatusServisaId; } var list = await _servisiService.GetParam <IEnumerable <ServisModel> >("GetServisiByUser", req); if (VrsteStatusaList.Count < 1) { var listaStatusa = await _servisiService.Get <IEnumerable <StatusServisaModel> >("GetVrsteStatusa"); VrsteStatusaList.Clear(); VrsteStatusaList.Add(new StatusServisaModel { StatusServisaId = 0, Naziv = "(SVE)" }); foreach (var item in listaStatusa) { VrsteStatusaList.Add(item); } } ServisiList.Clear(); foreach (var item in list) { ServisiList.Add(item); } }
public List <ServisModel> GetServisiByUser(SearchMobileServiceRequest request) { var query = _context.Servisi.Include("Serviser").Include("Klijent").Include("Status") .Include("Uredjaj").Include("TipPlacanja").Include("TipDostave").AsQueryable(); var isKorisnik = false; var isServiser = false; if (request.VrstaStatusaId > 0) { query = query.Where(x => x.StatusServisaId == request.VrstaStatusaId); } if (request.KorisnikId > 0) { var korisnik = _context.Korisnici.Include("KorisniciUloge.Uloga").Where(x => x.KorisnikId == request.KorisnikId).FirstOrDefault(); if (korisnik != null) { foreach (var item in korisnik.KorisniciUloge) { if (item.Uloga.Naziv == "korisnik") { isKorisnik = true; } if (item.Uloga.Naziv == "serviser") { isServiser = true; } } } if (isServiser) { query = query.Where(u => u.ServiserId == request.KorisnikId); var list = query.OrderByDescending(x => x.DatumServisa).ToList(); return(_mapper.Map <List <Model.ServisModel> >(list)); } else if (isKorisnik) { query = query.Where(u => u.KlijentId == request.KorisnikId); var list = query.OrderByDescending(x => x.DatumServisa).ToList(); return(_mapper.Map <List <Model.ServisModel> >(list)); } } return(null); }
public ActionResult <List <Model.ServisModel> > GetServisiByUser([FromQuery] SearchMobileServiceRequest request) { return(_service.GetServisiByUser(request)); }